-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkTest.java
More file actions
179 lines (163 loc) · 6.68 KB
/
LinkTest.java
File metadata and controls
179 lines (163 loc) · 6.68 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
/*
1. getLength() black-box returns the length of a link
2. getAdj() black-box
2a. getAdj() returns city1 if c is city2
2b. getAdj() returns city2 if c is city1
3. isUsed() black-box
3a. isUsed() returns true if the link is on a shortest path
3b. isUsed() returns false if the link is not on a shortest path
4. setUsed() withe-box set set used to u
4a. setUsed() set to true
4a. setUsed() set to false
5. testToString() black-box
5a. testToString() returns a return a string representation of the Link in sorted order
5b. testToString() returns a return a string representation of the Link in unsorted order
6. compareTo() black-box
6a. compareTo() returns 0 if both links have the same city1 and city2
6b. compareTo() returns negative int if this.city1 < l.city1
6c. compareTo() returns negative int if city1 are equal and this.city2 < l.city2
6d. compareTo() returns a positive int if none of the previous conditions occur
*/
class LinkTest {
public static final String city1Name = "City1";
public static final String city2Name = "City2";
public static final String city3Name = "City3";
public static final int cityDistance = 3;
/* 1. getLength() returns the length length of a link */
@Test
void getLength() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
Link link = new Link(city1, city2, cityDistance);
int expectedDistance = cityDistance;
int resultDistance = link.getLength();
City.cities.clear();
assertEquals(expectedDistance, resultDistance, "getLength returned wrong value");
}
/* 2. getAdj() black-box */
/* 2a. getAdj() returns city1 if c is city2 */
@Test
void getAdj_city1() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
Link link = new Link(city1, city2, cityDistance);
String expectedString = city1Name;
String resultString = link.getAdj(city2).toString();
City.cities.clear();
assertEquals(expectedString, resultString, "getAdj with city2 returned wrong city");
}
/* 2b. getAdj() returns city2 if c is city1 */
@Test
void getAdj_city2() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
Link link = new Link(city1, city2, cityDistance);
String expectedString = city2Name;
String resultString = link.getAdj(city1).toString();
City.cities.clear();
assertEquals(expectedString, resultString, "getAdj with city1 returned wrong city");
}
/* 3. isUsed() black-box */
/* 3a. isUsed() returns true if the link is on a shortest path */
@Test
void isUsed_true() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
Link link = new Link(city1, city2, cityDistance);
link.setUsed(true);
assertTrue(link.isUsed() == true, "true was not returned on the path");
}
/* 3b. isUsed() returns false if the link is not on a shortest path */
@Test
void isUsed_false() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
Link link = new Link(city1, city2, cityDistance);
link.setUsed(false);
assertTrue(link.isUsed() == false, "false was not returned on the path");
}
/* 4. setUsed() black-box */
/* 4a. setUsed() set to true */
@Test
void setUsed_true() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
Link link = new Link(city1, city2, cityDistance);
link.setUsed(true);
assertTrue(link.used == true, "user was not set to true");
}
/* 4a. setUsed() set to true */
@Test
void setUsed_false() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
Link link = new Link(city1, city2, cityDistance);
link.setUsed(false);
assertTrue(link.used == false, "user was not set to false");
}
/* 5. testToString() black-box */
/* 5a. testToString() returns a return a string representation of the Link in sorted order */
@Test
void testToString_sorted() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
Link link = new Link(city1, city2, cityDistance);
String expectedString = city1Name + " " + cityDistance + " " + city2Name;
String resultString = link.toString();
City.cities.clear();
assertEquals(expectedString, resultString, "toString with sorted city names returned wrong string");
}
/* 5b. testToString() returns a return a string representation of the Link in unsorted order */
@Test
void testToString_unsorted() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
Link link = new Link(city2, city1, cityDistance);
String expectedString = city1Name + " " + cityDistance + " " + city2Name;
String resultString = link.toString();
City.cities.clear();
assertEquals(expectedString, resultString, "toString with unsorted city names returned wrong string");
}
/* 6. compareTo() black-box */
/* 6a. compareTo() returns 0 if both links have the same city1 and city2 */
@Test
void compareTo_equals() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
Link link1 = new Link(city1, city2, cityDistance);
Link link2 = new Link(city1, city2, cityDistance);
assertTrue(link1.compareTo(link2) == 0, "compare was not 0");
}
/* 6b. compareTo() returns negative int if this.city1 < l.city1 */
@Test
void compareTo_sameCity1() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
City city3 = new City(city3Name);
Link link1 = new Link(city2, city1, cityDistance);
Link link2 = new Link(city3, city1, cityDistance);
assertTrue(link1.compareTo(link2) < 0, "compare was not negative");
}
/* 6c. compareTo() returns negative int if the city1 are equal and this.city2 < l.city2 */
@Test
void compareTo_sameCity2() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
City city3 = new City(city3Name);
Link link1 = new Link(city1, city2, cityDistance);
Link link2 = new Link(city1, city3, cityDistance);
assertTrue(link1.compareTo(link2) < 0, "compare was not negative");
}
/* 6d. compareTo() returns a positive int if none of the previous conditions occur */
@Test
void compareTo_differentCities() {
City city1 = new City(city1Name);
City city2 = new City(city2Name);
City city3 = new City(city3Name);
Link link1 = new Link(city2, city3, cityDistance);
Link link2 = new Link(city1, city2, cityDistance);
assertTrue(link1.compareTo(link2) > 0, "compare was not positive");
}
}