📄 testharness.java
字号:
// create new maze system instance
buildTestMaze();
// check reset
System.out.print("Checking for reset result...");
if (failureCheck( t.reset() ,false))
return false;
// set start point
System.out.print("Setting a start point...");
if (failureCheck( b.setStartPoint(new MazeRef(1,2,3)) ,true))
return false;
// set finish point
System.out.print("Setting a finish point...");
if (failureCheck( b.setFinishPoint(new MazeRef(2,2,5)) ,true))
return false;
// check reset
System.out.print("Checking for reset result...");
if (failureCheck( t.reset() ,true))
return false;
// check player string representation
String s = t.getPlayer().toString();
System.out.print("Player string is ");
System.out.print("\"" + s + "\"");
if(!s.equalsIgnoreCase("UNKNOWN:50:1,2,3"))
{
System.out.println(" ... not correct");
return false;
}
else
System.out.println(" ... correct");
return true;
}
// --- test11 ----------------------------------------------------------
public static boolean test11() throws Exception
{
// create new maze system instance
initialiseEngine(new MazeRef(10,10,10));
// create new maze system instance
buildTestMaze();
// set start point
System.out.print("Setting a start point...");
if (failureCheck( b.setStartPoint(new MazeRef(1,2,3)) ,true))
return false;
// set finish point
System.out.print("Setting a finish point...");
if (failureCheck( b.setFinishPoint(new MazeRef(2,2,5)) ,true))
return false;
// check reset
System.out.print("Checking for reset result...");
if (failureCheck( t.reset() ,true))
return false;
// check player string representation
String s = t.getPlayer().toString();
System.out.print("Player string is ");
System.out.print("\"" + s + "\"");
if(!s.equalsIgnoreCase("UNKNOWN:50:1,2,3"))
{
System.out.println(" ... not correct");
return false;
}
else
System.out.println(" ... correct");
// move player
System.out.print("Moving the player...");
if (failureCheck( t.move("test") ,true))
return false;
// check player string representation
s = t.getPlayer().toString();
System.out.print("Player string is ");
System.out.print("\"" + s + "\"");
if(!s.equalsIgnoreCase("UNKNOWN:48:1,2,4"))
{
System.out.println(" ... not correct");
return false;
}
else
System.out.println(" ... correct");
return true;
}
// --- test12 ----------------------------------------------------------
public static boolean test12() throws Exception
{
// create new maze system instance
initialiseEngine(new MazeRef(10,10,10));
// create new maze system instance
buildTestMaze();
// set start point
System.out.print("Setting a start point...");
if (failureCheck( b.setStartPoint(new MazeRef(1,2,3)) ,true))
return false;
// set finish point
System.out.print("Setting a finish point...");
if (failureCheck( b.setFinishPoint(new MazeRef(2,2,5)) ,true))
return false;
// check reset
System.out.print("Checking for reset result...");
if (failureCheck( t.reset() ,true))
return false;
// move player
System.out.print("Moving the player...");
if (failureCheck( t.move("test") ,true))
return false;
// check player string representation
String s = t.getPlayer().toString();
System.out.print("Player string is ");
System.out.print("\"" + s + "\"");
if(!s.equalsIgnoreCase("UNKNOWN:48:1,2,4"))
{
System.out.println(" ... not correct");
return false;
}
else
System.out.println(" ... correct");
// move player
System.out.print("Moving the player...");
if (failureCheck( t.move("test") ,true))
return false;
// check player string representation
s = t.getPlayer().toString();
System.out.print("Player string is ");
System.out.print("\"" + s + "\"");
if(!s.equalsIgnoreCase("UNKNOWN:46:1,2,5"))
{
System.out.println(" ... not correct");
return false;
}
else
System.out.println(" ... correct");
return true;
}
// --- test13 ----------------------------------------------------------
public static boolean test13() throws Exception
{
// create new maze system instance
initialiseEngine(new MazeRef(10,10,10));
// create new maze system instance
buildTestMaze();
// set start point
System.out.print("Setting a start point...");
if (failureCheck( b.setStartPoint(new MazeRef(1,2,3)) ,true))
return false;
// set finish point
System.out.print("Setting a finish point...");
if (failureCheck( b.setFinishPoint(new MazeRef(2,2,5)) ,true))
return false;
// check reset
System.out.print("Checking for reset result...");
if (failureCheck( t.reset() ,true))
return false;
// move player
System.out.print("Moving the player to win (1)...");
if (failureCheck( t.move("win") ,true))
return false;
// move player
System.out.print("Moving the player to win (2)...");
if (failureCheck( t.move("win") ,true))
return false;
// move player
System.out.print("Moving the player to win (3)...");
try
{
if (failureCheck( t.move("win") ,true))
return false;
}
catch (GameException ge)
{
System.out.println(" game exception thrown, OK");
return true;
}
return false;
}
// --- test14 ----------------------------------------------------------
public static boolean test14() throws Exception
{
// create new maze system instance
initialiseEngine(new MazeRef(10,10,10));
// create new maze system instance
buildTestMaze();
// set start point
System.out.print("Setting a start point...");
if (failureCheck( b.setStartPoint(new MazeRef(1,2,3)) ,true))
return false;
// set finish point
System.out.print("Setting a finish point...");
if (failureCheck( b.setFinishPoint(new MazeRef(2,2,5)) ,true))
return false;
// check reset
System.out.print("Checking for reset result...");
if (failureCheck( t.reset() ,true))
return false;
// move player
System.out.print("Moving the player to lose (1)...");
if (failureCheck( t.move("lose") ,true))
return false;
// move player
System.out.print("Moving the player to lose (2)...");
if (failureCheck( t.move("lose") ,true))
return false;
// move player
System.out.print("Moving the player to lose (3)...");
try
{
if (failureCheck( t.move("lose") ,true))
return false;
}
catch (GameException ge)
{
System.out.println(" game exception thrown, OK");
return true;
}
return false;
}
// ************************************************************************
// ************************************************************************
// ************************************************************************
// ************************************************************************
// ************************************************************************
// DO NOT TOUCH ANYTHING PAST THIS POINT
// ************************************************************************
// ************************************************************************
// ************************************************************************
// ************************************************************************
// ************************************************************************
// --- test15 ----------------------------------------------------------
public static void test15()
{
boolean anyFail = false;
int count = 0;
System.out.println("These tests failed: ");
PrintStream realErr, realOut;
PrintStream outFile = null;
try
{
outFile = new PrintStream(new FileOutputStream(new File("tests.txt")));
}
catch (FileNotFoundException e)
{
System.out.println("test harness can't open a file for summarising");
return;
}
realErr = System.err;
realOut = System.out;
System.setErr(outFile);
System.setOut(outFile);
// okay remember here that System.out and System.err are now the file
// the real output streams are in realOut and realErr!
try
{
System.out.println("--- Test 1 --------------------------");
if (!test1())
{
realOut.println("Test 1 **FAIL** (incorrect implementation)");
anyFail = true;
count++;
}
}
catch (Exception e)
{
realOut.println("Test 1 **FAIL** (unexpected exception occurred)");
anyFail = true;
count++;
}
try
{
System.out.println("--- Test 2 --------------------------");
if (!test2())
{
realOut.println("Test 2 **FAIL** (incorrect implementation)");
anyFail = true;
count++;
}
}
catch (Exception e)
{
realOut.println("Test 2 **FAIL** (unexpected exception occurred)");
anyFail = true;
count++;
}
try
{
System.out.println("--- Test 3 --------------------------");
if (!test3())
{
realOut.println("Test 3 **FAIL** (incorrect implementation)");
anyFail = true;
count++;
}
}
catch (Exception e)
{
realOut.println("Test 3 **FAIL** (unexpected exception occurred)");
anyFail = true;
count++;
}
try
{
System.out.println("--- Test 4 --------------------------");
if (!test4())
{
realOut.println("Test 4 **FAIL** (incorrect implementation)");
anyFail = true;
count++;
}
}
catch (Exception e)
{
realOut.println("Test 4 **FAIL** (unexpected exception occurred)");
anyFail = true;
count++;
}
try
{
System.out.println("--- Test 5 --------------------------");
if (!test5())
{
realOut.println("Test 5 **FAIL** (incorrect implementation)");
anyFail = true;
count++;
}
}
catch (Exception e)
{
realOut.println("Test 5 **FAIL** (unexpected exception occurred)");
anyFail = true;
count++;
}
try
{
System.out.println("--- Test 6 --------------------------");
if (!test6())
{
realOut.println("Test 6 **FAIL** (incorrect implementation)");
anyFail = true;
count++;
}
}
catch (Exception e)
{
realOut.println("Test 6 **FAIL** (unexpected exception occurred)");
anyFail = true;
count++;
}
try
{
System.out.println("--- Test 7 --------------------------");
if (!test7())
{
realOut.println("Test 7 **FAIL** (incorrect implementation)");
anyFail = true;
count++;
}
}
catch (Exception e)
{
realOut.println("Test 7 **FAIL** (unexpected exception occurred)");
anyFail = true;
count++;
}
try
{
System.out.println("--- Test 8 --------------------------");
if (!test8())
{
realOut.println("Test 8 **FAIL** (incorrect implementation)");
anyFail = true;
count++;
}
}
catch (Exception e)
{
realOut.println("Test 8 **FAIL** (unexpected exception occurred)");
anyFail = true;
count++;
}
try
{
System.out.println("--- Test 9 --------------------------");
if (!test9())
{
realOut.println("Test 9 **FAIL** (incorrect implementation)");
anyFail = true;
count++;
}
}
catch (Exception e)
{
realOut.println("Test 9 **FAIL** (unexpected exception occurred)");
anyFail = true;
count++;
}
try
{
System.out.println("--- Test 10 --------------------------");
if (!test10())
{
realOut.println("Test 10 **FAIL** (incorrect implementation)");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -