-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMazeJUnitTest.java
111 lines (94 loc) · 3.19 KB
/
MazeJUnitTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import org.junit.Test;
import java.io.File;
import java.io.FileReader;
import static junit.framework.TestCase.assertEquals;
/**
*
* Created by KaninJaevel on 16/04/2016.
*/
public class MazeJUnitTest {
/**
* Tests if the maze is able to be created with a
* correctly implemented maze-file.
* @throws Exception
*/
@Test
public void shouldBeAbleToCreate() throws Exception{
File inputFile= new File(System.getProperty("user.dir")
+"/testMazes/correctMaze.txt");
new Maze(inputFile);
}
/**
* Tests if the maze correctly throws if maze-file is
* implemented wrong.
* @throws Exception
*/
@Test (expected = Exception.class)
public void createWithInvalidSymbols() throws Exception {
File inputFile= new File(System.getProperty("user.dir")
+"/testMazes/incorrectMaze.txt");
new Maze(inputFile);
}
/**
* Tests if the maze correctly throws if maze-file is
* implemented wrong.
* @throws Exception
*/
@Test (expected = Exception.class)
public void createWithoutGoalOrStart() throws Exception {
File inputFile= new File(System.getProperty("user.dir")
+"testMazes/incorrectMaze2.txt");
new Maze(inputFile);
}
/**
* Tests if the getStartPosition method works as intended.
* @throws Exception
*/
@Test
public void testGetStartPosition() throws Exception{
File inputFile= new File(System.getProperty("user.dir")
+"/testMazes/correctMaze.txt");
Maze m = new Maze(inputFile);
assertEquals(2,m.getStartPosition().getX());
assertEquals(0,m.getStartPosition().getY());
}
/**
* Tests if isGoal works as intended.
* @throws Exception
*/
@Test
public void testisGoal() throws Exception {
File inputFile= new File(System.getProperty("user.dir")
+"/testMazes/correctMaze.txt");
Maze m = new Maze(inputFile);
Position p = new Position(0,0);
if(m.isGoal(p))
throw new Exception("isGoal not working as expected.");
p = new Position(4,2);
if(!m.isGoal(p))
throw new Exception("Goal is not at expected position");
}
/**
* Tests if isMovable works as intended.
* @throws Exception
*/
@Test
public void testIsMovable() throws Exception {
File inputFile= new File(System.getProperty("user.dir")
+"/testMazes/correctMaze.txt");
Maze m = new Maze(inputFile);
Position p = new Position(0,0);
if(m.isMovable(p))
throw new Exception("isMovable is not working as expected.");
p = new Position(1,1);
if(!m.isMovable(p))
throw new Exception("isMovable is not working as expected.");
}
@Test
public void shouldBeAbleToPrint() throws Exception{
File inputFile= new File(System.getProperty("user.dir")
+"/testMazes/correctMaze.txt");
Maze m = new Maze(inputFile);
m.printMaze(m.getStartPosition());
}
}