Created
September 26, 2013 13:56
-
-
Save tpatel/6714607 to your computer and use it in GitHub Desktop.
CppTester, the simplest test suite.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| CppTester, the simplest test suite | |
| */ | |
| #include <iostream> | |
| #include <vector> | |
| struct Test; | |
| std::vector<Test*> tests; | |
| struct Test { | |
| Test() {tests.push_back(this);} | |
| virtual bool operator()()=0; | |
| }; | |
| int main() { | |
| std::cout << "Begin tests..." << std::endl; | |
| unsigned int passed = tests.size(); | |
| for(unsigned int i=0; i<tests.size(); i++) { | |
| bool returned = (*tests[i])(); //Execute the test | |
| if(!returned) { | |
| std::cout << "Test " << i << " failed" << std::endl; | |
| passed--; | |
| } | |
| } | |
| std::cout << "Tests finished: " << passed << "/" << tests.size() << " tests passed."; | |
| if(passed == tests.size()) { | |
| std::cout << " Good Job!"; | |
| } | |
| std::cout << std::endl; | |
| } | |
| // TESTS | |
| struct T1: Test { virtual bool operator()() { | |
| return 1 == 1; | |
| } } t1; | |
| struct T2: Test { virtual bool operator()() { | |
| return 2 * 21 == 42; | |
| } } t2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment