From 5aedd25c5ffc4526ceabe4361196f408a281a2bf Mon Sep 17 00:00:00 2001 From: Berack96 Date: Fri, 7 Feb 2025 17:32:54 +0100 Subject: [PATCH] Refactor Net class by removing unused methods and updating child node retrieval logic in tests --- .../java/net/berack/upo/valpre/sim/Net.java | 26 ------------------- .../berack/upo/valpre/sim/TestSimulation.java | 16 +++++------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/berack/upo/valpre/sim/Net.java b/src/main/java/net/berack/upo/valpre/sim/Net.java index 6794526..4fd1915 100644 --- a/src/main/java/net/berack/upo/valpre/sim/Net.java +++ b/src/main/java/net/berack/upo/valpre/sim/Net.java @@ -146,20 +146,6 @@ public final class Net implements Iterable { return this.servers.get(index); } - /** - * Get one of the child nodes from the parent specified. - * If the node has no child then null is returned. - * - * @param parent the parent node - * @param rng the random number generator used for getting one of the child - * @return the resultig node - */ - public ServerNode getChildOf(ServerNode parent, Rng rng) { - var index = this.indices.get(parent); - index = this.getChildOf(index, rng); - return index < 0 ? null : this.servers.get(index); - } - /** * Get one of the child nodes from the parent specified. If the index is out of * bounds then an exception is thrown. If the node has no child then -1 is @@ -180,18 +166,6 @@ public final class Net implements Iterable { return -1; } - /** - * Get a list of all the children of the parent. - * In the list there is the node and the weight associated with. - * - * @param parent the parent node - * @return the list of children - */ - public List getChildren(ServerNode parent) { - var index = this.indices.get(parent); - return this.getChildren(index); - } - /** * Get a list of all the children of the parent. * In the list there is the node and the weight associated with. diff --git a/src/test/java/net/berack/upo/valpre/sim/TestSimulation.java b/src/test/java/net/berack/upo/valpre/sim/TestSimulation.java index 9e66bd1..a814618 100644 --- a/src/test/java/net/berack/upo/valpre/sim/TestSimulation.java +++ b/src/test/java/net/berack/upo/valpre/sim/TestSimulation.java @@ -2,6 +2,8 @@ package net.berack.upo.valpre.sim; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.HashSet; @@ -152,20 +154,16 @@ public class TestSimulation { var sample = net.getChildOf(0, rigged); assertEquals(1, sample); - var sample2 = net.getChildOf(node, rigged); - assertEquals(node1, sample2); + assertEquals(node1, net.getNode(sample)); } @Test public void nodeState() { - var net = new Net(); - var node = ServerNode.createQueue("First", 1, const0); - net.addNode(node); - var state = new ServerNodeState(0, net); + var state = new ServerNodeState(1, simpleNet); - assertEquals(0, state.index); - assertEquals(net, state.net); - assertEquals(node, state.node); + assertEquals(1, state.index); + assertEquals(simpleNet, state.net); + assertEquals(node1, state.node); assertEquals(0, state.numServerBusy); assertEquals(0, state.numServerUnavailable); assertEquals(0, state.queue.size());