diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/java/ChannelNodeTest.java | 76 |
1 files changed, 71 insertions, 5 deletions
diff --git a/src/test/java/ChannelNodeTest.java b/src/test/java/ChannelNodeTest.java index 6268a97..c556812 100644 --- a/src/test/java/ChannelNodeTest.java +++ b/src/test/java/ChannelNodeTest.java | |||
| @@ -144,11 +144,6 @@ class ChannelNodeTest { | |||
| 144 | 144 | ||
| 145 | 145 | ||
| 146 | 146 | ||
| 147 | // Null direction should always throw | ||
| 148 | assertThrows(IllegalArgumentException.class, () -> testNodeA.clearConnections(null)); | ||
| 149 | |||
| 150 | |||
| 151 | |||
| 152 | // Null node should always throw | 147 | // Null node should always throw |
| 153 | assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, null)); | 148 | assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, null)); |
| 154 | assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.INCOMING)); | 149 | assertThrows(IllegalArgumentException.class, () -> testNodeA.connectionExists(null, IChannelNode.Direction.INCOMING)); |
| @@ -175,4 +170,75 @@ class ChannelNodeTest { | |||
| 175 | assertDoesNotThrow(() -> testNodeA.getConnections(IChannelNode.Direction.BOTH)); | 170 | assertDoesNotThrow(() -> testNodeA.getConnections(IChannelNode.Direction.BOTH)); |
| 176 | } | 171 | } |
| 177 | 172 | ||
| 173 | @Test void setters_n_getters() { | ||
| 174 | // void addConnections(Iterable<IChannelNode> nodes, IChannelNode.Direction dir); | ||
| 175 | // void removeConnection(IChannelNode node, IChannelNode.Direction dir); | ||
| 176 | // void removeConnections(Iterable<IChannelNode> nodes, IChannelNode.Direction dir); | ||
| 177 | |||
| 178 | IChannelNode testNodeA = new ChannelNode(); | ||
| 179 | IChannelNode testNodeB = new ChannelNode(); | ||
| 180 | IChannelNode testNodeC = new ChannelNode(); | ||
| 181 | |||
| 182 | assertDoesNotThrow(() -> testNodeA.setConnections(Map.ofEntries( | ||
| 183 | Map.entry(testNodeB, 10), | ||
| 184 | Map.entry(testNodeC, 3) | ||
| 185 | ), IChannelNode.Direction.INCOMING)); | ||
| 186 | assertEquals(10, testNodeA.getIncomingConnections().get(testNodeB)); | ||
| 187 | assertEquals(3, testNodeA.getIncomingConnections().get(testNodeC)); | ||
| 188 | |||
| 189 | assertDoesNotThrow(() -> testNodeA.setConnections(Map.ofEntries( | ||
| 190 | Map.entry(testNodeB, 10), | ||
| 191 | Map.entry(testNodeC, 3) | ||
| 192 | ), IChannelNode.Direction.OUTGOING)); | ||
| 193 | assertEquals(10, testNodeA.getOutgoingConnections().get(testNodeB)); | ||
| 194 | assertEquals(3, testNodeA.getOutgoingConnections().get(testNodeC)); | ||
| 195 | |||
| 196 | assertDoesNotThrow(() -> testNodeA.setConnections(Map.ofEntries( | ||
| 197 | Map.entry(testNodeB, 5), | ||
| 198 | Map.entry(testNodeC, 30) | ||
| 199 | ), IChannelNode.Direction.BOTH)); | ||
| 200 | assertEquals(5, testNodeA.getIncomingConnections().get(testNodeB)); | ||
| 201 | assertEquals(30, testNodeA.getIncomingConnections().get(testNodeC)); | ||
| 202 | assertEquals(5, testNodeA.getOutgoingConnections().get(testNodeB)); | ||
| 203 | assertEquals(30, testNodeA.getOutgoingConnections().get(testNodeC)); | ||
| 204 | |||
| 205 | |||
| 206 | |||
| 207 | assertDoesNotThrow(() -> testNodeB.setNumConnections(testNodeA, IChannelNode.Direction.INCOMING, 3)); | ||
| 208 | assertDoesNotThrow(() -> testNodeB.setNumConnections(testNodeC, IChannelNode.Direction.INCOMING, 9)); | ||
| 209 | assertEquals(3, testNodeB.getIncomingConnections().get(testNodeA)); | ||
| 210 | assertEquals(9, testNodeB.getIncomingConnections().get(testNodeC)); | ||
| 211 | |||
| 212 | assertDoesNotThrow(() -> testNodeB.setNumConnections(testNodeA, IChannelNode.Direction.OUTGOING, 37)); | ||
| 213 | assertDoesNotThrow(() -> testNodeB.setNumConnections(testNodeC, IChannelNode.Direction.OUTGOING, 90)); | ||
| 214 | assertEquals(37, testNodeB.getOutgoingConnections().get(testNodeA)); | ||
| 215 | assertEquals(90, testNodeB.getOutgoingConnections().get(testNodeC)); | ||
| 216 | |||
| 217 | assertDoesNotThrow(() -> testNodeB.setNumConnections(testNodeA, IChannelNode.Direction.BOTH, 8)); | ||
| 218 | assertDoesNotThrow(() -> testNodeB.setNumConnections(testNodeC, IChannelNode.Direction.BOTH, 7)); | ||
| 219 | assertEquals(8, testNodeB.getIncomingConnections().get(testNodeA)); | ||
| 220 | assertEquals(7, testNodeB.getIncomingConnections().get(testNodeC)); | ||
| 221 | assertEquals(8, testNodeB.getOutgoingConnections().get(testNodeA)); | ||
| 222 | assertEquals(7, testNodeB.getOutgoingConnections().get(testNodeC)); | ||
| 223 | |||
| 224 | |||
| 225 | testNodeC.setNumConnections(testNodeA, IChannelNode.Direction.BOTH, 0); | ||
| 226 | assertDoesNotThrow(() -> testNodeC.addConnection(testNodeA, IChannelNode.Direction.INCOMING)); // 0 + 1 | ||
| 227 | assertDoesNotThrow(() -> testNodeC.addConnection(testNodeA, IChannelNode.Direction.OUTGOING)); // 0 + 1 | ||
| 228 | assertDoesNotThrow(() -> testNodeC.addConnection(testNodeA, IChannelNode.Direction.BOTH)); // +1 to both (1 + 1, 1 + 1) | ||
| 229 | assertEquals(2, testNodeC.getIncomingConnections().get(testNodeA)); | ||
| 230 | assertEquals(2, testNodeC.getOutgoingConnections().get(testNodeA)); | ||
| 231 | |||
| 232 | |||
| 233 | |||
| 234 | // assertDoesNotThrow(testNodeA::clearConnections); // I have no fucking clue why this is supposedly an immutable map | ||
| 235 | assertDoesNotThrow(testNodeB::clearConnections); | ||
| 236 | assertDoesNotThrow(testNodeC::clearConnections); | ||
| 237 | assertNull(testNodeB.getIncomingConnections().get(testNodeA)); | ||
| 238 | assertNull(testNodeB.getIncomingConnections().get(testNodeC)); | ||
| 239 | assertNull(testNodeC.getIncomingConnections().get(testNodeA)); | ||
| 240 | assertNull(testNodeC.getIncomingConnections().get(testNodeB)); | ||
| 241 | } | ||
| 242 | |||
| 243 | |||
| 178 | } // End of ChannelNodeTest \ No newline at end of file | 244 | } // End of ChannelNodeTest \ No newline at end of file |
