PraktikumHolonsTestClasses.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package tests;
  2. import classes.*;
  3. import org.junit.Test;
  4. import java.util.ArrayList;
  5. import static org.junit.Assert.assertTrue;
  6. /**
  7. * Test for the Classes.
  8. *
  9. * @author Gruppe14
  10. */
  11. public class PraktikumHolonsTestClasses {
  12. /**
  13. * Test for the Categories.
  14. */
  15. @Test
  16. public void testCategory() {
  17. Category test1 = new Category("Test1");
  18. Category test2 = new Category("Test2");
  19. HolonObject obj1 = new HolonObject("Test Object");
  20. ArrayList<AbstractCanvasObject> arr = new ArrayList<>();
  21. assertTrue("Name not correct", test1.getName().equals("Test1"));
  22. assertTrue("Name not correct", test2.getName().equals("Test2"));
  23. assertTrue("Name should not be the same", !test1.getName().equals(test2.getName()));
  24. assertTrue("Should be empty", test1.getObjects().size() == 0);
  25. test1.getObjects().add(obj1);
  26. assertTrue("Should not be empty", test1.getObjects().size() == 1);
  27. assertTrue("Should be empty", test2.getObjects().size() == 0);
  28. test1.setObjects(arr);
  29. assertTrue("Should be empty", test1.getObjects().size() == 0);
  30. arr.add(obj1);
  31. test2.setObjects(arr);
  32. arr = new ArrayList<>();
  33. assertTrue("Shoud be empty", arr.isEmpty());
  34. arr = test2.getObjects();
  35. assertTrue("Shoud not be empty", !arr.isEmpty());
  36. }
  37. /**
  38. * Test for HolonObject.
  39. */
  40. @Test
  41. public void testHolonObject() {
  42. HolonObject test1 = new HolonObject("Test1");
  43. HolonObject test2 = new HolonObject("Test2");
  44. HolonObject test3 = new HolonObject(test1);
  45. HolonElement ele = new HolonElement(test1, "Element", 1, 10, IdCounterElem.nextId());
  46. ArrayList<HolonElement> arr = new ArrayList<>();
  47. assertTrue("Should be Empty", test1.getElements().isEmpty());
  48. test1.setElements(arr);
  49. assertTrue("Should be Empty", test1.getElements().isEmpty());
  50. arr.add(ele);
  51. arr.add(ele);
  52. assertTrue("Should be Empty", test2.getElements().isEmpty());
  53. test2.setElements(arr);
  54. assertTrue("Should not be Empty", !test2.getElements().isEmpty());
  55. assertTrue("Current Energy not corrent", test2.getEnergyAtTimeStep(20) == 20);
  56. String str = test2.toStringElements();
  57. assertTrue("String not corrent", str.equals("Element, Element"));
  58. test2.deleteElement(0);
  59. test2.addElement(ele);
  60. assertTrue("Should be Empty", test3.getElements().isEmpty());
  61. test3.setElements(test2.copyElements(test2.getElements()));
  62. assertTrue("Element not Found", test3.searchElement("Element") != null);
  63. test1.setElements(new ArrayList<>());
  64. }
  65. /**
  66. * Test for HolonSwitch.
  67. */
  68. // @Test
  69. // public void testHolonSwitch() {
  70. // HolonSwitch test1 = new HolonSwitch("Test1");
  71. // HolonSwitch test2 = new HolonSwitch(test1);
  72. //
  73. // assertTrue("Manuel Mode is on", !test2.getManualMode());
  74. // test2.switchState();
  75. // assertTrue(test2.isWorking());
  76. // assertTrue(test2.isWorking(1));
  77. // test2.setManualMode(true);
  78. // test2.switchState();
  79. // test2.switchState();
  80. // assertTrue(test2.isWorking());
  81. // assertTrue(test2.isWorking(1));
  82. // assertTrue("Manuel Mode is off", test2.getManualMode());
  83. // assertTrue("ManuelActive is off", test2.getActiveManual());
  84. // test2.switchState();
  85. // assertTrue("ManuelActive is on", !test2.getActiveManual());
  86. // test2.switchState();
  87. // assertTrue("ManuelActive is off", test2.getActiveManual());
  88. // assertTrue(test1.getGraphPoints() != test2.getGraphPoints());
  89. // test2.setGraphPoints(test1.getGraphPoints());
  90. // assertTrue(test1.getGraphPoints() == test2.getGraphPoints());
  91. // }
  92. /**
  93. * Test for CpsEdge.
  94. */
  95. @Test
  96. public void testCpsEdge() {
  97. Node node1 = new Node("Node1");
  98. Node node2 = new Node("Node2");
  99. Node node3 = new Node("Node3");
  100. Edge edge1 = new Edge(node1, node2, 100);
  101. Edge edge2 = new Edge(node2, node3);
  102. node1 = (Node) edge1.getB();
  103. node2 = (Node) edge2.getA();
  104. assertTrue("Not Same", node1 == node2);
  105. edge2.setTags(new ArrayList<>());
  106. edge1.setTags(new ArrayList<>());
  107. assertTrue("Tags not Empty", edge2.getTags().isEmpty());
  108. edge2.addTag(1);
  109. assertTrue("Tags not Empty", edge1.getTags().isEmpty());
  110. assertTrue("Tags Empty", !edge2.getTags().isEmpty());
  111. edge1.setTags(edge2.getTags());
  112. assertTrue("Tags Empty", !edge1.getTags().isEmpty());
  113. }
  114. /**
  115. * Test for HolonElement.
  116. */
  117. @Test
  118. public void testHolonElement() {
  119. HolonElement ele1 = new HolonElement(null, "TV", 2, -20f, IdCounterElem.nextId());
  120. HolonElement ele2 = new HolonElement(null, "Fridge", 1, -50f, IdCounterElem.nextId());
  121. assertTrue("Array not empty", ele1.getEnergyAtTimeStep(0) == -40);
  122. assertTrue("Array not empty", ele1.getEnergyAtTimeStep(2) == -40);
  123. assertTrue("Name not correct", ele1.getEleName().equals("TV"));
  124. ele1.setEleName(ele2.getEleName());
  125. assertTrue("Name not correct", ele1.getEleName().equals("Fridge"));
  126. assertTrue("Amount not correct", ele2.getAmount() == 1);
  127. ele2.setAmount(5);
  128. assertTrue("Amount not correct", ele2.getAmount() == 5);
  129. assertTrue("Total Energy not Correct", ele2.getMaximumEnergy() == ele2.getAmount() * ele2.getEnergyPerElement());
  130. }
  131. /**
  132. * Test for Position.
  133. */
  134. @Test
  135. public void testPosition() {
  136. Position pos1 = new Position(100, 200);
  137. Position pos2 = new Position();
  138. assertTrue("Wrong coordinates", pos1.x == 100 && pos1.y == 200);
  139. assertTrue("Are the Same", pos1.x != pos2.x);
  140. assertTrue("not (-1,-1)", pos2.x == -1 && pos2.y == -1);
  141. }
  142. }