-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOneStepAlienTest.java
69 lines (57 loc) · 1.78 KB
/
OneStepAlienTest.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
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class OneStepAlienTest {
OneStepAlien osa;
BattleFieldElement element;
@Before
public void init(){
osa = new OneStepAlien(3,2);
element = new OneStepAlien(3,2);
}
@Test
public void testMove() {
assertEquals("At the start the x: 2", 2, element.getX());
assertEquals("At the start the y: 3", 3, element.getY());
element.move(4, 5);
assertEquals("After move method calling the x became: 5", 5, element.getX());
assertEquals("After move method calling the y became: 4", 4, element.getY());
}
@Test
public void testGetXOffset() {
BattleField bf = null;
try {
bf = new BattleField("es-in.txt");
} catch (IllegalElementException e) {
e.printStackTrace();
} catch (IllegalPositionException e) {
e.printStackTrace();
}
bf.setColumns(5);
assertEquals("Entry in first if", 5-(2+1), osa.getXOffset());
osa.changeDirection();
assertEquals("after changed direction", -2, osa.getXOffset());
osa.changeDirection(); //reset back because is static
}
@Test
public void testGetYOffset() {
assertEquals("Y of one step alien must return 0", 0, osa.getYOffset());
}
@Test
public void testToString() {
assertEquals("String returned must be: A", "A", osa.toString());
}
@Test
public void testOneStepAlien() {
assertEquals("The v must be: 3", 3, element.getY());
assertEquals("The h must be: 2", 2, element.getX());
}
@Test
public void testChangeDirection() {
assertEquals("armyDirection must be 1", 1, osa.getArmyDirection());
osa.changeDirection();
assertEquals("armyDirection (after call of change direction method) must be -1", -1, osa.getArmyDirection());
osa.changeDirection();
assertEquals("armyDirection return to 1", 1, osa.getArmyDirection());
}
}