add tests
This commit is contained in:
parent
dd24b7e9e2
commit
22006e5299
5 changed files with 94 additions and 2 deletions
3
pom.xml
3
pom.xml
|
@ -6,8 +6,7 @@
|
|||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
|
22
src/main/java/eu/m724/netsim/PathVisualizer.java
Normal file
22
src/main/java/eu/m724/netsim/PathVisualizer.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
package eu.m724.netsim;
|
||||
|
||||
public class PathVisualizer {
|
||||
public static String path(Machine from, Machine to, int limit) {
|
||||
String out = from.id;
|
||||
|
||||
Machine current = from;
|
||||
int i = 0;
|
||||
while (!current.equals(to)) {
|
||||
RoutingInfo route = current.getRouteTo(to);
|
||||
current = route.from();
|
||||
out += " - " + current.id;
|
||||
|
||||
if (++i >= limit) {
|
||||
out += " - x";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
33
src/test/java/netsim/PeeringDirectTest.java
Normal file
33
src/test/java/netsim/PeeringDirectTest.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package netsim;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import eu.m724.netsim.Machine;
|
||||
import eu.m724.netsim.PathVisualizer;
|
||||
|
||||
public class PeeringDirectTest {
|
||||
@Test
|
||||
public void testComplexPeering() {
|
||||
// machine1 - machine2 - machine3 - machine4
|
||||
// \------------/
|
||||
// so machine1 should skip machine2
|
||||
|
||||
Machine machine1 = new Machine("machine1");
|
||||
Machine machine2 = new Machine("machine2");
|
||||
Machine machine3 = new Machine("machine3");
|
||||
Machine machine4 = new Machine("machine4");
|
||||
|
||||
machine1.peerWith(machine2);
|
||||
machine2.peerWith(machine3);
|
||||
machine3.peerWith(machine4);
|
||||
machine1.peerWith(machine3); // that's the bottom arrow
|
||||
|
||||
System.out.println("\nMachine 1:");
|
||||
System.out.println(machine1.getRouteTo(machine2).toString());
|
||||
System.out.println(machine1.getRouteTo(machine3).toString());
|
||||
System.out.println(machine1.getRouteTo(machine4).toString());
|
||||
System.out.println(PathVisualizer.path(machine1, machine4, 10));
|
||||
System.out.println("\nMachine 2:");
|
||||
System.out.println(machine2.getRouteTo(machine4).toString());
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package netsim;
|
|||
import org.junit.Test;
|
||||
|
||||
import eu.m724.netsim.Machine;
|
||||
import eu.m724.netsim.PathVisualizer;
|
||||
|
||||
public class PeeringTest {
|
||||
@Test
|
||||
|
@ -21,5 +22,7 @@ public class PeeringTest {
|
|||
System.out.println(machine1.getRouteTo(machine2).toString());
|
||||
System.out.println(machine2.getRouteTo(machine3).toString());
|
||||
System.out.println(machine1.getRouteTo(machine3).toString());
|
||||
|
||||
System.out.print(PathVisualizer.path(machine1, machine3, 10));
|
||||
}
|
||||
}
|
||||
|
|
35
src/test/java/netsim/PeeringTreeTest.java
Normal file
35
src/test/java/netsim/PeeringTreeTest.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package netsim;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import eu.m724.netsim.Machine;
|
||||
import eu.m724.netsim.PathVisualizer;
|
||||
|
||||
public class PeeringTreeTest {
|
||||
@Test
|
||||
public void testTreePeering() {
|
||||
// / machine4
|
||||
// / machine2 - machine5
|
||||
// machine1
|
||||
// \ machine3 - machine6
|
||||
// \ machine7
|
||||
// so machine1 should skip machine2
|
||||
|
||||
Machine machine1 = new Machine("machine1");
|
||||
Machine machine2 = new Machine("machine2");
|
||||
Machine machine3 = new Machine("machine3");
|
||||
Machine machine4 = new Machine("machine4");
|
||||
Machine machine5 = new Machine("machine5");
|
||||
Machine machine6 = new Machine("machine6");
|
||||
Machine machine7 = new Machine("machine7");
|
||||
|
||||
machine1.peerWith(machine2);
|
||||
machine1.peerWith(machine3);
|
||||
machine2.peerWith(machine4);
|
||||
machine2.peerWith(machine5);
|
||||
machine3.peerWith(machine6);
|
||||
machine3.peerWith(machine7);
|
||||
|
||||
System.out.println(PathVisualizer.path(machine4, machine7, 10));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue