3
3
#include < cmath>
4
4
5
5
#include " scene.hpp"
6
+ #include " operators.hpp"
6
7
#include " testing.hpp"
7
8
8
9
testing::Environment* const env =
@@ -31,14 +32,20 @@ namespace expected {
31
32
}
32
33
}
33
34
34
- const float MIN = -10e6 ;
35
- const float MAX = 10e6 ;
35
+ const float MIN = -100 ;
36
+ const float MAX = 100 ;
36
37
37
- std::string distance_error_msg (Point2D a, Point2D b) {
38
+ std::string distance_error_msg (Point2D a, Point2D b, float expected, float actual ) {
38
39
std::ostringstream stream;
40
+ stream << " Testing expression:\n "
41
+ << " d = distance(a, b)" << " \n " ;
39
42
stream << " Test data:" << " \n "
40
- << " a = { " << a.x << " , " << a.y << " }" << " \n "
41
- << " b = { " << b.x << " , " << b.y << " }" << " \n " ;
43
+ << " a = " << a << " \n "
44
+ << " b = " << b << " \n " ;
45
+ stream << " Expected result:\n "
46
+ << " d = " << expected << " \n " ;
47
+ stream << " Actual result:\n "
48
+ << " d = " << actual << " \n " ;
42
49
return stream.str ();
43
50
}
44
51
@@ -54,20 +61,22 @@ TEST(distanceTest, distanceTestRandom) {
54
61
std::tie (a, b) = data;
55
62
float expected = expected::distance (a, b);
56
63
float actual = distance (a, b);
57
- ASSERT_FLOAT_EQ (expected, actual) << distance_error_msg (a, b);
64
+ ASSERT_FLOAT_EQ (expected, actual) << distance_error_msg (a, b, expected, actual );
58
65
}
59
66
);
60
67
}
61
68
62
- std::string collision_error_msg (Circle circle1, Circle circle2) {
69
+ std::string collision_error_msg (Circle circle1, Circle circle2, bool expected, bool actual ) {
63
70
std::ostringstream stream;
71
+ stream << " Testing expression:\n "
72
+ << " collide = collision(circle1, circle2)" << " \n " ;
64
73
stream << " Test data:" << " \n "
65
- << " circle1 = { "
66
- << " { " << circle1. center . x << " , " << circle1. center . y << " }, " << circle1. radius
67
- << " } " << " \n "
68
- << " circle2 = { "
69
- << " { " << circle2. center . x << " , " << circle2. center . y << " }, " << circle2. radius
70
- << " } " << " \n " ;
74
+ << " circle1 = " << circle1 << " \n "
75
+ << " circle2 = " << circle2 << " \n " ;
76
+ stream << " Expected result: \n "
77
+ << " collide = " << expected << " \n " ;
78
+ stream << " Actual result: \n "
79
+ << " collide = " << actual << " \n " ;
71
80
return stream.str ();
72
81
}
73
82
@@ -84,9 +93,9 @@ TEST(collisionTest, collisionTestTrue) {
84
93
[] (std::tuple<Circle, Circle> data) {
85
94
Circle c1, c2;
86
95
std::tie (c1, c2) = data;
87
- float expected = true ;
88
- float actual = collision (c1, c2);
89
- ASSERT_FLOAT_EQ (expected, actual) << collision_error_msg (c1, c2);
96
+ bool expected = true ;
97
+ bool actual = collision (c1, c2);
98
+ ASSERT_FLOAT_EQ (expected, actual) << collision_error_msg (c1, c2, expected, actual );
90
99
}
91
100
);
92
101
}
@@ -104,9 +113,9 @@ TEST(collisionTest, collisionTestFalse) {
104
113
[] (std::tuple<Circle, Circle> data) {
105
114
Circle c1, c2;
106
115
std::tie (c1, c2) = data;
107
- float expected = false ;
108
- float actual = collision (c1, c2);
109
- ASSERT_FLOAT_EQ (expected, actual) << collision_error_msg (c1, c2);
116
+ bool expected = false ;
117
+ bool actual = collision (c1, c2);
118
+ ASSERT_FLOAT_EQ (expected, actual) << collision_error_msg (c1, c2, expected, actual );
110
119
}
111
120
);
112
121
}
@@ -123,9 +132,9 @@ TEST(collisionTest, collisionTestRandom) {
123
132
[] (std::tuple<Circle, Circle> data) {
124
133
Circle c1, c2;
125
134
std::tie (c1, c2) = data;
126
- float expected = expected::collision (c1, c2);
127
- float actual = collision (c1, c2);
128
- ASSERT_FLOAT_EQ (expected, actual) << collision_error_msg (c1, c2);
135
+ bool expected = expected::collision (c1, c2);
136
+ bool actual = collision (c1, c2);
137
+ ASSERT_FLOAT_EQ (expected, actual) << collision_error_msg (c1, c2, expected, actual );
129
138
}
130
139
);
131
140
}
0 commit comments