-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphTest.java
140 lines (119 loc) · 3.58 KB
/
GraphTest.java
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
/**
* Filename: TestHashTableDeb.java
* Project: p3
* Authors: Debra Deppeler ([email protected])
*
* Semester: Fall 2018
* Course: CS400
*
* Due Date: before 10pm on 10/29
* Version: 1.0
*
* Credits: None so far
*
* Bugs:
*/
import org.junit.After;
import java.io.FileNotFoundException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author nvsmith
*
*/
public class GraphTest {
static Graph graphObject;
/** Initialize empty graph to be used in each test */
@BeforeEach
public void setUp() throws Exception {
// TODO: change HashTable for final solution
graphObject = new Graph();
}
/** make sure that variables are reset */
@AfterEach
public void tearDown() throws Exception {
graphObject = null;
}
@Test
public void test000_addEdge() {
graphObject = new Graph();
graphObject.addVertex("nate");
graphObject.addVertex("Smith");
graphObject.addEdge("nate", "Smith");
}
@Test
public void test001_boundary_conditions_add_Vertex() {
graphObject.addVertex("Nate");
graphObject.addVertex(null);
graphObject.addVertex("Nate");
assertEquals(1,graphObject.order());
}
@Test
public void test002_boundary_conditions_removeVertex() {
graphObject.addVertex("Nate");
graphObject.removeVertex("Van");
graphObject.addVertex("Smith");
graphObject.removeVertex(null);
assertEquals(2,graphObject.order());
}
@Test
public void test003_boundary_conditions_addEdge() {
graphObject.addEdge("Nate","Smith");
assertEquals(2,graphObject.order());
graphObject.addEdge("Nate", "Smith");
assertEquals(1,graphObject.size());
graphObject.addEdge("Nate", "Van");
assertEquals(3,graphObject.order());
assertEquals(2,graphObject.size());
}
@Test
public void test004_boundary_condition_removeEdge() {
graphObject.addEdge("Nate", "Smith");
graphObject.removeEdge("Nate", "Van");
assertEquals(1,graphObject.size());
graphObject.removeEdge("Van","Smith");
assertEquals(1,graphObject.size());
graphObject.addVertex("Van");
graphObject.removeEdge("Van", "Smith");
assertEquals(1,graphObject.size());
}
@Test
public void test005_getAllVertices_Returns_correctly() {
graphObject.addEdge("Nate", "Smith");
Set<String> test = new HashSet<String>();
test = graphObject.getAllVertices();
if(!test.contains("Nate")||!test.contains("Smith"))
fail("Set doesn't contain correct vertices");
graphObject.addEdge("Nate", "Van");
graphObject.addEdge("Van", "Smith");
test = graphObject.getAllVertices();
if(!test.contains("Van"))
fail("Set doesn't contain correct vertices");
assertEquals(3,test.size());
}
@Test
public void test006_getAdjacentVertices_returns_correctly() {
graphObject.addEdge("Nate", "Smith");
graphObject.addEdge("Nate", "Van");
graphObject.addEdge("Van", "Smith");
List<String> smith = new ArrayList<String>();
smith = graphObject.getAdjacentVerticesOf("Smith");
assertEquals(0,smith.size());
List<String> nate = new ArrayList<String>();
nate = graphObject.getAdjacentVerticesOf("Nate");
assertEquals(2,nate.size());
}
}