added tests for Nexus6 and RobotBluePrint
parent
b18663a28e
commit
9422e5c6ae
|
@ -1,26 +1,36 @@
|
|||
import de.hsmannheim.informatik.name.domain.RobotFactory;
|
||||
import de.hsmannheim.informatik.name.domain.RobotType;
|
||||
import de.hsmannheim.informatik.name.domain.exceptions.RobotException;
|
||||
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
|
||||
import de.hsmannheim.informatik.name.domain.requirements.Robot;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws RobotIllegalStateException {
|
||||
RobotFactory rf = new RobotFactory();
|
||||
RobotType R2D2 = RobotType.R2D2;
|
||||
RobotType C3P0 = RobotType.C3P0;
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
if(rf.getRobot(R2D2, "TestR2D2") == null){
|
||||
System.out.println("Error");
|
||||
}
|
||||
}
|
||||
System.out.println("finished R2D2");
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
if(rf.getRobot(C3P0, "TestC3P0") == null){
|
||||
System.out.println("Error");
|
||||
}
|
||||
}
|
||||
System.out.println("finished C3P0");
|
||||
System.out.println("finished");
|
||||
}
|
||||
// public static void main(String[] args) throws RobotException {
|
||||
// RobotFactory rf = new RobotFactory();
|
||||
// RobotType R2D2 = RobotType.R2D2;
|
||||
// RobotType C3P0 = RobotType.C3P0;
|
||||
//// for (int i = 0; i < 10000; i++) {
|
||||
//// if(rf.getRobot(R2D2, "TestR2D2") == null){
|
||||
//// System.out.println("Error");
|
||||
//// }
|
||||
//// }
|
||||
// Robot r1 = rf.getRobot(R2D2, "R2Test");
|
||||
// System.out.println(r1.getName());
|
||||
// try{
|
||||
// r1.think(new int[]{1,2,42,5});
|
||||
// } catch (RobotException re) {
|
||||
// System.err.println(re.getRobotName());
|
||||
// }
|
||||
// System.out.println("finished R2D2");
|
||||
// for (int i = 0; i < 10000; i++) {
|
||||
// if(rf.getRobot(C3P0, "TestC3P0") == null){
|
||||
// System.out.println("Error");
|
||||
// }
|
||||
// }
|
||||
// System.out.println("finished C3P0");
|
||||
// System.out.println("finished");
|
||||
// }
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@ class RobotFactoryTest {
|
|||
assertNull( rf.getRobot(R2D2, "TestR2D2"));
|
||||
}
|
||||
@Test
|
||||
public void toMuchC3P0() throws RobotIllegalStateException {
|
||||
public void toMuchC3P0() throws RobotIllegalStateException {
|
||||
RobotFactory rf = new RobotFactory();
|
||||
RobotType R2D2 = RobotType.C3P0;
|
||||
for (int i = 0; i < 9999; i++) {
|
||||
|
@ -27,4 +27,5 @@ class RobotFactoryTest {
|
|||
assertInstanceOf(C3PO.class, rf.getRobot(R2D2, "Test"));
|
||||
assertNull( rf.getRobot(R2D2, "TestC3P0"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package de.hsmannheim.informatik.name.domain.bladerunner;
|
||||
|
||||
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class NexusTest {
|
||||
@Test
|
||||
public void toManyNexusTest() throws RobotIllegalStateException {
|
||||
Nexus6 n1 = Nexus6.getInstance();
|
||||
assertEquals(n1, Nexus6.getInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nexusThinkTest() throws RobotIllegalStateException {
|
||||
Nexus6 n1 = Nexus6.getInstance();
|
||||
assertThrows(RobotIllegalStateException.class, () -> n1.think(new int[]{1,2,3,4}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nexusSpeakTest() throws RobotIllegalStateException {
|
||||
Nexus6 n1 = Nexus6.getInstance();
|
||||
assertThrows(RobotIllegalStateException.class, () -> n1.speak(new int[]{1,2,3,4}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPowerSwitch() throws RobotIllegalStateException {
|
||||
Nexus6 n1 = Nexus6.getInstance();
|
||||
n1.triggerPowerSwitch();
|
||||
assertFalse(n1.isPowerOn());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package de.hsmannheim.informatik.name.domain.starwars;
|
||||
|
||||
import de.hsmannheim.informatik.name.domain.exceptions.RobotException;
|
||||
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
|
||||
import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class GetterTest {
|
||||
@Test
|
||||
public void getIDTest() throws RobotIllegalStateException {
|
||||
C3PO c1 = new C3PO(10001, "C3PO");
|
||||
assertEquals(10001, c1.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameTest() throws RobotIllegalStateException {
|
||||
C3PO c1 = new C3PO(10001, "C3PO");
|
||||
assertEquals("C3PO", c1.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void powerSwitchTest() throws RobotIllegalStateException {
|
||||
C3PO c1 = new C3PO(10001, "C3PO");
|
||||
assertFalse(c1.isPowerOn());
|
||||
c1.triggerPowerSwitch();
|
||||
assertTrue(c1.isPowerOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLastExceptionTest() throws RobotIllegalStateException {
|
||||
C3PO c1 = new C3PO(10001, "C3PO");
|
||||
try {
|
||||
c1.think(new int[]{42});
|
||||
} catch (RobotException e) {
|
||||
assertEquals(e, c1.getLastException());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameFromExceptionTest() throws RobotIllegalStateException {
|
||||
C3PO c1 = new C3PO(10001, "C3PO");
|
||||
try {
|
||||
c1.think(new int[]{42});
|
||||
} catch (RobotException e) {
|
||||
assertEquals(c1.getName(), e.getRobotName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue