Subversion Repositories sokoban

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 daniel-mar 1
package gdi.ws0809.test;
2
 
3
 
4
import static org.junit.Assert.*;
5
 
6
import java.io.File;
7
import java.net.URISyntaxException;
8
 
9
import org.junit.Before;
10
import org.junit.BeforeClass;
11
import org.junit.Test;
12
 
13
/**
14
 * Public tests for the minimal Sokoban implementation level
15
 *
16
 * @author Steven Arzt, Oren Avni
17
 * @version 1.0
18
 */
19
public class SokobanTestMinimal {
20
 
21
        /**
22
         * the tested Sokoban implementation
23
         */
24
        private SokobanTest testee = null;
25
 
26
        /**
27
         * variables and constants needed for tests
28
         */
29
        private static File validLevel;
30
        private static final String validLevelString = "####\n# .#\n#  ###\n#*@  #\n#  $ #\n#  ###\n####\n";
31
        private static File levelWithoutMan;
32
        private static File solvedLevel;
33
 
34
 
35
        @BeforeClass
36
        public static void init() {
37
                try {
38
                        validLevel = new File(ClassLoader.getSystemClassLoader().getResource("valid.txt").toURI());
39
                        levelWithoutMan = new File(ClassLoader.getSystemClassLoader().getResource("noman.txt").toURI());
40
                        solvedLevel = new File(ClassLoader.getSystemClassLoader().getResource("solved.txt").toURI());
41
                } catch (final URISyntaxException e) {
42
                        e.printStackTrace();
43
                }
44
                SokobanTestAdapter.init();
45
        }
46
 
47
        @Before
48
        public void before() {
49
                testee = new SokobanTestAdapter();
50
        }
51
 
52
        /**
53
         * Requirements "parseLevel", "toString" & "checkSyntax"
54
         * @throws Exception
55
         */
56
        @Test
57
        public void parseValidLevelFile() throws Exception {
58
                testee.loadLevel(validLevel);
59
                assertEquals("The string representation of the parsed level1 differs from file content",validLevelString, testee.currentLevelToString());
60
        }
61
 
62
        @Test(expected=Exception.class)
63
        public void parseInvalidLevel() throws Exception {
64
                testee.loadLevel(levelWithoutMan);
65
        }
66
 
67
        /**
68
         * Requirements "detectSolved"
69
         * @throws Exception
70
         */
71
        @Test
72
        public void detectSolved() throws Exception {
73
                testee.loadLevel(validLevel);
74
                assertFalse("Unsolved level detected as solved.", testee.isSolved());
75
 
76
                testee.loadLevel(solvedLevel);
77
                assertTrue("Solved level not detected as solved.", testee.isSolved()); 
78
        }
79
 
80
        @Test
81
        public void testGetLevelWidth() throws Exception {
82
                testee.loadLevel(validLevel);
83
                assertEquals("The width of the first level should be", 6, testee.getLevelWidth());
84
        }
85
 
86
        @Test
87
        public void testGetLevelHeight () throws Exception {
88
                testee.loadLevel(validLevel);
89
                assertEquals("The height of the first level should be 7", 7, testee.getLevelHeight());
90
        }
91
 
92
        @Test
93
        public void testGetWallCount() throws Exception {
94
                testee.loadLevel(validLevel);
95
                assertEquals ("The first level contains 22 wall pieces", 22, testee.getWallCount());           
96
        }
97
 
98
        @Test
99
        public void testGetCrateCount() throws Exception        {
100
                testee.loadLevel(validLevel);
101
                assertEquals ("The first level contains 2 movable crates", 2, testee.getCrateCount());         
102
        }
103
 
104
        @Test
105
        public void testGetGoalCount() throws Exception {
106
                testee.loadLevel(validLevel);
107
                assertEquals ("The first level contains 2 goal positions", 2, testee.getGoalCount());          
108
        }
109
 
110
 
111
 
112
 
113
}
114