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
|
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
class ChannelNodeTest {
@Test void doesCorrectExceptions() {
// Should throw an error when:
// Invalid constructor argument
// Invalid member function argument
IChannelNode testNodeA = new ChannelNode();
IChannelNode testNodeB = new ChannelNode();
// Null map should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, null));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(null, IChannelNode.Direction.BOTH));
// Null direction should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(new HashMap<>(), null));
// Self endpoint should throw
Map<IChannelNode, Integer> temp = new HashMap<>();
temp.put(testNodeA, 1);
assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(temp, IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(temp, IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(temp, IChannelNode.Direction.BOTH));
// Should not throw
assertDoesNotThrow(() -> testNodeA.setConnections(new HashMap<>(), IChannelNode.Direction.INCOMING));
assertDoesNotThrow(() -> testNodeA.setConnections(new HashMap<>(), IChannelNode.Direction.OUTGOING));
assertDoesNotThrow(() -> testNodeA.setConnections(new HashMap<>(), IChannelNode.Direction.BOTH));
// Null endpoint should throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(null, null, -1));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(null, IChannelNode.Direction.INCOMING, 1));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(null, IChannelNode.Direction.OUTGOING, 1));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(null, IChannelNode.Direction.BOTH, 1));
// Null direction should throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(testNodeB, null, 1));
// Self endpoint should throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(testNodeA, IChannelNode.Direction.INCOMING, 1));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(testNodeA, IChannelNode.Direction.OUTGOING, 1));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(testNodeA, IChannelNode.Direction.BOTH, 1));
// Negative connections should throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(testNodeB, IChannelNode.Direction.INCOMING, -1));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(testNodeB, IChannelNode.Direction.OUTGOING, -1));
assertThrows(IllegalArgumentException.class, () -> testNodeA.setNumConnections(testNodeB, IChannelNode.Direction.BOTH, -1));
// Should not throw
assertDoesNotThrow(() -> testNodeA.setNumConnections(testNodeB, IChannelNode.Direction.INCOMING, 10));
assertDoesNotThrow(() -> testNodeA.setNumConnections(testNodeB, IChannelNode.Direction.OUTGOING, 10));
assertDoesNotThrow(() -> testNodeA.setNumConnections(testNodeB, IChannelNode.Direction.BOTH, 3));
assertDoesNotThrow(() -> testNodeB.setNumConnections(testNodeA, IChannelNode.Direction.INCOMING, 3));
assertDoesNotThrow(() -> testNodeB.setNumConnections(testNodeA, IChannelNode.Direction.OUTGOING, 5));
assertDoesNotThrow(() -> testNodeB.setNumConnections(testNodeA, IChannelNode.Direction.BOTH, 90));
// Null endpoint should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, null));
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(null, IChannelNode.Direction.BOTH));
// Self endpoint should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeA, IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeA, IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeA, IChannelNode.Direction.BOTH));
// Null direction should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnection(testNodeB, null));
assertThrows(IllegalArgumentException.class, () -> testNodeB.addConnection(testNodeA, null));
// Should not throw
assertDoesNotThrow(() -> testNodeA.addConnection(testNodeB, IChannelNode.Direction.INCOMING));
assertDoesNotThrow(() -> testNodeA.addConnection(testNodeB, IChannelNode.Direction.OUTGOING));
assertDoesNotThrow(() -> testNodeA.addConnection(testNodeB, IChannelNode.Direction.BOTH));
// Null iterable should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, null));
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(null, IChannelNode.Direction.BOTH));
// Null direction should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeB}), null));
assertThrows(IllegalArgumentException.class, () -> testNodeB.addConnections(List.of(new IChannelNode[]{testNodeA}), null));
// Self endpoint should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.BOTH));
// Should not throw
assertDoesNotThrow(() -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeB}), IChannelNode.Direction.INCOMING));
assertDoesNotThrow(() -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeB}), IChannelNode.Direction.OUTGOING));
assertDoesNotThrow(() -> testNodeA.addConnections(List.of(new IChannelNode[]{testNodeB}), IChannelNode.Direction.BOTH));
// Null node should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, null));
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(null, IChannelNode.Direction.BOTH));
// Null direction should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeB, null));
assertThrows(IllegalArgumentException.class, () -> testNodeB.removeConnection(testNodeA, null));
// Self node should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeA, IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeA, IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnection(testNodeA, IChannelNode.Direction.BOTH));
// Null iterable should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, null));
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(null, IChannelNode.Direction.BOTH));
// Null direction should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{}), null));
// Self node should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.removeConnections(List.of(new IChannelNode[]{testNodeA}), IChannelNode.Direction.BOTH));
// Null direction should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.clearConnections(null));
// Null node should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, null));
assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.INCOMING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.OUTGOING));
assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.BOTH));
// Null direction should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(testNodeB, null));
// Null direction should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.getNumConnections(null));
assertDoesNotThrow(() -> testNodeA.getNumConnections(IChannelNode.Direction.INCOMING));
assertDoesNotThrow(() -> testNodeA.getNumConnections(IChannelNode.Direction.OUTGOING));
assertDoesNotThrow(() -> testNodeA.getNumConnections(IChannelNode.Direction.BOTH));
// Null direction should always throw
assertThrows(IllegalArgumentException.class, () -> testNodeA.getConnections(null));
assertDoesNotThrow(() -> testNodeA.getConnections(IChannelNode.Direction.INCOMING));
assertDoesNotThrow(() -> testNodeA.getConnections(IChannelNode.Direction.OUTGOING));
assertDoesNotThrow(() -> testNodeA.getConnections(IChannelNode.Direction.BOTH));
}
} // End of ChannelNodeTest
|