Skip to content

Instantly share code, notes, and snippets.

View TheBarbellCoder's full-sized avatar
😎
Happily Coding

Avinash C. Ravi Shankar TheBarbellCoder

😎
Happily Coding
View GitHub Profile
@TheBarbellCoder
TheBarbellCoder / test_dummy.cpp
Created November 12, 2022 07:17
Sample test declaration and definiton
// File: test_dummy.cpp
#include "test_dummy.hpp"
DefineTest(dummy, dummycase){
// Write your test code here
// ...
}
@TheBarbellCoder
TheBarbellCoder / test_main.cpp
Last active November 12, 2022 07:03
Test Project
// File: test_main.cpp
#include "test_project.hpp"
int main(){
RegisterTest(module, test1)
RegisterTest(module, test2)
RunTests()
return 0;
@TheBarbellCoder
TheBarbellCoder / test_project.cpp
Last active May 3, 2022 06:23
Sample test program
// test.hpp
#include "unittest.hpp"
DeclareTest(module, test1)
DeclareTest(module, test2)
...
//test.cpp
#include "test.hpp"
@TheBarbellCoder
TheBarbellCoder / unittest.cpp
Last active November 12, 2022 19:08
Running tests in separate processes
// File: unittest.cpp
void UnitTest::runTests()
{
// variables to count the number of passed and failed tests
static int passed{0};
static int failed{0};
if(testList.empty())
{
std::cout << "No tests registered!!" << std::endl;
@TheBarbellCoder
TheBarbellCoder / unittest.hpp
Last active November 12, 2022 07:12
Macros to register, run, and compare
// File: unittest.hpp
#define RegisterTest(Module, TestName) \
UnitTest::getInstance().testList.push_back( \
Test_##Module##_##TestName::getInstance());
#define RunTests() \
UnitTest::getInstance().runTests();
#define ExpectEQ(arg1, arg2) \
isTrue &= expectEQ(arg1, arg2);
@TheBarbellCoder
TheBarbellCoder / unittest.cpp
Last active November 11, 2022 06:13
runTests method definition
// File: unitest.cpp
void UnitTest::runTests()
{
// Variables to track passed and failed tests
int passed{0};
int failed{0};
if(testList.empty()) {
std::cout << "No tests registered!!" << std::endl;
return;
@TheBarbellCoder
TheBarbellCoder / unittest.hpp
Last active November 11, 2022 06:16
UnitTest class declaration
// File: unittest.hpp
class UnitTest {
protected:
UnitTest() {}
public:
bool isTrue{true};
static std::list<UnitTest*> testList;
virtual ~UnitTest() {}
@TheBarbellCoder
TheBarbellCoder / testcase.cpp
Last active November 11, 2022 06:16
Test case definition
// File: testcase.cpp
#include "testcase.hpp"
DefineTest(dummy, dummycase){
// Write your test code here
// ...
}
@TheBarbellCoder
TheBarbellCoder / testcase.hpp
Last active November 11, 2022 06:14
Test case declaration
// File: testcase.hpp
#include "unittest.hpp"
DeclareTest(dummy, dummycase)
@TheBarbellCoder
TheBarbellCoder / unittest.hpp
Last active November 11, 2022 06:14
Macros to declare and define test cases
// File: unittest.hpp
#define DeclareTest(Module, TestName) \
class Test_##Module##_##TestName: public UnitTest \
{ \
Test_##Module##_##TestName(): UnitTest(){} \
public: \
static Test_##Module##_##TestName* getInstance() \
{ \
static Test_##Module##_##TestName testClass; \
return &testClass; \