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 = {};
boolean results = testOnSequenceOfCommands(commands, expectedOutputs);
loadMap("gapTest");
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
@ -297,35 +283,48 @@ public class Tester {
return results; return results;
} }
@Test @Test
boolean rotationTest() { boolean rotationTest() throws IOException {
String[] commands = {"loadMap rotationTest\n", boolean success = true;
"Rotate O L\n",
"Rotate O R\n"}; loadMap("rotationTest");
String[] expectedOutputs = {};
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)
System.out.println("Sikeres!");
else System.out.println("Sikertelen!");
return success;
} }
@Test @Test
boolean testBoxes(){ boolean testBoxes() throws IOException{
String[] commands = {"loadMap testBoxes\n", boolean success = true;
"boxLift\n",
"boxDrop\n"};
String[] expectedOutputs = {"boc3 lifted\n", loadMap("testBoxes");
"box3 dropped\n"};
if(!boxLift("O").equals("box lifted"))
boolean results = testOnSequenceOfCommands(commands, expectedOutputs); success = false;
if(!boxDrop("O").equals("box dropped"))
success = false;
System.out.print("testBoxes: "); System.out.print("testBoxes: ");
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;
}
private boolean testOnSequenceOfCommands(String[] commands, String[] expectedOutputs) {
return true;
} }
} }