From 7b84eb10c7c70dc83acd21afcc1ae631369428eb Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Wed, 1 Oct 2025 21:26:08 -0500 Subject: Implement ChannelNode --- src/test/java/ChannelNodeTest.java | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/test/java/ChannelNodeTest.java') diff --git a/src/test/java/ChannelNodeTest.java b/src/test/java/ChannelNodeTest.java index 5623d72..6268a97 100644 --- a/src/test/java/ChannelNodeTest.java +++ b/src/test/java/ChannelNodeTest.java @@ -23,6 +23,14 @@ class ChannelNodeTest { // Null direction should always throw assertThrows(IllegalArgumentException.class, () -> testNodeA.setConnections(new HashMap<>(), null)); + // Self endpoint should throw + Map 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)); @@ -30,6 +38,36 @@ class ChannelNodeTest { + // 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)); @@ -45,6 +83,11 @@ class ChannelNodeTest { 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 @@ -62,6 +105,10 @@ class ChannelNodeTest { 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 @@ -113,8 +160,19 @@ class ChannelNodeTest { + // 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 \ No newline at end of file -- cgit v1.2.3