|
@@ -1,29 +1,97 @@
|
1
|
1
|
#include "../include/Test.h"
|
2
|
2
|
|
3
|
3
|
Test::Test( bool verbose = true ){
|
4
|
|
- this->verbose = verbose;
|
|
4
|
+ this->verbose = verbose ;
|
5
|
5
|
}
|
6
|
6
|
|
7
|
|
-bool Test::assertEqual( std::string result, std::string expected )
|
|
7
|
+bool Test::print_assertEqual( std::string result, std::string expected )
|
8
|
8
|
{
|
9
|
|
- if ( result == expected ){
|
10
|
|
- std::cout << "[\033[32msuccess\033[0m] : result equals expectation : \033[36m" << result << "\033[0m" << std::endl;
|
|
9
|
+ if (Test::do_assertEqual( result, expected )){
|
|
10
|
+ std::cout << "[\033[32msuccess\033[0m] : result equals expectation : \033[36m" << result << "\033[0m" << std::endl ;
|
11
|
11
|
return true;
|
12
|
12
|
}else{
|
13
|
|
- std::cout << "[\033[31mfailure\033[0m] : result \033[36m: " << result << "\033[0m" << std::endl
|
14
|
|
- << " expectation :\033[36m" << expected << std::endl;
|
|
13
|
+ std::cout << "[\033[31mfailure\033[0m] : result \033[36m: " << result << "\033[0m" << " ≠ \033[36m" << expected << std::endl;
|
15
|
14
|
return false;
|
16
|
15
|
}
|
17
|
16
|
}
|
18
|
17
|
|
19
|
|
-bool Test::assertNotEqual( std::string result, std::string expected )
|
|
18
|
+bool Test::do_assertEqual( std::string result, std::string expected )
|
|
19
|
+{
|
|
20
|
+ return ( result == expected );
|
|
21
|
+}
|
|
22
|
+
|
|
23
|
+bool Test::assertEqual( std::string result, std::string expected )
|
|
24
|
+{
|
|
25
|
+ return ( this->verbose )?
|
|
26
|
+ Test::print_assertEqual( result, expected ):
|
|
27
|
+ Test::do_assertEqual( result, expected );
|
|
28
|
+}
|
|
29
|
+
|
|
30
|
+bool Test::print_assertNotEqual( std::string result, std::string expected )
|
20
|
31
|
{
|
21
|
|
- if ( result == expected ){
|
|
32
|
+ if ( Test::do_assertNotEqual( result, expected ) ){
|
22
|
33
|
std::cout << "[\033[31mfailure\033[0m] : result equals expectation : \033[36m" << result << "\033[0m" << std::endl;
|
|
34
|
+ return true;
|
|
35
|
+ }else{
|
|
36
|
+ std::cout << "[\033[32msuccess\033[0m] : \033[36m" << result << "\033[0m" << " ≠ \033[36m" << expected << "\033[0m" << std::endl;
|
23
|
37
|
return false;
|
|
38
|
+ }
|
|
39
|
+}
|
|
40
|
+
|
|
41
|
+bool Test::do_assertNotEqual( std::string result, std::string expected )
|
|
42
|
+{
|
|
43
|
+ return !Test::assertEqual( result, expected );
|
|
44
|
+}
|
|
45
|
+
|
|
46
|
+bool Test::assertNotEqual( std::string result, std::string expected )
|
|
47
|
+{
|
|
48
|
+ return ( this->verbose )?
|
|
49
|
+ Test::print_assertNotEqual( result, expected ):
|
|
50
|
+ Test::do_assertNotEqual( result, expected );
|
|
51
|
+}
|
|
52
|
+
|
|
53
|
+bool Test::assertInRange( int value, int min, int max ){
|
|
54
|
+ return (this->verbose)?
|
|
55
|
+ Test::print_assertInRange( value, min, max ) :
|
|
56
|
+ Test::do_assertInRange( value, min, max ) ;
|
|
57
|
+}
|
|
58
|
+
|
|
59
|
+bool Test::do_assertInRange( int value, int min, int max ){
|
|
60
|
+ return ( value < min || value > max )?
|
|
61
|
+ false :
|
|
62
|
+ true ;
|
|
63
|
+}
|
|
64
|
+
|
|
65
|
+bool Test::print_assertInRange( int value, int min, int max ){
|
|
66
|
+ if( Test::do_assertInRange( value, min, max ) ){
|
|
67
|
+ std::cout << "[\033[32msuccess\033[0m] : \033[36m" << value << "\033[0m" << " in \033[36m[" << min << ";" << max << "]\033[0m" << std::endl ;
|
|
68
|
+ return true;
|
24
|
69
|
}else{
|
25
|
|
- std::cout << "[\033[32msuccess\033[0m] : result : \033[36m" << result << "\033[0m" << std::endl
|
26
|
|
- << " expectation : \033[36m" << expected << "\033[0m" << std::endl;
|
|
70
|
+ std::cout << "[\033[31mfailure\033[0m] : \033[36m" << value << "\033[0m" << " not in \033[36m[" << min << ";" << max << "]\033[0m" << std::endl ;
|
|
71
|
+ return false;
|
|
72
|
+ }
|
|
73
|
+}
|
|
74
|
+
|
|
75
|
+bool Test::assertNotInRange( int value, int min, int max ){
|
|
76
|
+ return (this->verbose)?
|
|
77
|
+ Test::print_assertNotInRange( value, min, max ) :
|
|
78
|
+ Test::do_assertNotInRange( value, min, max ) ;
|
|
79
|
+}
|
|
80
|
+
|
|
81
|
+bool Test::do_assertNotInRange( int value, int min, int max ){
|
|
82
|
+ return ( value < min || value > max )?
|
|
83
|
+ true :
|
|
84
|
+ false ;
|
|
85
|
+}
|
|
86
|
+
|
|
87
|
+bool Test::print_assertNotInRange( int value, int min, int max ){
|
|
88
|
+ if( Test::do_assertNotInRange( value, min, max ) ){
|
|
89
|
+ std::cout << "[\033[32msuccess\033[0m] : value : \033[36m" << value << "\033[0m" << std::endl
|
|
90
|
+ << " range : \033[36m[" << min << ";" << max << "]\033[0m" << std::endl;
|
27
|
91
|
return true;
|
|
92
|
+ }else{
|
|
93
|
+ std::cout << "[\033[31mfailure\033[0m] : value in range : \033[36m" << value << "\033[0m" << std::endl
|
|
94
|
+ << " range : \033[36m[" << min << ";" << max << "]\033[0m" << std::endl;
|
|
95
|
+ return false;
|
28
|
96
|
}
|
29
|
97
|
}
|