Repository navigation
Expand file tree
/
Copy pathWorldUT.java
More file actions
156 lines (142 loc) · 4.37 KB
/
Copy pathWorldUT.java
File metadata and controls
156 lines (142 loc) · 4.37 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import org.junit.*;
import static org.junit.Assert.*;
public class WorldUT {
////////////////////
// TOSTRING TESTS //
////////////////////
// Tests that in a 10 * 10 world of 30 percent aliveness,
// 10 rows of cells with 10 cells in each row will be printed out
@Test
public void test_toString_interior_value()
{
World myWorld = new World(10, 5, 30);
String expectedValue = " 0123456789\n" +
"0 ...XXX..XX\n" +
"1 .X..X..XXX\n" +
"2 X.X..X..XX\n" +
"3 ...XX.....\n" +
"4 ..........\n" +
"5 XXX.XX.X..\n" +
"6 ..XX.....X\n" +
"7 ........X.\n" +
"8 .......X..\n" +
"9 .XXXX.X...\n";
assertEquals(expectedValue, myWorld.toString());
}
// Tests that in a 1*1 world of 20 percent aliveness,
// only one cell will be printed out
@Test
public void test_toString_world_size_one()
{
World myWorld = new World(1, 7, 20);
String expectedValue = " 0\n" +
"0 .\n";
assertEquals(expectedValue, myWorld.toString());
}
// Tests that in a 6*6 world of 0 percent aliveness,
// each cell will be printed out as "."
@Test
public void test_toString_zero_percent()
{
World myWorld = new World(6, 9, 0);
String expectedValue = " 012345\n" +
"0 ......\n" +
"1 ......\n" +
"2 ......\n" +
"3 ......\n" +
"4 ......\n" +
"5 ......\n";
assertEquals(expectedValue, myWorld.toString());
}
// Tests that in a 8*8 world of 100 percent aliveness,
// each cell will be printed out as "X"
@Test
public void test_toString_full_percent()
{
World myWorld = new World(8, 11, 100);
String expectedValue = " 01234567\n" +
"0 XXXXXXXX\n" +
"1 XXXXXXXX\n" +
"2 XXXXXXXX\n" +
"3 XXXXXXXX\n" +
"4 XXXXXXXX\n" +
"5 XXXXXXXX\n" +
"6 XXXXXXXX\n" +
"7 XXXXXXXX\n";
assertEquals(expectedValue, myWorld.toString());
}
// Tests that in a 0*0 world of 10 percent aliveness,
// an empty string will be printed out
@Test
public void tes_toString_world_size_zero()
{
World myWorld = new World(0, 19, 10);
String expectedValue = " \n";
assertEquals(expectedValue, myWorld.toString());
}
// Tests that passing in a negative number (invalid)
// for the aliveness percentage will result in an
// invalid World and so print out a null string
@Test
public void test_toString_negative_percent()
{
World myWorld = new World(0, 4, -17);
String expectedValue = null;
assertEquals(expectedValue, myWorld.toString());
}
///////////////////
// ITERATE TESTS //
///////////////////
// Tests that after iterating a 10*10 world of 30 percent
// aliveness, the new world coming out matches the expected world
@Test
public void test_iterate_world_size_ten()
{
World myWorld = new World(10, 5, 30);
String expectedWorld = " 0123456789\n" +
"0 .X....X..X\n" +
"1 .XX...XX..\n" +
"2 XXX..X.X..\n" +
"3 ...XX....X\n" +
"4 .XX..X....\n" +
"5 XXX.X.....\n" +
"6 X.XXX...XX\n" +
"7 ........X.\n" +
"8 ..XX...X..\n" +
"9 ..X...XXX.\n";
assertEquals(expectedWorld, myWorld.iterate().toString());
}
// Tests that after iterating a 0*0 world of 40 percent
// aliveness, the new world coming out matches the expected world
@Test
public void test_iterate_world_size_zero()
{
World myWorld = new World(0, 99, 40);
String expectedWorld = " \n";
assertEquals(expectedWorld, myWorld.iterate().toString());
}
// Tests that after iterating a 4*4 world of 100 percent
// aliveness, the new world coming out matches the expected world
@Test
public void test_iterate_world_full_percent()
{
World myWorld = new World(4, 1, 100);
String expectedWorld = " 0123\n" +
"0 ....\n" +
"1 ....\n" +
"2 ....\n" +
"3 ....\n";
assertEquals(expectedWorld, myWorld.iterate().toString());
}
// Tests that after iterating a 2*2 world of 0 percent
// aliveness, the new world coming out matches the expected world
@Test
public void test_iterate_world_zero_percent()
{
World myWorld = new World(2, 71, 0);
String expectedWorld = " 01\n" +
"0 ..\n" +
"1 ..\n";
assertEquals(expectedWorld, myWorld.iterate().toString());
}
}