Skip to content

Commit 4febd8e

Browse files
committed
Added tests
1 parent 818985e commit 4febd8e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/test/java/g3201_3300/s3248_snake_in_matrix/SolutionTest.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.hamcrest.CoreMatchers.equalTo;
44
import static org.hamcrest.MatcherAssert.assertThat;
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
56

67
import java.util.List;
78
import org.junit.jupiter.api.Test;
@@ -17,4 +18,60 @@ void finalPositionOfSnake2() {
1718
assertThat(
1819
new Solution().finalPositionOfSnake(3, List.of("DOWN", "RIGHT", "UP")), equalTo(1));
1920
}
21+
22+
@Test
23+
void testFinalPositionOfSnake_AllCommands() {
24+
List<String> commands = List.of("UP", "DOWN", "LEFT", "RIGHT");
25+
int result = new Solution().finalPositionOfSnake(3, commands);
26+
assertEquals(4, result);
27+
}
28+
29+
@Test
30+
void testFinalPositionOfSnake_OnlyUp() {
31+
List<String> commands = List.of("UP", "UP");
32+
int result = new Solution().finalPositionOfSnake(3, commands);
33+
assertEquals(0, result);
34+
}
35+
36+
@Test
37+
void testFinalPositionOfSnake_OnlyDown() {
38+
List<String> commands = List.of("DOWN", "DOWN");
39+
int result = new Solution().finalPositionOfSnake(3, commands);
40+
assertEquals(6, result);
41+
}
42+
43+
@Test
44+
void testFinalPositionOfSnake_OnlyLeft() {
45+
List<String> commands = List.of("LEFT", "LEFT");
46+
int result = new Solution().finalPositionOfSnake(3, commands);
47+
assertEquals(0, result);
48+
}
49+
50+
@Test
51+
void testFinalPositionOfSnake_OnlyRight() {
52+
List<String> commands = List.of("RIGHT", "RIGHT");
53+
int result = new Solution().finalPositionOfSnake(3, commands);
54+
assertEquals(2, result);
55+
}
56+
57+
@Test
58+
void testFinalPositionOfSnake_EmptyCommands() {
59+
List<String> commands = List.of();
60+
int result = new Solution().finalPositionOfSnake(3, commands);
61+
assertEquals(0, result);
62+
}
63+
64+
@Test
65+
void testFinalPositionOfSnake_MixedCommands() {
66+
List<String> commands = List.of("DOWN", "RIGHT", "UP", "LEFT", "UP", "DOWN", "RIGHT");
67+
int result = new Solution().finalPositionOfSnake(3, commands);
68+
assertEquals(4, result);
69+
}
70+
71+
@Test
72+
void testFinalPositionOfSnake_InvalidCommands() {
73+
List<String> commands = List.of("DOWN", "RIGHT", "JUMP", "LEFT", "UP", "DOWN", "RIGHT");
74+
int result = new Solution().finalPositionOfSnake(3, commands);
75+
assertEquals(4, result);
76+
}
2077
}

0 commit comments

Comments
 (0)