refactor: Replaced pointer with reference
This commit is contained in:
parent
3b25f2dd5c
commit
e58bdb01ba
1 changed files with 9 additions and 26 deletions
35
test.cpp
35
test.cpp
|
|
@ -24,10 +24,10 @@ class TestSuite {
|
|||
void run();
|
||||
|
||||
template<class T>
|
||||
TestSuite* eq(std::string, T, T);
|
||||
TestSuite& eq(std::string, T, T);
|
||||
template<class T>
|
||||
TestSuite* neq(std::string, T, T);
|
||||
TestSuite* custom(std::string, std::function<bool()>);
|
||||
TestSuite& neq(std::string, T, T);
|
||||
TestSuite& custom(std::string, std::function<bool()>);
|
||||
};
|
||||
|
||||
TestSuite::TestSuite(std::string name): suite_name(name) {
|
||||
|
|
@ -35,20 +35,20 @@ TestSuite::TestSuite(std::string name): suite_name(name) {
|
|||
}
|
||||
|
||||
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;}));
|
||||
return this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
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;}));
|
||||
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));
|
||||
return this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
#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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue