summaryrefslogtreecommitdiff
path: root/src/common/include/gudhi/Test.h
blob: 18b7ca827b8aa87278aa5071cb0a232ba1ddc8c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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