Teh-Hai Julian Zheng 8 years ago
parent
commit
74d38237ae

+ 0 - 10
src/classes/AbstractCpsObject.java

@@ -249,16 +249,6 @@ public abstract class AbstractCpsObject {
 		this.borderColor = c;
 	}
 
-	/**
-	 * Set the Color of the edges.
-	 * 
-	 * @param color
-	 *            the Color to set
-	 */
-	public void setConnections(Color color) {
-		this.borderColor = color;
-	}
-
 	/**
 	 * For internal purpose (energy flow).
 	 * 

+ 0 - 21
src/classes/HolonElement.java

@@ -23,8 +23,6 @@ public class HolonElement {
 	private boolean active;
 	/* Total Energy */
 	private float totalEnergy;
-	/* Path of the image for the Obj. */
-	private String image;
 	/* +: for Consumers and -: Producers */
 	private char sign;
 	/* Place where the Object is Stored */
@@ -189,25 +187,6 @@ public class HolonElement {
 		this.active = active;
 	}
 
-	/**
-	 * Get Image path.
-	 * 
-	 * @return the image
-	 */
-	public String getImage() {
-		return image;
-	}
-
-	/**
-	 * Set Image path.
-	 * 
-	 * @param image
-	 *            the image to set
-	 */
-	public void setImage(String image) {
-		this.image = image;
-	}
-
 	/**
 	 * Multiply the amount of gadgets, given by the user, and the
 	 * consumption/production. If the switch isWorking is turned off for on

+ 0 - 53
src/tests/PraktikumHolonsTestAutoSaveControlle.java

@@ -1,53 +0,0 @@
-package tests;
-
-import java.io.File;
-
-import org.junit.Before;
-
-import ui.controller.CanvasController;
-import ui.controller.CategoryController;
-import ui.controller.LoadController;
-import ui.controller.MultiPurposeController;
-import ui.controller.ObjectController;
-import ui.controller.StoreController;
-import ui.model.Model;
-import ui.model.IdCounter;
-
-public class PraktikumHolonsTestAutoSaveControlle {
-	protected PraktikumHolonsAdapter adapter;
-	protected Model model;
-	protected MultiPurposeController mp;
-	protected CategoryController cg;
-	protected CanvasController cvs;
-	protected ObjectController obj;
-	protected StoreController storeController;
-	protected LoadController loadController;
-	protected IdCounter id;
-	protected String path = System.getProperty("user.home") + "/HolonGUI/Test/";
-
-	/**
-	 * Setup for the test.
-	 */
-	@Before
-	public void setUp() {
-		adapter = new PraktikumHolonsAdapter();
-		model = new Model();
-		mp = new MultiPurposeController(model);
-		cg = new CategoryController(model, mp);
-		cvs = new CanvasController(model, mp);
-		obj = new ObjectController(model, mp);
-		storeController = new StoreController(model);
-		loadController = new LoadController(model, cg, cvs, obj, mp);
-		// cg.initCategories();
-		// obj.initHolonElements();
-		File file = new File(path);
-		file.mkdirs();
-	}
-
-	/**
-	 *  kommentar hier hin.
-	 */
-	public void autoSaveMinimal() {
-
-	}
-}

+ 55 - 0
src/tests/PraktikumHolonsTestAutoSaveController.java

@@ -0,0 +1,55 @@
+package tests;
+
+import java.io.File;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import ui.controller.AutoSaveController;
+import ui.controller.CanvasController;
+import ui.controller.CategoryController;
+import ui.controller.LoadController;
+import ui.controller.MultiPurposeController;
+import ui.controller.ObjectController;
+import ui.controller.StoreController;
+import ui.model.Model;
+import ui.model.IdCounter;
+
+public class PraktikumHolonsTestAutoSaveController {
+	protected Model model;
+	protected AutoSaveController controller;
+
+
+	/**
+	 * Setup for the test.
+	 */
+	@Before
+	public void setUp() {
+		model = new Model();
+		controller = new AutoSaveController(model);
+	}
+
+	/**
+	 *  kommentar hier hin.
+	 */
+	@Test
+	public void testAutoSave() {
+		int temp = controller.getAutoSaveNr();
+		assertTrue("AutoSave Number not forrect", temp == -1);
+		controller.increaseAutoSaveNr();
+		assertTrue("AutoSave Number not forrect", controller.getAutoSaveNr() == 0);
+		
+		for (int i = 0; i < 20; i++) {
+			controller.increaseAutoSaveNr();
+		}
+		
+		assertTrue("Is Allowed not set", controller.allowed());
+		
+		for (int i = 0; i < 20; i++) {
+			controller.decreaseAutoSaveNr();;
+		}
+		
+		
+	}
+}

