2
2
3
3
import static org .hamcrest .CoreMatchers .equalTo ;
4
4
import static org .hamcrest .MatcherAssert .assertThat ;
5
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
5
6
6
7
import java .util .List ;
7
8
import org .junit .jupiter .api .Test ;
@@ -17,4 +18,60 @@ void finalPositionOfSnake2() {
17
18
assertThat (
18
19
new Solution ().finalPositionOfSnake (3 , List .of ("DOWN" , "RIGHT" , "UP" )), equalTo (1 ));
19
20
}
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
+ }
20
77
}
0 commit comments