-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubmissionTestSuite.java
138 lines (96 loc) · 3 KB
/
SubmissionTestSuite.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package breakout;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class SubmissionTestSuite {
Ball[] oneBall;
BlockState[] oneBlock;
Point bottomRight;
PaddleState paddle;
BreakoutState state1;
BreakoutState stateWon;
BreakoutState stateDead;
BreakoutState stateBeforeBounceBlock;
Vector origBallVelocity;
BlockState bounceBlock;
Ball ball;
public static final String initMap1 = """
#
o
=
""";
public static final String initMapWon = """
o
=
""";
public static final String initMapDead = """
#
=
""";
public static final String initMapBeforeBounce = """
o
###
=
""";
@BeforeEach
void setUp() throws Exception {
state1 = GameMap.createStateFromDescription(initMap1);
oneBall = state1.getBalls();
ball = oneBall[0];
origBallVelocity = ball.getVelocity();
oneBlock = state1.getBlocks();
bottomRight = state1.getBottomRight();
paddle = state1.getPaddle();
stateWon = GameMap.createStateFromDescription(initMapWon);
stateDead = GameMap.createStateFromDescription(initMapDead);
stateBeforeBounceBlock = GameMap.createStateFromDescription(initMapBeforeBounce);
}
@Test
void testBreakoutStateNull() {
assertThrows(IllegalArgumentException.class,
() -> new BreakoutState(null,oneBlock,bottomRight,paddle) );
assertThrows(IllegalArgumentException.class,
() -> new BreakoutState(oneBall,null,bottomRight,paddle) );
assertThrows(IllegalArgumentException.class,
() -> new BreakoutState(oneBall,oneBlock,null,paddle) );
assertThrows(IllegalArgumentException.class,
() -> new BreakoutState(oneBall,oneBlock,bottomRight,null) );
}
@Test
void testBreakoutStateNormal() {
BreakoutState state = new BreakoutState(oneBall,oneBlock,bottomRight,paddle);
assertTrue(Arrays.equals(oneBall, state.getBalls()));
assertTrue(Arrays.equals(oneBlock, state.getBlocks()));
assertEquals(bottomRight,state.getBottomRight());
assertEquals(paddle, state.getPaddle());
}
@Test
void testTickNormal() {
state1.tick(0,1);
assertEquals(1,state1.getBalls().length);
Ball b = state1.getBalls()[0];
assertEquals(origBallVelocity,b.getVelocity());
}
@Test
void testTickBounceBlock() {
for(int i = 0; i < 500; ++i) {
stateBeforeBounceBlock.tick(1,1);
}
assertEquals(1,stateBeforeBounceBlock.getBalls().length);
assertEquals(2,stateBeforeBounceBlock.getBlocks().length);
assertEquals(new Vector(4,-5),stateBeforeBounceBlock.getBalls()[0].getVelocity());
}
@Test
void testIsWon() {
assertFalse(state1.isWon());
assertTrue(stateWon.isWon());
assertFalse(stateDead.isWon());
}
@Test
void testIsDead() {
assertFalse(state1.isDead());
assertFalse(stateWon.isDead());
assertTrue(stateDead.isDead());
}
}