refactor: Replaced pointer with reference

This commit is contained in:
Rendo 2026-09-02 19:53:18 +05:00
commit e58bdb01ba

View file

@ -24,10 +24,10 @@ class TestSuite {
void run(); void run();
template<class T> template<class T>
TestSuite* eq(std::string, T, T); TestSuite& eq(std::string, T, T);
template<class T> template<class T>
TestSuite* neq(std::string, T, T); TestSuite& neq(std::string, T, T);
TestSuite* custom(std::string, std::function<bool()>); TestSuite& custom(std::string, std::function<bool()>);
}; };
TestSuite::TestSuite(std::string name): suite_name(name) { TestSuite::TestSuite(std::string name): suite_name(name) {
@ -35,20 +35,20 @@ TestSuite::TestSuite(std::string name): suite_name(name) {
} }
template<class T> template<class T>
TestSuite* TestSuite::eq(std::string test_name, T test_value, T expected_value) { TestSuite& TestSuite::eq(std::string test_name, T test_value, T expected_value) {
tests.push_back(Test(test_name, [=](){return test_value == expected_value;})); tests.push_back(Test(test_name, [=](){return test_value == expected_value;}));
return this; return *this;
} }
template<class T> template<class T>
TestSuite* TestSuite::neq(std::string test_name, T test_value, T expected_value) { TestSuite& TestSuite::neq(std::string test_name, T test_value, T expected_value) {
tests.push_back(Test(test_name, [=](){return test_value != expected_value;})); tests.push_back(Test(test_name, [=](){return test_value != expected_value;}));
return this; return *this;
} }
TestSuite* TestSuite::custom(std::string test_name, std::function<bool()> completness_function) { TestSuite& TestSuite::custom(std::string test_name, std::function<bool()> completness_function) {
tests.push_back(Test(test_name, completness_function)); tests.push_back(Test(test_name, completness_function));
return this; return *this;
} }
void TestSuite::run() { void TestSuite::run() {
@ -68,20 +68,3 @@ void TestSuite::run() {
std::cout << "Tests completed: " << completed << "/" << amount << (completed == amount ? ". Well done!" : "... You've got a job to do") << std::endl; std::cout << "Tests completed: " << completed << "/" << amount << (completed == amount ? ". Well done!" : "... You've got a job to do") << std::endl;
} }
#ifdef TEST_THE_TEST
int sum(int a, int b) {
return a+b;
}
int main() {
TestSuite tests = TestSuite("Test of test suite");
tests.eq("Successful eq", sum(1,1), 2)
->neq("Successful neq", sum(1,1), 1)
->eq("Failed eq", sum(1,1), 1)
->run();
return 0;
}
#endif