+ 1 - 1
src/tests/PraktikumHolonsTestCanvasController.java

@@ -127,7 +127,7 @@ public class PraktikumHolonsTestCanvasController {
 
 			// test how many connections current vertice got
 			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
+			// actually just means if its a
 			// complete graph -> all vertices connected all other vertices
 			n = model.getObjectsOnCanvas().size();
 			assertTrue("Number of Edges does not Match", model.getEdgesOnCanvas().size() == (n * (n - 1)) / 2);

+ 104 - 5
src/tests/PraktikumHolonsTestClasses.java

@@ -78,7 +78,6 @@ public class PraktikumHolonsTestClasses {
 		test1.setElements(new ArrayList<>());
 		assertTrue("Not Empty", !test1.checkIfPartiallySupplied(1));
 		test3.addElements(new HolonElement("Element2", 1, -10));
-
 		assertTrue("Not Partially Supplied", test3.checkIfPartiallySupplied(1));
 		test3.addElements(new HolonElement("Element2", 2, -10));
 		assertTrue("Not Partially Supplied", test3.checkIfPartiallySupplied(1));
@@ -87,13 +86,23 @@ public class PraktikumHolonsTestClasses {
 		Color color = test3.getColor();
 		test3.setColor(new Color(0, 255, 255));
 		assertTrue(color.getBlue() != test3.getColor().getBlue());
+
+		test3.addElements(new HolonElement("Element3", 3, 50));
+		test3.setState();
+		assertTrue("Should be state 3", test3.getState() == 3);
+		test1.setState();
+		assertTrue("Should be state 0", test1.getState() == 0);
+		test2.setState();
+		
+		test2.setBorderColor(color);
+		assertTrue("Color not Same", color == test2.getBorderColor());
 	}
 
 	@Test
 	public void testHolonSwitch() {
 		HolonSwitch test1 = new HolonSwitch("Test1");
 		HolonSwitch test2 = new HolonSwitch(test1);
-		
+
 		assertTrue("Manuel Mode is on", !test2.getManualMode());
 		test2.switchState();
 		assertTrue(test2.getState());
@@ -113,7 +122,7 @@ public class PraktikumHolonsTestClasses {
 		test2.setGraphPoints(test1.getGraphPoints());
 		assertTrue(test1.getGraphPoints() == test2.getGraphPoints());
 	}
-	
+
 	@Test
 	public void testCpsEdge() {
 		CpsNode node1 = new CpsNode("Node1");
@@ -121,11 +130,101 @@ public class PraktikumHolonsTestClasses {
 		CpsNode node3 = new CpsNode("Node3");
 		CpsEdge edge1 = new CpsEdge(node1, node2, 100);
 		CpsEdge edge2 = new CpsEdge(node2, node3);
-		
+
+		assertTrue("Flow not 0", edge1.getFlow() == 0);
+		edge1.setFlow(50);
+		assertTrue("Capacity not right", edge1.getCapacity() == 100);
+		edge2.setFlow(50);
+		edge1.setCapacity(200);
+		assertTrue("Flow was not changed", edge1.getFlow() == 50);
+		assertTrue("Capacity not right", edge1.getCapacity() == 200);
+		assertTrue("line broken", edge2.getState());
+		edge2.calculateState(false);
+		assertTrue("line broken", edge2.getState());
+		edge2.setFlow(200);
+		edge2.calculateState(false);
+		assertTrue("line not broken", !edge2.getState());
+		edge1.setCapacity(-1);
+		edge1.calculateState(false);
+		edge1.setCapacity(500);
+		edge1.calculateState(true);
+		node1 = (CpsNode) edge1.getB();
+		node2 = (CpsNode) edge2.getA();
+		assertTrue("Not Same", node1 == node2);
+		assertTrue("State not right", edge1.getState());
+		edge1.setState(false);
+		assertTrue("State not right", !edge1.getState());
+		edge2.setTags(new ArrayList<>());
+		edge1.setTags(new ArrayList<>());
+		assertTrue("Tags not Empty", edge2.getTags().isEmpty());
+		edge2.addTag(1);
+		assertTrue("Tags not Empty", edge1.getTags().isEmpty());
+		assertTrue("Tags Empty", !edge2.getTags().isEmpty());
+		edge1.setTags(edge2.getTags());
+		assertTrue("Tags Empty", !edge1.getTags().isEmpty());
 	}
-	
+
 	@Test
 	public void testHolonElement() {
+		HolonElement ele1 = new HolonElement("TV", 2, -20);
+		HolonElement ele2 = new HolonElement("Fridge", 1, -50);
+		HolonElement ele3 = new HolonElement(ele2);
+
+		assertTrue("Array not empty", ele1.getEnergyAt()[0] == -20);
+		assertTrue("Array not empty", ele1.getEnergyAt()[2] == -20);
+		ele1.setEnergyAt(2, -10);
+		assertTrue("Array not empty", ele1.getEnergyAt()[2] == -10);
+		assertTrue("Name not correct", ele1.getEleName().equals("TV"));
+		ele1.setEleName(ele2.getEleName());
+		assertTrue("Name not correct", ele1.getEleName().equals("Fridge"));
+		assertTrue("Amount not correct", ele2.getAmount() == 1);
+		ele2.setAmount(5);
+		assertTrue("Amount not correct", ele2.getAmount() == 5);
+		assertTrue("Total Energy not Correct", ele2.getTotalEnergy() == ele2.getAmount() * ele2.getEnergy());
+		assertTrue("Sign not correct", ele2.getSign() == '-');
+		ele3.setSav("CVS");
+		assertTrue("SAV not correct", ele3.getSav().equals("CVS"));
+	}
+
+	@Test
+	public void testPosition() {
+		Position pos1 = new Position(100, 200);
+		Position pos2 = new Position();
+
+		assertTrue("Wront coordinates", pos1.x == 100 && pos1.y == 200);
+		assertTrue("Are the Same", pos1.x != pos2.x);
+		assertTrue("not (-1,-1)", pos2.x == -1 && pos2.y == -1);
+	}
+
+	@Test
+	public void testSubNet() {
+		PraktikumHolonsAdapter adapter = new PraktikumHolonsAdapter();
+
+		ArrayList<HolonObject> obj = new ArrayList<>();
+		ArrayList<CpsEdge> edge = new ArrayList<>();
+		ArrayList<HolonSwitch> sw = new ArrayList<>();
+
+		assertTrue("Not Empty", obj.isEmpty());
+		assertTrue("Not Empty", sw.isEmpty());
+		assertTrue("Not Empty", edge.isEmpty());
+
+		for (int i = 1; i < 10; i++) {
+			HolonObject o = new HolonObject(adapter.generate(i));
+			HolonSwitch s = new HolonSwitch(adapter.generate(i));
+			o = new HolonObject(o);
+			s = new HolonSwitch(s);
+			obj.add(o);
+			sw.add(s);
+			edge.add(new CpsEdge(o, s));
+		}
+		
+		SubNet sub = new SubNet(obj, edge, sw);
+
+		assertTrue("Empty", !sub.getObjects().isEmpty() && sub.getObjects().size() == 9);
+		assertTrue("Empty", !sub.getSwitches().isEmpty() && sub.getSwitches().size() == 9);
+		assertTrue("Empty", !sub.getEdges().isEmpty() && sub.getEdges().size() == 9);
+		assertTrue("Wrong Obj", sub.getObjects().get(5).getObjName().equals("F"));
+		
 		
 	}
 

+ 33 - 0
src/tests/PraktikumHolonsTestConsoleController.java

@@ -0,0 +1,33 @@
+package tests;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import ui.controller.ConsoleController;
+import ui.model.Model;
+import ui.view.Console;
+
+import static org.junit.Assert.*;
+
+import java.awt.Color;
+
+public class PraktikumHolonsTestConsoleController {
+
+	protected Model model;
+	protected ConsoleController controller;
+
+	@Before
+	public void setUp() {
+		model = new Model();
+		model.setConsole(new Console());
+		controller = new ConsoleController(model);
+	}
+
+	@Test
+	public void testConsoleController() {
+		controller.addTextToConsole("Hello World");
+		controller.addTextToConsole("Hello World2!", new Color(255, 255, 255), 11, false, true, false);
+		controller.clearConsole();
+
+	}
+}

+ 25 - 22
src/tests/PraktikumHolonsTestLoadAndStoreController.java

@@ -169,7 +169,6 @@ public class PraktikumHolonsTestLoadAndStoreController {
 			}
 		}
 
-
 		try {
 			File sav = new File(path + "TestSavAdvanced.json");
 			storeController.writeSaveFile(sav.getAbsolutePath());
@@ -188,27 +187,28 @@ public class PraktikumHolonsTestLoadAndStoreController {
 	@Test
 	public void testLoadMinimal() {
 		try {
-			//Category Tests
+			// Category Tests
 			Category building = mp.searchCat("Building");
 			assertTrue("Number of Categories does not match", model.getCategories().size() == 3);
 			assertTrue("TestFile was not found", new File(path + "TestCategoryMinimal.json").exists());
 			loadController.readJSON(path + "TestCategoryMinimal.json");
 			assertTrue("Number of Categories does not match", model.getCategories().size() == 3);
-			//Tests if its same instance and if Name is the same
+			// Tests if its same instance and if Name is the same
 			assertTrue("Same instance of Category:Building", building != mp.searchCat("Building")
 					&& building.getName().equals(mp.searchCat("Building").getName()));
-			
-			//Canvas Tests.. basically nothing happens because nothing is on the Canvas
+
+			// Canvas Tests.. basically nothing happens because nothing is on
+			// the Canvas
 			assertTrue("Number of Objects on Canvas does not match", model.getObjectsOnCanvas().size() == 0);
 			assertTrue("TestFile was not found", new File(path + "TestCanvasMinimal.json").exists());
 			loadController.readJSON(path + "TestCanvasMinimal.json");
 			assertTrue("Number of Objects on Canvas does not match", model.getObjectsOnCanvas().size() == 0);
-			
-			//Save File tests basically both Test from Above Combined
+
+			// Save File tests basically both Test from Above Combined
 			building = mp.searchCat("Building");
 			assertTrue("Number of Objects in Energy does not Match", mp.searchCat("Energy").getObjects().size() == 1);
 			assertTrue("TestFile was not found", new File(path + "TestSavMinimal.json").exists());
-			loadController.readJSON( path + "TestSavMinimal.json");
+			loadController.readJSON(path + "TestSavMinimal.json");
 			assertTrue("Number of Objects in Energy does not Match", mp.searchCat("Energy").getObjects().size() == 1);
 			assertTrue("Number of Objects on Canvas does not match", model.getObjectsOnCanvas().size() == 0);
 			assertTrue("Same instance of Category:Building", building != mp.searchCat("Building")
@@ -219,7 +219,7 @@ public class PraktikumHolonsTestLoadAndStoreController {
 			e.printStackTrace();
 		}
 	}
-	
+
 	/**
 	 * basic tests for loading a save file.
 	 */
@@ -231,8 +231,7 @@ public class PraktikumHolonsTestLoadAndStoreController {
 		assertTrue("Non-Existant Category Exists", mp.searchCat("I") == null);
 		assertTrue("Non-Existant Category Exists", mp.searchCat("A") == null);
 		assertTrue("Non-Existant Category Exists", mp.searchCat("N") == null);
-		
-		
+
 		try {
 			assertTrue("Objects on Canvas is not 0", model.getObjectsOnCanvas().size() == 0);
 			assertTrue("Canvas File was not found", new File(path + "TestCanvasBasic.json").exists());
@@ -243,7 +242,7 @@ public class PraktikumHolonsTestLoadAndStoreController {
 				assertTrue("Not instance of HolonObject", obj instanceof HolonObject || obj instanceof HolonSwitch);
 
 			}
-			
+
 			assertTrue("NUmber of Categories not match", model.getCategories().size() == 3);
 			assertTrue("Canvas File was not found", new File(path + "TestSavBasic.json").exists());
 			loadController.readJSON(path + "TestSavBasic.json");
@@ -260,37 +259,40 @@ public class PraktikumHolonsTestLoadAndStoreController {
 			assertTrue("Existant Object dont Exists", mp.searchCatObj(mp.searchCat("Z"), "D") != null);
 			assertTrue("Existant Object dont Exists", mp.searchCatObj(mp.searchCat("Z"), "E") != null);
 			assertTrue("Existant Object dont Exists", mp.searchCatObj(mp.searchCat("Z"), "F") != null);
-			
+
 		} catch (IOException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
 	}
-	
+
 	/**
 	 * advanced tests for loading a save file.
 	 */
 	@Test
 	public void testLoadAdvanced() {
-		
+
 		try {
 			assertTrue("Objects on Canvas is not 0", model.getObjectsOnCanvas().size() == 0);
 			assertTrue("Save File was not found", new File(path + "TestSavAdvanced.json").exists());
 			loadController.readJSON(path + "TestSavAdvanced.json");
 			assertTrue("Objects on Canvas is not 100", model.getObjectsOnCanvas().size() == 100);
-			
+
 			int n = model.getObjectsOnCanvas().size();
 			assertTrue("Number of Edges does not Match", model.getEdgesOnCanvas().size() == (n * (n - 1)) / 2);
-			assertTrue("Element has no UnitGraph", !mp.searchEle((HolonObject)model.getObjectsOnCanvas().get(77), "Fridge").getGraphPoints().isEmpty());
-			assertTrue("Points in UnitGraph does not Match", mp.searchEle((HolonObject)model.getObjectsOnCanvas().get(77), "Fridge").getGraphPoints().size() == 3);
-			
+			assertTrue("Element has no UnitGraph", !mp
+					.searchEle((HolonObject) model.getObjectsOnCanvas().get(77), "Fridge").getGraphPoints().isEmpty());
+			assertTrue("Points in UnitGraph does not Match",
+					mp.searchEle((HolonObject) model.getObjectsOnCanvas().get(77), "Fridge").getGraphPoints()
+							.size() == 3);
+
 		} catch (IOException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
 	}
-	
-	@Test (expected=FileNotFoundException.class)
+
+	@Test(expected = FileNotFoundException.class)
 	public void testLoadException() throws IOException {
 		assertTrue("Save File was not found", !new File(path + "TestSavDummy.json").exists());
 		loadController.readJSON(path + "TestSavDummy.json");
@@ -299,7 +301,8 @@ public class PraktikumHolonsTestLoadAndStoreController {
 	/**
 	 * sets the graph points in all elements of an Object.
 	 * 
-	 * @param obj the Object
+	 * @param obj
+	 *            the Object
 	 */
 	public void setGraphPoints(HolonObject obj) {
 		LinkedList<Point> list = new LinkedList<>();

+ 2 - 1
src/tests/PraktikumHolonsTestSuite.java

@@ -19,7 +19,8 @@ public class PraktikumHolonsTestSuite {
 		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestObjectController.class));
 		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestLoadAndStoreController.class));
 		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestGlobalController.class));
-//		suite.addTest(new JUnit4TestAdapter(praktikumHolonsTestAutoSaveController.class));
+		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestAutoSaveController.class));
+		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestConsoleController.class));
 		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestClasses.class));
 		return suite;
 	}