forked from ee538/Summer22_Project_Grader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trojanmap_test_grader9.cc
143 lines (123 loc) · 7.37 KB
/
trojanmap_test_grader9.cc
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "gtest/gtest.h"
#include "src/lib/trojanmap.h"
TEST(TrojanMapTest, TSP_brute_force) {
TrojanMap m;
std::vector<std::string> input{"1873056015", "6905329551", "213332060", "1931345270"}; // Input location ids
auto result = m.TravellingTrojan_Brute_force(input);
std::cout << "My path length: " << result.first << "miles" << std::endl; // Print the result path lengths
std::vector<std::string> gt{"1873056015", "213332060", "1931345270", "6905329551", "1873056015"}; // Expected order
std::cout << "GT path length: " << m.CalculatePathLength(gt) << "miles" << std::endl; // Print the gt path lengths
bool flag = false;
if (gt == result.second[result.second.size()-1]) // clockwise
flag = true;
std::reverse(gt.begin(),gt.end()); // Reverse the expected order because the counterclockwise result is also correct
if (gt == result.second[result.second.size()-1])
flag = true;
EXPECT_EQ(flag, true);
}
TEST(TrojanMapTest, TSP_brute_force_2) {
TrojanMap m;
std::vector<std::string> input{"1862312636", "7424270441", "67666219", "4015405548", "4015203110", "6807439002"}; // Input location ids
auto result = m.TravellingTrojan_Brute_force(input);
std::cout << "My path length: " << result.first << "miles" << std::endl; // Print the result path lengths
std::vector<std::string> gt{"1862312636", "4015405548", "4015203110", "6807439002", "7424270441", "67666219", "1862312636"}; // Expected order
std::cout << "GT path length: " << m.CalculatePathLength(gt) << "miles" << std::endl; // Print the groundtruth path lengths
bool flag = false;
if (gt == result.second[result.second.size()-1]) // clockwise
flag = true;
std::reverse(gt.begin(),gt.end()); // Reverse the expected order because the counterclockwise result is also correct
if (gt == result.second[result.second.size()-1]) // counterclockwise
flag = true;
EXPECT_EQ(flag, true);
}
TEST(TrojanMapTest, TSP) {
TrojanMap m;
std::vector<std::string> input{"1873056015", "6905329551", "213332060", "1931345270"}; // Input location ids
auto result = m.TravellingTrojan_Backtracking(input);
std::cout << "My path length: " << result.first << "miles" << std::endl; // Print the result path lengths
std::vector<std::string> gt{"1873056015", "213332060", "1931345270", "6905329551", "1873056015"}; // Expected order
std::cout << "GT path length: " << m.CalculatePathLength(gt) << "miles" << std::endl; // Print the gt path lengths
bool flag = false;
if (gt == result.second[result.second.size()-1]) // clockwise
flag = true;
std::reverse(gt.begin(),gt.end()); // Reverse the expected order because the counterclockwise result is also correct
if (gt == result.second[result.second.size()-1])
flag = true;
EXPECT_EQ(flag, true);
}
TEST(TrojanMapTest, TSP2) {
TrojanMap m;
std::vector<std::string> input{"1862312636", "7424270441", "67666219", "4015405548", "4015203110", "6807439002"}; // Input location ids
auto result = m.TravellingTrojan_Backtracking(input);
std::cout << "My path length: " << result.first << "miles" << std::endl; // Print the result path lengths
std::vector<std::string> gt{"1862312636", "4015405548", "4015203110", "6807439002", "7424270441", "67666219", "1862312636"}; // Expected order
std::cout << "GT path length: " << m.CalculatePathLength(gt) << "miles" << std::endl; // Print the groundtruth path lengths
bool flag = false;
if (gt == result.second[result.second.size()-1]) // clockwise
flag = true;
std::reverse(gt.begin(),gt.end()); // Reverse the expected order because the counterclockwise result is also correct
if (gt == result.second[result.second.size()-1]) // counterclockwise
flag = true;
EXPECT_EQ(flag, true);
}
TEST(TrojanMapTest, TSP_2opt) {
TrojanMap m;
std::vector<std::string> input{"1873056015", "6905329551", "213332060", "1931345270"}; // Input location ids
auto result = m.TravellingTrojan_2opt(input);
std::cout << "My path length: " << result.first << "miles" << std::endl; // Print the result path lengths
std::vector<std::string> gt{"1873056015", "213332060", "1931345270", "6905329551", "1873056015"}; // Expected order
std::cout << "GT path length: " << m.CalculatePathLength(gt) << "miles" << std::endl; // Print the gt path lengths
bool flag = false;
if (gt == result.second[result.second.size()-1]) // clockwise
flag = true;
std::reverse(gt.begin(),gt.end()); // Reverse the expected order because the counterclockwise result is also correct
if (gt == result.second[result.second.size()-1])
flag = true;
EXPECT_EQ(flag, true);
}
TEST(TrojanMapTest, TSP_2opt_2) {
TrojanMap m;
std::vector<std::string> input{"1862312636", "7424270441", "67666219", "4015405548", "4015203110", "6807439002"}; // Input location ids
auto result = m.TravellingTrojan_2opt(input);
std::cout << "My path length: " << result.first << "miles" << std::endl; // Print the result path lengths
std::vector<std::string> gt{"1862312636", "4015405548", "4015203110", "6807439002", "7424270441", "67666219", "1862312636"}; // Expected order
std::cout << "GT path length: " << m.CalculatePathLength(gt) << "miles" << std::endl; // Print the groundtruth path lengths
bool flag = false;
if (gt == result.second[result.second.size()-1]) // clockwise
flag = true;
std::reverse(gt.begin(),gt.end()); // Reverse the expected order because the counterclockwise result is also correct
if (gt == result.second[result.second.size()-1]) // counterclockwise
flag = true;
EXPECT_EQ(flag, true);
}
// copied below, just for ease of points assignment
TEST(TrojanMapTest, TSP_2opt_3) {
TrojanMap m;
std::vector<std::string> input{"1862312636", "7424270441", "67666219", "4015405548", "4015203110", "6807439002"}; // Input location ids
auto result = m.TravellingTrojan_2opt(input);
std::cout << "My path length: " << result.first << "miles" << std::endl; // Print the result path lengths
std::vector<std::string> gt{"1862312636", "4015405548", "4015203110", "6807439002", "7424270441", "67666219", "1862312636"}; // Expected order
std::cout << "GT path length: " << m.CalculatePathLength(gt) << "miles" << std::endl; // Print the groundtruth path lengths
bool flag = false;
if (gt == result.second[result.second.size()-1]) // clockwise
flag = true;
std::reverse(gt.begin(),gt.end()); // Reverse the expected order because the counterclockwise result is also correct
if (gt == result.second[result.second.size()-1]) // counterclockwise
flag = true;
EXPECT_EQ(flag, true);
}
TEST(TrojanMapTest, TSP_2opt_4) {
TrojanMap m;
std::vector<std::string> input{"1862312636", "7424270441", "67666219", "4015405548", "4015203110", "6807439002"}; // Input location ids
auto result = m.TravellingTrojan_2opt(input);
std::cout << "My path length: " << result.first << "miles" << std::endl; // Print the result path lengths
std::vector<std::string> gt{"1862312636", "4015405548", "4015203110", "6807439002", "7424270441", "67666219", "1862312636"}; // Expected order
std::cout << "GT path length: " << m.CalculatePathLength(gt) << "miles" << std::endl; // Print the groundtruth path lengths
bool flag = false;
if (gt == result.second[result.second.size()-1]) // clockwise
flag = true;
std::reverse(gt.begin(),gt.end()); // Reverse the expected order because the counterclockwise result is also correct
if (gt == result.second[result.second.size()-1]) // counterclockwise
flag = true;
EXPECT_EQ(flag, true);
}