-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChenilleTest.java
More file actions
118 lines (102 loc) · 3.59 KB
/
Copy pathChenilleTest.java
File metadata and controls
118 lines (102 loc) · 3.59 KB
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
import static org.junit.Assert.*;
import org.junit.Test;
public class ChenilleTest {
@SuppressWarnings("deprecation")
@Test
public void testConstructors() {
Espace e = new Espace();
Case c = new Case(1, 1);
Chenille ch = new Chenille(e, c, 5);
assertEquals("Testing constructor A", e, ch.getEspace());
assertEquals("Testing constructor A", 1, ch.getTaille());
assertEquals("Testing constructor A", 5, ch.getCases().length);
assertEquals("Testing constructor A", new Case[] { c }, ch.getOccupiedCases());
ch = new Chenille(e, 5);
assertEquals("Testing constructor B", e, ch.getEspace());
assertEquals("Testing constructor B", 1, ch.getTaille());
assertEquals("Testing constructor B", 5, ch.getCases().length);
ch = new Chenille(e);
assertEquals("Testing constructor C", e, ch.getEspace());
assertEquals("Testing constructor C", 1, ch.getTaille());
assertEquals("Testing constructor C", 10, ch.getCases().length);
}
@Test
public void testEstSur() {
Espace e = new Espace();
Case c = new Case(1, 1);
Chenille ch = new Chenille(e, c, 5);
assertEquals("Testing estSur", true, ch.estSur(c));
assertEquals("Testing estSur", false, ch.estSur(new Case(2, 2)));
}
@SuppressWarnings("deprecation")
@Test
public void testGetOccupiedCases() {
Espace e = new Espace();
Case c = new Case(1, 1);
Chenille ch = new Chenille(e, c, 5);
assertEquals("Testing getOccupiedCases", new Case[] { c }, ch.getOccupiedCases());
ch.avance();
// occupies 1 space by default, avance() increases by 1
assertEquals("Testing getOccupiedCases", 2, ch.getOccupiedCases().length);
}
/*
* As avance() works on randomness, our tests are limited to input we can
* predict. As such, the test class tests for when only one neighbour is
* free (i.e. it should have to move to this neighbour alone) as well as
* when there are no neighbours free.
*/
@SuppressWarnings("deprecation")
@Test
public void testAvance() {
Espace e = new Espace();
Case c = new Case(1, 1);
Chenille ch = new Chenille(e, c, 2);
e.addChenille(ch);
//north neighbour
Chenille ch1 = new Chenille(e,c.nord(),1);
e.addChenille(ch1);
//east neighbour
Chenille ch2 = new Chenille(e,c.est(),1);
e.addChenille(ch2);
//west neighbour
Chenille ch3 = new Chenille(e,c.ouest(),1);
e.addChenille(ch3);
ch.avance();
assertEquals("Testing avance",new Case[]{c.sud(),c},ch.getOccupiedCases());
e = new Espace();
c = new Case(5,5);
ch = new Chenille(e, c, 5);
e.addChenille(ch);
//north neighbour
ch1 = new Chenille(e,c.nord(),1);
e.addChenille(ch1);
//east neighbour
ch2 = new Chenille(e,c.est(),1);
e.addChenille(ch2);
//west neighbour
ch3 = new Chenille(e,c.ouest(),1);
e.addChenille(ch3);
//add south neighbour, so all four neighbour spots are filled
Chenille ch4 = new Chenille(e,c.sud(),1);
e.addChenille(ch4);
ch.avance();
assertEquals("Testing avance",false,ch.peutAvancer());
}
@Test
public void testToString() {
Espace e = new Espace();
Case c = new Case(1, 1);
Chenille ch = new Chenille(e, c, 1);
String s = "Chenille(1/1):[(1, 1)]";
assertEquals("Testing toString",s,ch.toString());
}
public void testGetters() {
Espace e = new Espace();
Case c = new Case(1, 1);
Chenille ch = new Chenille(e, c, 5);
assertEquals("Testing getEspace()",e,ch.getEspace());
assertEquals("Testing getTaille()",1,ch.getTaille());
assertEquals("Testing getCases()",5,ch.getCases().length);
assertEquals("Testing peutAvancer",true,ch.peutAvancer());
}
}