Added old project initial commit
All checks were successful
Locusworks Team/lsproject/pipeline/head This commit looks good

This commit is contained in:
2021-10-18 19:26:42 -05:00
parent dd103f0e5d
commit 40e2af6a93
25 changed files with 2414 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
package object;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import net.locusworks.lsproject.object.Connection;
public class ConnectionTest {
private Connection testConnection;
@Before
public void setUpBeforeTest(){
testConnection = new Connection("1", "2", 4);
}
@Test
public void testGetCost() {
assertEquals(4, testConnection.getCost());
}
@Test
public void testSetCost() {
testConnection.setCost(21);
assertEquals(21, testConnection.getCost());
}
@Test
public void testGetFirstParticipantAddress() {
assertEquals("1", testConnection.getFirstParticipantAddress());
}
@Test
public void testGetSecondParticipantAddress() {
assertEquals("2", testConnection.getSecondParticipantAddress());
}
@Test
public void testSetParticipants() {
testConnection.setParticipants("100", "200");
assertEquals("100", testConnection.getFirstParticipantAddress());
assertEquals("200", testConnection.getSecondParticipantAddress());
}
}

View File

@@ -0,0 +1,90 @@
package object;
import java.awt.Point;
import java.util.ArrayList;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import net.locusworks.lsproject.driver.Program;
import net.locusworks.lsproject.object.Connection;
import net.locusworks.lsproject.object.DijkstraEngine;
import net.locusworks.lsproject.object.Network;
import net.locusworks.lsproject.object.Path;
import net.locusworks.lsproject.object.Router;
public class NetworkTest {
@BeforeClass
public static void setUpBeforeClass() {
Network.createInstance("Johnny");
}
@Before
public void setUpBeforeTest(){
Router router1 = new Router("192.168.1.0", new Point(0,1));
Router router2 = new Router("192.168.1.1", new Point(0,2));
Router router3 = new Router("192.168.1.2", new Point(0,3));
Router router4 = new Router("192.168.1.3", new Point(0,4));
Router router5 = new Router("192.168.1.4", new Point(0,5));
Connection connection1 = new Connection(router1.getIpAddress(),
router2.getIpAddress(), 1);
Connection connection2 = new Connection(router1.getIpAddress(),
router3.getIpAddress(), 3);
Connection connection3 = new Connection(router1.getIpAddress(),
router4.getIpAddress(), 6);
Connection connection4 = new Connection(router2.getIpAddress(),
router3.getIpAddress(), 5);
Connection connection5 = new Connection(router2.getIpAddress(),
router4.getIpAddress(), 2);
Connection connection6 = new Connection(router3.getIpAddress(),
router5.getIpAddress(), 2);
Connection connection7 = new Connection(router4.getIpAddress(),
router5.getIpAddress(), 1);
Router.addConnection(router1, router2, connection1);
Router.addConnection(router1, router3, connection2);
Router.addConnection(router1, router4, connection3);
Router.addConnection(router2, router3, connection4);
Router.addConnection(router2, router4, connection5);
Router.addConnection(router3, router5, connection6);
Router.addConnection(router4, router5, connection7);
Network.getInstance().addRouter(router1);
Network.getInstance().addRouter(router2);
Network.getInstance().addRouter(router3);
Network.getInstance().addRouter(router4);
Network.getInstance().addRouter(router5);
}
@Test
public void testFindShortestPath(){
DijkstraEngine engine = new DijkstraEngine();
System.out.println(Network.getInstance().getRouters().size());
Path path = engine.findShortestPath(Network.getInstance().getRouterByIp("192.168.1.0"),
Network.getInstance().getRouterByIp("192.168.1.4"));
int i = 1;
ArrayList<Router> routerz = new ArrayList<Router>();
while (path.hasNext()) {
Router r = path.getNext();
routerz.add(r);
System.out.println("Step " + i++ + ": " + r.getIpAddress());
}
System.out.println("Total cost: " + path.getTotalCost());
}
}

View File

@@ -0,0 +1,73 @@
package object;
import static org.junit.Assert.*;
import org.junit.Before;
import java.awt.Point;
import org.junit.Test;
import net.locusworks.lsproject.object.Connection;
import net.locusworks.lsproject.object.Path;
import net.locusworks.lsproject.object.Router;
public class PathTest {
private Path path;
private Path path2;
private final int expectedTotalCost = 9;
@Before
public void setUpBeforeClass(){
Router[] routers = new Router[10];
for(int i = 0; i < 10; i++){
Router router = new Router("192.168.1."+ i, new Point(0, 0));
routers[i] = router;
}
for(int i = 0; i < 9; i++){
Connection connection = new Connection("192.168.1."+i, "192.168.1."+(i+1),
1);
routers[i].addConnection(connection);
routers[i+1].addConnection(connection);
}
path = new Path(routers, expectedTotalCost);
path2 = new Path(routers, expectedTotalCost);
}
@Test
public void testPath() {
for(int i = 0; i < 8; i++){
if(path.hasNext() == false|| path2.hasNext() == false){
fail("Has Next failed at " + i + ". Should Never be False but was False");
}
assertEquals(path.getNext(), path2.getNext());
}
}
@Test
public void testGetTotalCost() {
assertEquals(expectedTotalCost, path.getTotalCost());
}
@Test
public void testGetNext(){
for(int i = 0; i < 9; i++){
if(path.getNext() == null){
fail("getNext reached null. Should never reach it");
}
}
}
@Test
public void testHasNext(){
for (int i = 0; i < 9; i++){
path.getNext();
if(path.hasNext() == false){
fail("hasNext reached the end of the elements");
}
}
}
}

View File

@@ -0,0 +1,78 @@
package object;
import static org.junit.Assert.*;
import java.awt.Point;
import org.junit.Before;
import org.junit.Test;
import net.locusworks.lsproject.object.Connection;
import net.locusworks.lsproject.object.Router;
public class RouterTest {
private Router router = null;
@Before
public void setUpBeforeTest(){
router = new Router("192.168.1.0", new Point(0, 0));
}
@Test
public void testGetIpAddress() {
if (! router.getIpAddress().equals("192.168.1.0")){
fail("ip Address does not match");
}
}
@Test
public void testSetIpAddress() {
router.setIpAddress("192.168.1.2");
if(! router.getIpAddress().equals("192.168.1.2")){
fail("Ip address did not set correctly");
}
}
@Test
public void testAddConnection() {
Connection testConnection = new Connection("192.168.1.3", "192.168.1.4", 3);
router.addConnection(testConnection);
String connection1 = router.getConnections().get(0).getFirstParticipantAddress();
String connection2 = router.getConnections().get(0).getSecondParticipantAddress();
assertEquals("192.168.1.3", connection1);
assertEquals("192.168.1.4", connection2);
}
@Test
public void testGetConnectionByParticipant() {
for(int i = 0; i < 10; i++){
router.addConnection(new Connection(Integer.toString(i), Integer.toString(i+1), 1));
}
for (int i = 0; i < 10; i++){
Connection testConnection = router.getConnectionByParticipant(
Integer.toString(i), Integer.toString(i+1));
assertEquals(Integer.toString(i), testConnection.getFirstParticipantAddress());
assertEquals(Integer.toString(i+1), testConnection.getSecondParticipantAddress());
}
Connection testCase = new Connection ("a", "A", 1);
router.clearConnections();
router.addConnection(testCase);
assertNull(router.getConnectionByParticipant("a", "a"));
}
}