diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2014-12-05 13:32:54 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2014-12-05 13:32:54 +0000 |
commit | 425b462d361286822ee0ed7b5fe00881ba312ea3 (patch) | |
tree | e8f641a8604418882b916573cf32c87b78d33472 /src/common/include/gudhi/Test.h | |
parent | 952b77f3b1e2415602d5d9ffc2fb7ff45cc3edc4 (diff) |
Moved into trunk
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@341 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Diffstat (limited to 'src/common/include/gudhi/Test.h')
-rw-r--r-- | src/common/include/gudhi/Test.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/common/include/gudhi/Test.h b/src/common/include/gudhi/Test.h new file mode 100644 index 00000000..18b7ca82 --- /dev/null +++ b/src/common/include/gudhi/Test.h @@ -0,0 +1,85 @@ +#ifndef __TEST_H +#define __TEST_H + +#include <list> +#include <string> +#include <vector> +#include <sstream> +#include <iostream> + + +#define TEST(a) std::cout << "TEST: " << (a)<<std::endl +#define TESTMSG(a,b) std::cout << "TEST: " << a<<b<<std::endl +#define TESTVALUE(a) std::cout << "TEST: " << #a << ": " << a<<std::endl + + +/** + * Class to perform test + */ + +class Test +{ +private : + std::string name; + bool (*test)(); + + std::string separation() const{ + return "+++++++++++++++++++++++++++++++++++++++++++++++++\n"; + } + + std::string print_between_plus(std::string& s) const{ + std::stringstream res; + res << "+++++++++++++++++"<<s<<"+++++++++++++++++\n"; + return res.str(); + } + + +public: + Test(std::string name_,bool (*test_)()){ + name=name_; + test =test_; + } + + bool run(){ + std::cout << print_between_plus(name); + return test(); + } + std::string getName(){ + return name; + } +}; + + +class Tests +{ +private: + std::list<Test> tests; + +public: + void add(std::string name_,bool (*test_)()){ + Test test(name_,test_); + tests.push_back(test); + } + bool run(){ + bool tests_succesful(true); + std::vector<bool> res; + for (Test test : tests){ + res.push_back(test.run()); + } + std::cout << "\n\n results of tests : "<<std::endl; + int i=0; + for (Test t : tests){ + std::cout << "Test "<<i<< " \""<<t.getName()<<"\" --> "; + if (res[i++]) std::cout << "OK"<<std::endl; + else { + std::cout << "Fail"<<std::endl; + tests_succesful = false; + break; + } + } + return tests_succesful; + + } +}; + +#endif |