Skip to content

Commit 0fe7a38

Browse files
committed
improve error messages in tests output
Signed-off-by: Evgenii Moiseenko <evg.moiseenko94@gmail.com>
1 parent 46bdf05 commit 0fe7a38

File tree

27 files changed

+277
-180
lines changed

27 files changed

+277
-180
lines changed

WarmUp/MovingOn/ALittleSpontaneity/src/generate.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#include <cstdlib>
44

55
Circle generateCircle(float radius) {
6-
Circle circle = { { 600, 150 }, radius };
6+
Circle circle = { { 0, 0 }, 0 };
77
circle.center.x = generateCoordinate(WEST_BORDER + radius, EAST_BORDER - radius);
88
circle.center.y = generateCoordinate(NORTH_BORDER + radius, SOUTH_BORDER - radius);
9+
circle.radius = radius;
910
return circle;
1011
}
1112

WarmUp/MovingOn/ALittleSpontaneity/task-info.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ files:
44
- name: src/generate.cpp
55
visible: true
66
placeholders:
7-
- offset: 130
8-
length: 169
7+
- offset: 121
8+
length: 197
99
placeholder_text: /* TODO */
10-
- offset: 375
10+
- offset: 394
1111
length: 49
1212
placeholder_text: return min;
1313
- name: src/collision.cpp

WarmUp/MovingOn/ALittleSpontaneity/test/test.cpp

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include <gtest/gtest.h>
22

33
#include "scene.hpp"
4+
#include "operators.hpp"
45
#include "testing.hpp"
56

67
testing::Environment* const env =
78
testing::AddGlobalTestEnvironment(new TestEnvironment);
89

9-
const float MIN = -10e6;
10-
const float MAX = 10e6;
10+
const float MIN = -10e3;
11+
const float MAX = 10e3;
1112
const float DELTA = 0.5f;
1213

1314
TEST(generateCoordinateTest, generateCoordinateTestBounds) {
@@ -16,8 +17,8 @@ TEST(generateCoordinateTest, generateCoordinateTestBounds) {
1617
return generateCoordinate(MIN, MAX);
1718
},
1819
[] (float coordinate) {
19-
ASSERT_GT(coordinate, MIN - DELTA) << "Generated value exceeds bounds";
20-
ASSERT_LT(coordinate, MAX + DELTA) << "Generated value exceeds bounds";
20+
ASSERT_GT(coordinate, MIN - DELTA) << "Generated value exceeds bounds.";
21+
ASSERT_LT(coordinate, MAX + DELTA) << "Generated value exceeds bounds.";
2122
}
2223
);
2324
}
@@ -38,12 +39,10 @@ TEST(generateCoordinateTest, generateCoordinateTestRandomness) {
3839

3940
std::string error_msg(float radius, Circle circle) {
4041
std::ostringstream stream;
41-
stream << "Test data:" << "\n"
42-
<< " radius = " << radius << "\n";
43-
stream << "Generated data:" << "\n"
44-
<< " circle = { "
45-
<< "{ " << circle.center.x << ", " << circle.center.y << " }, " << circle.radius
46-
<< " }" << "\n";
42+
stream << "Testing expression:\n"
43+
<< " circle = generateCircle(" << radius << ")" << "\n";
44+
stream << "Generated result:" << "\n"
45+
<< " circle = " << circle << "\n";
4746
return stream.str();
4847
}
4948

@@ -60,19 +59,19 @@ TEST(generateCircleTest, generateCircleTestBounds) {
6059
std::tie(radius, circle) = data;
6160

6261
ASSERT_FLOAT_EQ(radius, circle.radius)
63-
<< "Radius does not match requested value " << error_msg(radius, circle);
62+
<< "Radius does not match requested value.\n" << error_msg(radius, circle);
6463

6564
ASSERT_GT(circle.center.x - radius, WEST_BORDER + DELTA)
66-
<< "Generated circle exceeds bounds";
65+
<< "Generated circle center exceeds bounds.\n" << error_msg(radius, circle);
6766

6867
ASSERT_LT(circle.center.x + radius, EAST_BORDER - DELTA)
69-
<< "Generated circle exceeds bounds";
68+
<< "Generated circle center exceeds bounds.\n" << error_msg(radius, circle);
7069

7170
ASSERT_GT(circle.center.y - radius, NORTH_BORDER + DELTA)
72-
<< "Generated circle exceeds bounds";
71+
<< "Generated circle center exceeds bounds.\n" << error_msg(radius, circle);
7372

7473
ASSERT_LT(circle.center.y + radius, SOUTH_BORDER - DELTA)
75-
<< "Generated circle exceeds bounds";
74+
<< "Generated circle center exceeds bounds.\n" << error_msg(radius, circle);
7675
}
7776
);
7877
}
@@ -87,9 +86,9 @@ TEST(generateCircleTest, generateCircleTestRandomness) {
8786
abs(a.center.x - b.center.x) < EPS &&
8887
abs(a.center.y - b.center.y) < EPS;
8988
},
90-
[](Circle a) {
89+
[](Circle c) {
9190
std::ostringstream stream;
92-
stream << "{ { " << a.center.x << ", " << a.center.y << " }, " << a.radius << " }";
91+
stream << c;
9392
return stream.str();
9493
}
9594
);

