Skip to content

Commit e942559

Browse files
committed
Added tests for new road functions
1 parent c6ef3b6 commit e942559

File tree

3 files changed

+90
-4
lines changed

3 files changed

+90
-4
lines changed

include/Road.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class Road {
2020
Coordinate start;
2121
Coordinate end;
2222

23-
Coordinate getStart();
24-
2523
bool equals(const Road& otherRoad);
2624
bool equals(const Coordinate& otherStart, const Coordinate& otherEnd);
2725

tests/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
int main() {
44
return UnitTest::RunAllTests();
5-
}
5+
}
6+

tests/test_Roads.cpp

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,95 @@
88
#include "Road.h"
99
#include "Util.h"
1010

11-
TEST(road_constructor_1){
11+
TEST(road_constructor_good){
1212
Coordinate start = Coordinate(0,0);
1313
Coordinate end = Coordinate(0,1);
14+
Player test_player("tester");
15+
Road test_road(start, end, test_player);
16+
17+
CHECK(test_road.start == start);
18+
CHECK(test_road.end == end);
19+
}
20+
21+
TEST(road_constuctor_bad){
22+
Coordinate start = Coordinate(0,0);
23+
Coordinate end = Coordinate(3,4);
24+
25+
Player test_player("tester");
26+
//test start == end
27+
try {
28+
Road test_road_1(start, start, test_player);
29+
CHECK(false);
30+
} catch (int n) {
31+
CHECK(n == -1);
32+
}
33+
//test road too long
34+
try {
35+
Road test_road_2(start, end, test_player);
36+
CHECK(false);
37+
} catch (int n) {
38+
CHECK(n == -1);
39+
}
40+
41+
}
42+
43+
TEST(road_equals_Road){
44+
Coordinate start_1 = Coordinate(0,0);
45+
Coordinate end_1 = Coordinate(0,1);
46+
Player test_player_1("tester_1");
47+
Road test_road_1(start_1, end_1, test_player_1);
48+
49+
50+
Coordinate start_2 = Coordinate(0,1);
51+
Coordinate end_2 = Coordinate(0,0);
52+
Player test_player_2("tester_2");
53+
Road test_road_2(start_2, end_2, test_player_2);
54+
55+
Coordinate start_3 = Coordinate(1,1);
56+
Coordinate end_3 = Coordinate(1,2);
57+
Player test_player_3("tester_3");
58+
Road test_road_3(start_3, end_3, test_player_3);
59+
60+
CHECK(test_road_1.equals(test_road_2));
61+
CHECK(!test_road_1.equals(test_road_3));
62+
}
63+
64+
TEST(road_equals_Coordinate){
65+
Coordinate start_1 = Coordinate(0,0);
66+
Coordinate end_1 = Coordinate(0,1);
67+
Player test_player_1("tester_1");
68+
Road test_road_1(start_1, end_1, test_player_1);
69+
70+
71+
Coordinate start_2 = Coordinate(0,1);
72+
Coordinate end_2 = Coordinate(0,0);
73+
74+
Coordinate start_3 = Coordinate(1,1);
75+
Coordinate end_3 = Coordinate(1,2);
76+
77+
CHECK(test_road_1.equals(start_2, end_2));
78+
CHECK(!test_road_1.equals(start_3, end_3));
1479
}
1580

81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+

0 commit comments

Comments
 (0)