Gudhi  1.1.0
 All Classes Functions Typedefs Friends Groups Pages
Test.h
1 #ifndef __TEST_H
2 #define __TEST_H
3 
4 #include <list>
5 #include <string>
6 #include <vector>
7 #include <sstream>
8 #include <iostream>
9 
10 
11 #define TEST(a) std::cout << "TEST: " << (a)<<std::endl
12 #define TESTMSG(a,b) std::cout << "TEST: " << a<<b<<std::endl
13 #define TESTVALUE(a) std::cout << "TEST: " << #a << ": " << a<<std::endl
14 
15 
20 class Test
21 {
22 private :
23  std::string name;
24  bool (*test)();
25 
26  std::string separation() const{
27  return "+++++++++++++++++++++++++++++++++++++++++++++++++\n";
28  }
29 
30  std::string print_between_plus(std::string& s) const{
31  std::stringstream res;
32  res << "+++++++++++++++++"<<s<<"+++++++++++++++++\n";
33  return res.str();
34  }
35 
36 
37 public:
38  Test(std::string name_,bool (*test_)()){
39  name=name_;
40  test =test_;
41  }
42 
43  bool run(){
44  std::cout << print_between_plus(name);
45  return test();
46  }
47  std::string getName(){
48  return name;
49  }
50 };
51 
52 
53 class Tests
54 {
55 private:
56  std::list<Test> tests;
57 
58 public:
59  void add(std::string name_,bool (*test_)()){
60  Test test(name_,test_);
61  tests.push_back(test);
62  }
63  bool run(){
64  bool tests_succesful(true);
65  std::vector<bool> res;
66  for (Test test : tests){
67  res.push_back(test.run());
68  }
69  std::cout << "\n\n results of tests : "<<std::endl;
70  int i=0;
71  for (Test t : tests){
72  std::cout << "Test "<<i<< " \""<<t.getName()<<"\" --> ";
73  if (res[i++]) std::cout << "OK"<<std::endl;
74  else {
75  std::cout << "Fail"<<std::endl;
76  tests_succesful = false;
77  break;
78  }
79  }
80  return tests_succesful;
81 
82  }
83 };
84 
85 #endif
Definition: Test.h:20