-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkTest.java
130 lines (107 loc) · 3.8 KB
/
NetworkTest.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
/**
* JUnit test program for methods in Network Class.
* Course: 5DV133
* Written by: Thomas Sarlin id15tsn
* @Author Group 15 - 5DV133 vt2016
* @Version 1.0
*/
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Test for class Network.
*/
public class NetworkTest {
/**
* Testing constructor with accepted values.
*
* @throws Exception if constructor is not working as intended.
*/
@Test
public void shouldBeAbleToCreate() throws Exception {
new Network(40,10,15,10,100);
}
/**
* Testing if constructor throws exception as intended when
* distance is larger than range.
*
* @throws Exception if constructor works as intended.
*/
@Test (expected = Exception.class)
public void tryCreatingWithInvalidRange() throws Exception{
new Network(40,15,10,10,100);
}
/**
* Testing if constructor throws exception as intended when
* breakpoint is larger than endpoint.
*
* @throws Exception if constructor works as intended.
*/
@Test (expected = Exception.class)
public void tryCreatingWithInvalidBreakEndPoints() throws Exception{
new Network(40,10,15,100,10);
}
/**
* Testing if constructor throws exception as intended when
* using an invalid field size.
* @throws Exception if constructor works as intended.
*/
@Test (expected = Exception.class)
public void tryCreatingWithInvalidFieldSize() throws Exception {
new Network(-10,10,15,10,100);
}
/**
* Testing so that the network is able to set neighbours.
* @throws Exception if neighbours are incorrect.
*/
@Test
public void shouldBeAbleToSetNeighbours() throws Exception{
Network n = new Network(50,10,15,10,100);
Node[][] array = n.getAllNodes();
assertEquals(3,array[0][0].getNeighbours().size());
assertEquals(8,array[3][3].getNeighbours().size());
}
/**
* Tests different ranges of the network and how well the network is
* able to add neighbours using the pythagoras theorem.
*
* @throws Exception if range is incorrect.
*/
@Test
public void shouldBeAbleToUseDifferentRanges() throws Exception{
Network n = new Network(50,1,2,10,100);
Node[][] array = n.getAllNodes();
assertEquals(12,array[10][10].getNeighbours().size());
n = new Network(50,1,5,10,100);
array = n.getAllNodes();
assertEquals(80,array[10][10].getNeighbours().size());
}
/**
* Testing if the network sets the correct neighbours.
* @throws Exception if Network was unable to set correct neighbours.
*/
@Test
public void shouldAddCorrectNeighbours()throws Exception{
Network n = new Network(50,10,15,10,100);
Node[][] array = n.getAllNodes();
assertEquals(8,array[5][5].getNeighbours().size());
assertEquals(204,array[5][5].getNeighbours().get(0).getNodeID());
assertEquals(205,array[5][5].getNeighbours().get(1).getNodeID());
assertEquals(206,array[5][5].getNeighbours().get(2).getNodeID());
assertEquals(254,array[5][5].getNeighbours().get(3).getNodeID());
assertEquals(256,array[5][5].getNeighbours().get(4).getNodeID());
assertEquals(304,array[5][5].getNeighbours().get(5).getNodeID());
assertEquals(305,array[5][5].getNeighbours().get(6).getNodeID());
assertEquals(306,array[5][5].getNeighbours().get(7).getNodeID());
}
/**
* Testing timeSteps is able to end program as intended.
* @throws Exception if isEndOfProgram returns false.
*/
@Test
public void tryEndOfProgram() throws Exception{
Network n = new Network(10,10,15,2,10);
for(int i=0;i<10;i++)
n.timeStep();
assertTrue(n.isEndOfProgram());
}
}