add tests

This commit is contained in:
Minecon724 2024-07-20 13:03:42 +02:00
parent dd24b7e9e2
commit 22006e5299
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
5 changed files with 94 additions and 2 deletions

View file

@ -6,8 +6,7 @@
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<properties> <properties>
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
</properties> </properties>
<dependencies> <dependencies>

View 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;
}
}

View 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());
}
}

View file

@ -3,6 +3,7 @@ package netsim;
import org.junit.Test; import org.junit.Test;
import eu.m724.netsim.Machine; import eu.m724.netsim.Machine;
import eu.m724.netsim.PathVisualizer;
public class PeeringTest { public class PeeringTest {
@Test @Test
@ -21,5 +22,7 @@ public class PeeringTest {
System.out.println(machine1.getRouteTo(machine2).toString()); System.out.println(machine1.getRouteTo(machine2).toString());
System.out.println(machine2.getRouteTo(machine3).toString()); System.out.println(machine2.getRouteTo(machine3).toString());
System.out.println(machine1.getRouteTo(machine3).toString()); System.out.println(machine1.getRouteTo(machine3).toString());
System.out.print(PathVisualizer.path(machine1, machine3, 10));
} }
} }

View 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));
}
}