Tester methods modified

This commit is contained in:
ericnerdo 2016-04-26 00:46:09 +02:00
parent b37606b86f
commit 848350394f

View File

@ -43,7 +43,7 @@ public class Tester {
} }
} }
void boxLift(String param) { String boxLift(String param) {
switch (param) { switch (param) {
case "O" : case "O" :
oneill.boxLift(); oneill.boxLift();
@ -52,9 +52,10 @@ public class Tester {
jaffa.boxLift(); jaffa.boxLift();
break; break;
} }
return "box lifted";
} }
void boxDrop(String param) { String boxDrop(String param) {
switch (param) { switch (param) {
case "O" : case "O" :
oneill.boxDrop(); oneill.boxDrop();
@ -63,6 +64,7 @@ public class Tester {
oneill.boxDrop(); oneill.boxDrop();
break; break;
} }
return "box dropped";
} }
void shootONeillsGun(String param) { void shootONeillsGun(String param) {
@ -76,26 +78,29 @@ public class Tester {
} }
} }
void rotate(String playerParam, String directionParam) { String rotate(String playerParam, String directionParam) {
switch (playerParam) { switch (playerParam) {
case "O" : case "O" :
switch (directionParam) { switch (directionParam) {
case "L" : case "L" :
oneill.rotateLeft(); oneill.rotateLeft();
break; return oneill.getFacingDirection().toString();
case "R" : case "R" :
oneill.rotateRight(); oneill.rotateRight();
break; return oneill.getFacingDirection().toString();
default: return "Hiba, nem fordult!";
} }
case "J" : case "J" :
switch (directionParam) { switch (directionParam) {
case "L" : case "L" :
jaffa.rotateLeft(); jaffa.rotateLeft();
break; return jaffa.getFacingDirection().toString();
case "R" : case "R" :
jaffa.rotateRight(); jaffa.rotateRight();
break; return jaffa.getFacingDirection().toString();
default: return "Hiba, nem fordult!";
} }
default: return "Hiba, nem létező játékos!";
} }
} }
@ -108,6 +113,12 @@ public class Tester {
return blue + " " + yellow + " " + red + " " + green; return blue + " " + yellow + " " + red + " " + green;
} }
String getConnectedGateOpen(Scale s){
if(s.getGateConnected().isOpen())
return "gate open";
else return "gate closed";
}
/* custom Test annotation */ /* custom Test annotation */
@Target(ElementType.METHOD) // it's for methods @Target(ElementType.METHOD) // it's for methods
@Retention(RetentionPolicy.RUNTIME) // we want to retain annotations in runtime @Retention(RetentionPolicy.RUNTIME) // we want to retain annotations in runtime
@ -134,31 +145,31 @@ public class Tester {
@Test @Test
boolean moveTest() throws IOException{ boolean moveTest() throws IOException{
boolean succes = true; boolean success = true;
loadMap("moveTest"); loadMap("moveTest");
String listOfPlayers = listPlayers(); String listOfPlayers = listPlayers();
if(!listOfPlayers.equals("ONeill: 1, 1 Jaffa: -666, -666 Replicator: -666, -666")) if(!listOfPlayers.equals("ONeill: 1, 1 Jaffa: -666, -666 Replicator: -666, -666"))
succes = false; success = false;
move("O"); move("O");
listOfPlayers = listPlayers(); listOfPlayers = listPlayers();
if(!listOfPlayers.equals("ONeill: 1, 2 Jaffa: -666, -666 Replicator: -666, -666")) if(!listOfPlayers.equals("ONeill: 1, 2 Jaffa: -666, -666 Replicator: -666, -666"))
succes = false; success = false;
System.out.print("moveTest: "); System.out.print("moveTest: ");
if(succes) if(success)
System.out.println("Sikeres!"); System.out.println("Sikeres!");
else System.out.println("Sikertelen!"); else System.out.println("Sikertelen!");
return succes; return success;
} }
@Test @Test
boolean testStargates() throws IOException{ boolean testStargates() throws IOException{
boolean succes = true; boolean success = true;
loadMap("testStargates"); loadMap("testStargates");
shootONeillsGun("B"); shootONeillsGun("B");
@ -167,7 +178,7 @@ public class Tester {
String listOfStargates = listStargates(); String listOfStargates = listStargates();
if(!listOfStargates.equals("BlueStargate: 5, 10 YellowStargate: 10, 5 RedStargate: not spawned GreenStargate: not spawned")) if(!listOfStargates.equals("BlueStargate: 5, 10 YellowStargate: 10, 5 RedStargate: not spawned GreenStargate: not spawned"))
succes = false; success = false;
move("O"); move("O");
move("O"); move("O");
@ -175,95 +186,70 @@ public class Tester {
String listOfPlayers = listPlayers(); String listOfPlayers = listPlayers();
if(!listOfPlayers.equals("ONeill: 5, 9 Jaffa: -666, -666 Replicator: -666, -666")) if(!listOfPlayers.equals("ONeill: 5, 9 Jaffa: -666, -666 Replicator: -666, -666"))
succes = false; success = false;
System.out.print("testStargates: "); System.out.print("testStargates: ");
if(succes) if(success)
System.out.println("Sikeres!"); System.out.println("Sikeres!");
else System.out.println("Sikertelen!"); else System.out.println("Sikertelen!");
return succes; return success;
} }
@Test @Test
boolean testExtraZPM(){
String[] commands = {"loadMap testExtraZPMs\n",
"listZPMs\n",
"move O\n",
"move O\n",
"listZPMs\n"};
String[] expectedOutputs = {};
loadMap("testExtraZPMs");
boolean results = testOnSequenceOfCommands(commands, expectedOutputs);
System.out.print("testExtraZPMs: ");
if(results)
System.out.println("Sikeres!");
else System.out.println("Sikertelen!");
return results;
}
boolean testScalesAndGates() throws IOException { boolean testScalesAndGates() throws IOException {
boolean succes = true; boolean success = true;
String[] commands = {"loadMap testScalesAndGates\n",
"boxLift O\n",
"rotate O L\n",
"boxDrop O\n"};
String[] expectedOutputs = {"door open\n"};
loadMap("testScalesAndGates"); loadMap("testScalesAndGates");
boxLift("O"); boxLift("O");
rotate("O", "L"); rotate("O", "L");
boxDrop("O"); boxDrop("O");
String gateOpen = getConnectedGateOpen((Scale)oneill.getCurrentTile().getAdjacentTile(oneill.facingDirection));
if(!gateOpen.equals("gate open"))
success = false;
System.out.print("testScalesAndGates: "); System.out.print("testScalesAndGates: ");
if(succes) if(success)
System.out.println("Sikeres!"); System.out.println("Sikeres!");
else System.out.println("Sikertelen!"); else System.out.println("Sikertelen!");
return succes; return success;
} }
@Test @Test
boolean gapTest(){ boolean gapTest() throws IOException{
String[] commands = {"loadMap gapTest\n",
"move O\n"};
String[] expectedOutputs = {}; loadMap("gapTest");
boolean results = testOnSequenceOfCommands(commands, expectedOutputs); move("O");
boolean success = oneill.isDestroyed();
System.out.print("gapTest: "); System.out.print("gapTest: ");
if(results) if(success)
System.out.println("Sikeres!"); System.out.println("Sikeres!");
else System.out.println("Sikertelen!"); else System.out.println("Sikertelen!");
return results; return success;
} }
@Test @Test
boolean ZPMTest() throws IOException{ boolean ZPMTest() throws IOException{
boolean succes = true; boolean success = true;
String[] commands = {"loadMap ZPMTest\n",
"move O\n"};
String[] expectedOutputs = {};
loadMap("ZPMTest"); loadMap("ZPMTest");
move("O"); move("O");
if(oneill.getZPMCount() != 1)
success = false;
System.out.print("ZPMTest: "); System.out.print("ZPMTest: ");
if(succes) if(success)
System.out.println("Sikeres!"); System.out.println("Sikeres!");
else System.out.println("Sikertelen!"); else System.out.println("Sikertelen!");
return succes; return success;
} }
@Test @Test
@ -299,33 +285,46 @@ public class Tester {
} }
@Test @Test
boolean rotationTest() { boolean rotationTest() throws IOException {
String[] commands = {"loadMap rotationTest\n", boolean success = true;
"Rotate O L\n",
"Rotate O R\n"};
String[] expectedOutputs = {}; loadMap("rotationTest");
boolean results = testOnSequenceOfCommands(commands, expectedOutputs);
if(!rotate("O", "L").equals("WEST"))
success = false;
if(!rotate("O", "R").equals("NORTH"))
success = false;
System.out.print("rotationTest: "); System.out.print("rotationTest: ");
} if(success)
@Test
boolean testBoxes(){
String[] commands = {"loadMap testBoxes\n",
"boxLift\n",
"boxDrop\n"};
String[] expectedOutputs = {"boc3 lifted\n",
"box3 dropped\n"};
boolean results = testOnSequenceOfCommands(commands, expectedOutputs);
System.out.print("testBoxes: ");
if(results)
System.out.println("Sikeres!"); System.out.println("Sikeres!");
else System.out.println("Sikertelen!"); else System.out.println("Sikertelen!");
return results; return success;
}
@Test
boolean testBoxes() throws IOException{
boolean success = true;
loadMap("testBoxes");
if(!boxLift("O").equals("box lifted"))
success = false;
if(!boxDrop("O").equals("box dropped"))
success = false;
System.out.print("testBoxes: ");
if(success)
System.out.println("Sikeres!");
else System.out.println("Sikertelen!");
return success;
}
private boolean testOnSequenceOfCommands(String[] commands, String[] expectedOutputs) {
return true;
} }
} }