WarmUp/MovingOn/ConsumeAnObject/test/test.cpp

+31-22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <cmath>
44

55
#include "scene.hpp"
6+
#include "operators.hpp"
67
#include "testing.hpp"
78

89
testing::Environment* const env =
@@ -31,14 +32,20 @@ namespace expected {
3132
}
3233
}
3334

34-
const float MIN = -10e6;
35-
const float MAX = 10e6;
35+
const float MIN = -100;
36+
const float MAX = 100;
3637

37-
std::string distance_error_msg(Point2D a, Point2D b) {
38+
std::string distance_error_msg(Point2D a, Point2D b, float expected, float actual) {
3839
std::ostringstream stream;
40+
stream << "Testing expression:\n"
41+
<< " d = distance(a, b)" << "\n";
3942
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";
4249
return stream.str();
4350
}
4451

@@ -54,20 +61,22 @@ TEST(distanceTest, distanceTestRandom) {
5461
std::tie(a, b) = data;
5562
float expected = expected::distance(a, b);
5663
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);
5865
}
5966
);
6067
}
6168

62-
std::string collision_error_msg(Circle circle1, Circle circle2) {
69+
std::string collision_error_msg(Circle circle1, Circle circle2, bool expected, bool actual) {
6370
std::ostringstream stream;
71+
stream << "Testing expression:\n"
72+
<< " collide = collision(circle1, circle2)" << "\n";
6473
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";
7180
return stream.str();
7281
}
7382

@@ -84,9 +93,9 @@ TEST(collisionTest, collisionTestTrue) {
8493
[] (std::tuple<Circle, Circle> data) {
8594
Circle c1, c2;
8695
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);
9099
}
91100
);
92101
}
@@ -104,9 +113,9 @@ TEST(collisionTest, collisionTestFalse) {
104113
[] (std::tuple<Circle, Circle> data) {
105114
Circle c1, c2;
106115
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);
110119
}
111120
);
112121
}
@@ -123,9 +132,9 @@ TEST(collisionTest, collisionTestRandom) {
123132
[] (std::tuple<Circle, Circle> data) {
124133
Circle c1, c2;
125134
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);
129138
}
130139
);
131140
}

WarmUp/MovingOn/DrawALine/test/test.cpp

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <gtest/gtest.h>
22

33
#include "scene.hpp"
4+
#include "operators.hpp"
45
#include "testing.hpp"
56

67
testing::Environment* const env =
@@ -26,10 +27,16 @@ namespace expected {
2627
}
2728
}
2829

29-
std::string error_msg(Point2D p) {
30+
std::string error_msg(Point2D p, Point2D expected, Point2D actual) {
3031
std::ostringstream stream;
32+
stream << "Testing expression:\n"
33+
<< " newPosition = adjustToBorders(position)" << "\n";
3134
stream << "Test data:" << "\n"
32-
<< " position = { " << p.x << ", " << p.y << " }" << "\n";
35+
<< " position = " << p << "\n";
36+
stream << "Expected result:\n"
37+
<< " newPosition = " << expected << "\n";
38+
stream << "Actual result:\n"
39+
<< " newPosition = " << actual << "\n";
3340
return stream.str();
3441
}
3542

@@ -40,9 +47,9 @@ TEST(adjustToBordersTest, adjustToBordersTestNorth) {
4047
return position;
4148
},
4249
[] (Point2D position) {
43-
float expected = NORTH_BORDER + RADIUS;
50+
Point2D expected = { position.x, NORTH_BORDER + RADIUS };
4451
Point2D actual = adjustToBorders(position);
45-
ASSERT_FLOAT_EQ(expected, actual.y) << error_msg(position);
52+
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(position, expected, actual);
4653
}
4754
);
4855
}
@@ -54,9 +61,9 @@ TEST(adjustToBordersTest, adjustToBordersTestSouth) {
5461
return position;
5562
},
5663
[] (Point2D position) {
57-
float expected = SOUTH_BORDER - RADIUS;
64+
Point2D expected = { position.x, SOUTH_BORDER - RADIUS };
5865
Point2D actual = adjustToBorders(position);
59-
ASSERT_FLOAT_EQ(expected, actual.y) << error_msg(position);
66+
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(position, expected, actual);
6067
}
6168
);
6269
}
@@ -68,9 +75,9 @@ TEST(adjustToBordersTest, adjustToBordersTestEast) {
6875
return position;
6976
},
7077
[] (Point2D position) {
71-
float expected = WEST_BORDER + RADIUS;
78+
Point2D expected = { WEST_BORDER + RADIUS, position.y };
7279
Point2D actual = adjustToBorders(position);
73-
ASSERT_FLOAT_EQ(expected, actual.x) << error_msg(position);
80+
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(position, expected, actual);
7481
}
7582
);
7683
}
@@ -82,9 +89,9 @@ TEST(adjustToBordersTest, adjustToBordersTestWest) {
8289
return position;
8390
},
8491
[] (Point2D position) {
85-
float expected = EAST_BORDER - RADIUS;
92+
Point2D expected = { EAST_BORDER - RADIUS, position.y };
8693
Point2D actual = adjustToBorders(position);
87-
ASSERT_FLOAT_EQ(expected, actual.x) << error_msg(position);
94+
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(position, expected, actual);
8895
}
8996
);
9097
}
@@ -99,8 +106,8 @@ TEST(adjustToBordersTest, adjustToBordersTestId) {
99106
[] (Point2D position) {
100107
Point2D expected = position;
101108
Point2D actual = adjustToBorders(position);
102-
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(position);
103-
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(position);
109+
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(position, expected, actual);
110+
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(position, expected, actual);
104111
}
105112
);
106113
}
@@ -114,8 +121,8 @@ TEST(adjustToBordersTest, adjustToBordersTestRandom) {
114121
[] (Point2D position) {
115122
Point2D expected = expected::adjustToBorders(position);
116123
Point2D actual = adjustToBorders(position);
117-
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(position);
118-
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(position);
124+
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(position, expected, actual);
125+
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(position, expected, actual);
119126
}
120127
);
121128
}
+16-11
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
11
#include <gtest/gtest.h>
22

33
#include "scene.hpp"
4+
#include "operators.hpp"
45
#include "testing.hpp"
56

67
testing::Environment* const env =
78
testing::AddGlobalTestEnvironment(new TestEnvironment);
89

9-
std::string error_msg(Direction direction) {
10+
std::string error_msg(Direction direction, Point2D expected, Point2D actual) {
1011
std::ostringstream stream;
11-
stream << "Incorrect vector for direction: "
12-
<< directionToString(direction) << "\n";
12+
stream << "Testing expression:\n"
13+
<< " vector = getDirection(" << direction << ")" << "\n";
14+
stream << "Expected result:\n"
15+
<< " vector = " << expected << "\n";
16+
stream << "Actual result:\n"
17+
<< " vector = " << actual << "\n";
1318
return stream.str();
1419
}
1520

1621
TEST(GetDirectionTest, GetDirectionNorth) {
1722
Point2D expected = { 0.0f, -1.0f };
1823
Point2D actual = getDirection(North);
19-
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(North);
20-
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(North);
24+
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(North, expected, actual);
25+
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(North, expected, actual);
2126
}
2227

2328
TEST(GetDirectionTest, GetDirectionEast) {
2429
Point2D expected = { 1.0f, 0.0f };
2530
Point2D actual = getDirection(East);
26-
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(East);
27-
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(East);
31+
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(East, expected, actual);
32+
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(East, expected, actual);
2833
}
2934

3035
TEST(GetDirectionTest, GetDirectionSouth) {
3136
Point2D expected = { 0.0f, 1.0f };
3237
Point2D actual = getDirection(South);
33-
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(South);
34-
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(South);;
38+
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(South, expected, actual);
39+
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(South, expected, actual);
3540
}
3641

3742
TEST(GetDirectionTest, GetDirectionWest) {
3843
Point2D expected = { -1.0f, 0.0f };
3944
Point2D actual = getDirection(West);
40-
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(West);
41-
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(West);
45+
ASSERT_FLOAT_EQ(expected.x, actual.x) << error_msg(West, expected, actual);
46+
ASSERT_FLOAT_EQ(expected.y, actual.y) << error_msg(West, expected, actual);
4247
}

WarmUp/MovingOn/HuntingBugs/src/generate.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#include <cstdlib>
44

55
Circle generateCircle(float radius) {
6-
Circle circle = { { 600, 150 }, radius };
6+
Circle circle = { { 0, 0 }, 0 };
77
circle.center.x = generateCoordinate(WEST_BORDER + radius, EAST_BORDER - radius);
88
circle.center.y = generateCoordinate(NORTH_BORDER + radius, SOUTH_BORDER - radius);
9+
circle.radius = radius;
910
return circle;
1011
}
1112

0 commit comments

Comments
 (0)