Refactor Net class by removing unused methods and updating child node retrieval logic in tests
This commit is contained in:
@@ -146,20 +146,6 @@ public final class Net implements Iterable<ServerNode> {
|
|||||||
return this.servers.get(index);
|
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
|
* 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
|
* 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<ServerNode> {
|
|||||||
return -1;
|
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<NetChild> getChildren(ServerNode parent) {
|
|
||||||
var index = this.indices.get(parent);
|
|
||||||
return this.getChildren(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of all the children of the parent.
|
* Get a list of all the children of the parent.
|
||||||
* In the list there is the node and the weight associated with.
|
* In the list there is the node and the weight associated with.
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package net.berack.upo.valpre.sim;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
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 static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -152,20 +154,16 @@ public class TestSimulation {
|
|||||||
|
|
||||||
var sample = net.getChildOf(0, rigged);
|
var sample = net.getChildOf(0, rigged);
|
||||||
assertEquals(1, sample);
|
assertEquals(1, sample);
|
||||||
var sample2 = net.getChildOf(node, rigged);
|
assertEquals(node1, net.getNode(sample));
|
||||||
assertEquals(node1, sample2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nodeState() {
|
public void nodeState() {
|
||||||
var net = new Net();
|
var state = new ServerNodeState(1, simpleNet);
|
||||||
var node = ServerNode.createQueue("First", 1, const0);
|
|
||||||
net.addNode(node);
|
|
||||||
var state = new ServerNodeState(0, net);
|
|
||||||
|
|
||||||
assertEquals(0, state.index);
|
assertEquals(1, state.index);
|
||||||
assertEquals(net, state.net);
|
assertEquals(simpleNet, state.net);
|
||||||
assertEquals(node, state.node);
|
assertEquals(node1, state.node);
|
||||||
assertEquals(0, state.numServerBusy);
|
assertEquals(0, state.numServerBusy);
|
||||||
assertEquals(0, state.numServerUnavailable);
|
assertEquals(0, state.numServerUnavailable);
|
||||||
assertEquals(0, state.queue.size());
|
assertEquals(0, state.queue.size());
|
||||||
|
|||||||
Reference in New Issue
Block a user