diff options
| author | @syxhe <t.me/syxhe> | 2025-10-02 19:05:32 -0500 |
|---|---|---|
| committer | @syxhe <t.me/syxhe> | 2025-10-02 19:05:32 -0500 |
| commit | 3de3a9d4ca7b188abb0411c9e0a484ed2561a4b7 (patch) | |
| tree | a1e98915a810354e51ef2a82e616d586702b522a | |
| parent | 82c6f12de286db3c89758f201f619a63accf17f4 (diff) | |
Wrangle with test cases
| -rw-r--r-- | .idea/inspectionProfiles/Project_Default.xml | 8 | ||||
| -rw-r--r-- | .idea/vcs.xml | 1 | ||||
| -rw-r--r-- | src/main/java/ChannelNode.java | 19 | ||||
| -rw-r--r-- | src/main/java/IChannelNode.java | 10 | ||||
| -rw-r--r-- | src/test/java/ChannelNodeTest.java | 76 |
5 files changed, 93 insertions, 21 deletions
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..969ca91 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | <component name="InspectionProjectProfileManager"> | ||
| 2 | <profile version="1.0"> | ||
| 3 | <option name="myName" value="Project Default" /> | ||
| 4 | <inspection_tool class="PointlessBitwiseExpression" enabled="false" level="WARNING" enabled_by_default="false"> | ||
| 5 | <option name="m_ignoreExpressionsContainingConstants" value="true" /> | ||
| 6 | </inspection_tool> | ||
| 7 | </profile> | ||
| 8 | </component> \ No newline at end of file | ||
diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..7dc97e3 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml | |||
| @@ -2,5 +2,6 @@ | |||
| 2 | <project version="4"> | 2 | <project version="4"> |
| 3 | <component name="VcsDirectoryMappings"> | 3 | <component name="VcsDirectoryMappings"> |
| 4 | <mapping directory="$PROJECT_DIR$" vcs="Git" /> | 4 | <mapping directory="$PROJECT_DIR$" vcs="Git" /> |
| 5 | <mapping directory="$PROJECT_DIR$/td" vcs="Git" /> | ||
| 5 | </component> | 6 | </component> |
| 6 | </project> \ No newline at end of file | 7 | </project> \ No newline at end of file |
diff --git a/src/main/java/ChannelNode.java b/src/main/java/ChannelNode.java index 20a7ac0..6c2e9a3 100644 --- a/src/main/java/ChannelNode.java +++ b/src/main/java/ChannelNode.java | |||
| @@ -43,8 +43,8 @@ public class ChannelNode implements IChannelNode { | |||
| 43 | if(dir == null) throw new IllegalArgumentException("dir is null"); | 43 | if(dir == null) throw new IllegalArgumentException("dir is null"); |
| 44 | 44 | ||
| 45 | Direction.overVals(Map.ofEntries( | 45 | Direction.overVals(Map.ofEntries( |
| 46 | entry(Direction.INCOMING, () -> incoming.put(node, incoming.get(node) + 1)), | 46 | entry(Direction.INCOMING, () -> incoming.put(node, ((incoming.get(node) != null) ? incoming.get(node) : 0) + 1)), |
| 47 | entry(Direction.OUTGOING, () -> outgoing.put(node, outgoing.get(node) + 1)) | 47 | entry(Direction.OUTGOING, () -> outgoing.put(node, ((outgoing.get(node) != null) ? outgoing.get(node) : 0) + 1)) |
| 48 | ), dir); | 48 | ), dir); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| @@ -56,8 +56,8 @@ public class ChannelNode implements IChannelNode { | |||
| 56 | 56 | ||
| 57 | for(IChannelNode node: nodes) { | 57 | for(IChannelNode node: nodes) { |
| 58 | Direction.overVals(Map.ofEntries( | 58 | Direction.overVals(Map.ofEntries( |
| 59 | entry(Direction.INCOMING, () -> incoming.put(node, incoming.get(node) + 1)), | 59 | entry(Direction.INCOMING, () -> incoming.put(node,((incoming.get(node) != null) ? incoming.get(node) : 0) + 1)), |
| 60 | entry(Direction.OUTGOING, () -> outgoing.put(node, outgoing.get(node) + 1)) | 60 | entry(Direction.OUTGOING, () -> outgoing.put(node,((outgoing.get(node) != null) ? outgoing.get(node) : 0) + 1)) |
| 61 | ), dir); | 61 | ), dir); |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| @@ -89,13 +89,10 @@ public class ChannelNode implements IChannelNode { | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | @Override | 91 | @Override |
| 92 | public void clearConnections(Direction dir) throws IllegalArgumentException { | 92 | public void clearConnections() throws IllegalArgumentException { |
| 93 | if(dir == null) throw new IllegalArgumentException("dir is null"); | 93 | // I have no idea why this is throwing an unsupported operation exception |
| 94 | 94 | incoming.clear(); | |
| 95 | Direction.overVals(Map.ofEntries( | 95 | outgoing.clear(); |
| 96 | entry(Direction.INCOMING, () -> incoming.clear()), | ||
| 97 | entry(Direction.OUTGOING, () -> outgoing.clear()) | ||
| 98 | ), dir); | ||
| 99 | } | 96 | } |
| 100 | 97 | ||
| 101 | @Override | 98 | @Override |
diff --git a/src/main/java/IChannelNode.java b/src/main/java/IChannelNode.java index a6446f1..cc1d3e8 100644 --- a/src/main/java/IChannelNode.java +++ b/src/main/java/IChannelNode.java | |||
| @@ -3,9 +3,9 @@ import java.util.Map; | |||
| 3 | 3 | ||
| 4 | public interface IChannelNode extends Comparable<IChannelNode> { | 4 | public interface IChannelNode extends Comparable<IChannelNode> { |
| 5 | enum Direction { | 5 | enum Direction { |
| 6 | INCOMING(1), // Users incoming from outside channel (aka: other channel forwarded this channel's post) | 6 | INCOMING(1 << 0), // Users incoming from outside channel (aka: other channel forwarded this channel's post) |
| 7 | OUTGOING(2), // Users outgoing from this channel (aka: this channel forwarded someone else's post) | 7 | OUTGOING(1 << 1), // Users outgoing from this channel (aka: this channel forwarded someone else's post) |
| 8 | BOTH(3); // Modify both incoming and outgoing counts at once | 8 | BOTH(INCOMING.val | OUTGOING.val); // Modify both incoming and outgoing counts at once |
| 9 | 9 | ||
| 10 | private final int val; | 10 | private final int val; |
| 11 | Direction(int val) {this.val = val;} | 11 | Direction(int val) {this.val = val;} |
| @@ -22,7 +22,7 @@ public interface IChannelNode extends Comparable<IChannelNode> { | |||
| 22 | 22 | ||
| 23 | // For each direction in the map, check that the given direction is gte, and if so run the callback | 23 | // For each direction in the map, check that the given direction is gte, and if so run the callback |
| 24 | for(Direction cdir: cmap.keySet()) | 24 | for(Direction cdir: cmap.keySet()) |
| 25 | if(dir.getVal() >= cdir.getVal()) | 25 | if((dir.getVal() & cdir.getVal()) > 0) |
| 26 | cmap.get(cdir).cb(); | 26 | cmap.get(cdir).cb(); |
| 27 | } | 27 | } |
| 28 | // This is hilariously overengineered because java fucking sucks my entire cock and balls | 28 | // This is hilariously overengineered because java fucking sucks my entire cock and balls |
| @@ -35,7 +35,7 @@ public interface IChannelNode extends Comparable<IChannelNode> { | |||
| 35 | void addConnections(Iterable<IChannelNode> nodes, Direction dir); | 35 | void addConnections(Iterable<IChannelNode> nodes, Direction dir); |
| 36 | void removeConnection(IChannelNode node, Direction dir); | 36 | void removeConnection(IChannelNode node, Direction dir); |
| 37 | void removeConnections(Iterable<IChannelNode> nodes, Direction dir); | 37 | void removeConnections(Iterable<IChannelNode> nodes, Direction dir); |
| 38 | void clearConnections(Direction dir); | 38 | void clearConnections(); |
| 39 | 39 | ||
| 40 | boolean connectionExists(IChannelNode node, Direction dir); | 40 | boolean connectionExists(IChannelNode node, Direction dir); |
| 41 | int getNumConnections(Direction dir); | 41 | int getNumConnections(Direction dir); |
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 |
