|
@@ -1,20 +1,20 @@
|
|
package tests;
|
|
package tests;
|
|
|
|
|
|
-import static org.junit.Assert.assertTrue;
|
|
|
|
-
|
|
|
|
-import org.junit.Before;
|
|
|
|
-import org.junit.Test;
|
|
|
|
-
|
|
|
|
-import classes.CpsEdge;
|
|
|
|
import classes.AbstractCpsObject;
|
|
import classes.AbstractCpsObject;
|
|
|
|
+import classes.CpsEdge;
|
|
import classes.HolonObject;
|
|
import classes.HolonObject;
|
|
import classes.HolonSwitch;
|
|
import classes.HolonSwitch;
|
|
|
|
+
|
|
import ui.controller.CanvasController;
|
|
import ui.controller.CanvasController;
|
|
import ui.controller.CategoryController;
|
|
import ui.controller.CategoryController;
|
|
import ui.controller.MultiPurposeController;
|
|
import ui.controller.MultiPurposeController;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
import ui.model.idCounter;
|
|
import ui.model.idCounter;
|
|
|
|
|
|
|
|
+import org.junit.Test;
|
|
|
|
+import org.junit.Before;
|
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
|
+
|
|
public class praktikumHolonsTestCanvasController {
|
|
public class praktikumHolonsTestCanvasController {
|
|
|
|
|
|
protected praktikumHolonsAdapter adapter;
|
|
protected praktikumHolonsAdapter adapter;
|
|
@@ -23,6 +23,9 @@ public class praktikumHolonsTestCanvasController {
|
|
protected CategoryController cg;
|
|
protected CategoryController cg;
|
|
protected CanvasController controller;
|
|
protected CanvasController controller;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Setup for the tests.
|
|
|
|
+ */
|
|
@Before
|
|
@Before
|
|
public void setUp() {
|
|
public void setUp() {
|
|
adapter = new praktikumHolonsAdapter();
|
|
adapter = new praktikumHolonsAdapter();
|
|
@@ -33,9 +36,12 @@ public class praktikumHolonsTestCanvasController {
|
|
idCounter.setCounter(1);
|
|
idCounter.setCounter(1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Tests adding objects.
|
|
|
|
+ */
|
|
@Test
|
|
@Test
|
|
public void testAddingObjects() {
|
|
public void testAddingObjects() {
|
|
- //just adding a few things
|
|
|
|
|
|
+ // just adding a few things
|
|
assertTrue("Number of Objects does not Match", model.getObjectsOnCanvas().size() == 0);
|
|
assertTrue("Number of Objects does not Match", model.getObjectsOnCanvas().size() == 0);
|
|
controller.addNewObject(new HolonObject(mp.searchCatObj(mp.searchCat("Energy"), "Power Plant")));
|
|
controller.addNewObject(new HolonObject(mp.searchCatObj(mp.searchCat("Energy"), "Power Plant")));
|
|
assertTrue("ID of the Object does not Match", mp.searchByID(1).getName().equals("Power Plant"));
|
|
assertTrue("ID of the Object does not Match", mp.searchByID(1).getName().equals("Power Plant"));
|
|
@@ -68,7 +74,9 @@ public class praktikumHolonsTestCanvasController {
|
|
controller.addNewObject(new HolonSwitch(mp.searchCatObj(mp.searchCat("Component"), "Switch")));
|
|
controller.addNewObject(new HolonSwitch(mp.searchCatObj(mp.searchCat("Component"), "Switch")));
|
|
assertTrue("Number of Objects does not Match", model.getObjectsOnCanvas().size() == 10);
|
|
assertTrue("Number of Objects does not Match", model.getObjectsOnCanvas().size() == 10);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Tests deleting Objects.
|
|
|
|
+ */
|
|
@Test(expected = NullPointerException.class)
|
|
@Test(expected = NullPointerException.class)
|
|
public void testDeletingObject() {
|
|
public void testDeletingObject() {
|
|
// Adding Objects on Canvas.. without Coordinates
|
|
// Adding Objects on Canvas.. without Coordinates
|
|
@@ -97,37 +105,41 @@ public class praktikumHolonsTestCanvasController {
|
|
controller.deleteObjectOnCanvas(mp.searchByID(4));
|
|
controller.deleteObjectOnCanvas(mp.searchByID(4));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Tests adding and deleting Edges.
|
|
|
|
+ */
|
|
@Test
|
|
@Test
|
|
public void testAddingAndDeletingEdges() {
|
|
public void testAddingAndDeletingEdges() {
|
|
- HolonObject A = new HolonObject("A");
|
|
|
|
- controller.addNewObject(new HolonObject(A));
|
|
|
|
|
|
+ HolonObject a = new HolonObject("A");
|
|
|
|
+ controller.addNewObject(new HolonObject(a));
|
|
int n = 0;
|
|
int n = 0;
|
|
|
|
|
|
- //creates vertices A - Z
|
|
|
|
|
|
+ // creates vertices A - Z
|
|
for (int i = 2; i < 27; i++) {
|
|
for (int i = 2; i < 27; i++) {
|
|
- //adds Object on canvas
|
|
|
|
|
|
+ // adds Object on canvas
|
|
HolonObject temp = new HolonObject(adapter.generate(i));
|
|
HolonObject temp = new HolonObject(adapter.generate(i));
|
|
controller.addNewObject(new HolonObject(temp));
|
|
controller.addNewObject(new HolonObject(temp));
|
|
- //connect current vertice with all other vertices
|
|
|
|
|
|
+ // connect current vertice with all other vertices
|
|
for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
|
|
if (!cps.equals(mp.searchByID(i)))
|
|
if (!cps.equals(mp.searchByID(i)))
|
|
controller.addEdgeOnCanvas(new CpsEdge(mp.searchByID(i), cps));
|
|
controller.addEdgeOnCanvas(new CpsEdge(mp.searchByID(i), cps));
|
|
}
|
|
}
|
|
|
|
|
|
- //test how many connections current vertice got
|
|
|
|
|
|
+ // test how many connections current vertice got
|
|
assertTrue("Number of Connections does not Match", mp.searchByID(i).getConnectedTo().size() == i - 1);
|
|
assertTrue("Number of Connections does not Match", mp.searchByID(i).getConnectedTo().size() == i - 1);
|
|
// some mathematical shit we got here. actually just means if its a
|
|
// some mathematical shit we got here. actually just means if its a
|
|
// complete graph -> all vertices connected all other vertices
|
|
// complete graph -> all vertices connected all other vertices
|
|
n = model.getObjectsOnCanvas().size();
|
|
n = model.getObjectsOnCanvas().size();
|
|
assertTrue("Number of Edges does not Match", model.getEdgesOnCanvas().size() == (n * (n - 1)) / 2);
|
|
assertTrue("Number of Edges does not Match", model.getEdgesOnCanvas().size() == (n * (n - 1)) / 2);
|
|
}
|
|
}
|
|
- //same as above
|
|
|
|
|
|
+ // same as above
|
|
n = model.getObjectsOnCanvas().size();
|
|
n = model.getObjectsOnCanvas().size();
|
|
assertTrue("Number of Edges does not Match", model.getEdgesOnCanvas().size() == (n * (n - 1)) / 2);
|
|
assertTrue("Number of Edges does not Match", model.getEdgesOnCanvas().size() == (n * (n - 1)) / 2);
|
|
-
|
|
|
|
- //here starts the deleting
|
|
|
|
|
|
+
|
|
|
|
+ // here starts the deleting
|
|
controller.removeEdgesOnCanvas(mp.searchEdge(13, 14));
|
|
controller.removeEdgesOnCanvas(mp.searchEdge(13, 14));
|
|
- assertTrue("Number of Connection of Vertice M does not Match", mp.searchByID(13).getConnections().size() == model.getObjectsOnCanvas().size() - 2);
|
|
|
|
|
|
+ assertTrue("Number of Connection of Vertice M does not Match",
|
|
|
|
+ mp.searchByID(13).getConnections().size() == model.getObjectsOnCanvas().size() - 2);
|
|
assertTrue("Edge-M-N was not deleted", mp.searchEdge(13, 14) == null);
|
|
assertTrue("Edge-M-N was not deleted", mp.searchEdge(13, 14) == null);
|
|
|
|
|
|
controller.deleteObjectOnCanvas(mp.searchByID(13));
|
|
controller.deleteObjectOnCanvas(mp.searchByID(13));
|