-
Notifications
You must be signed in to change notification settings - Fork 1
/
LifeBoardTest.java
143 lines (108 loc) · 3.65 KB
/
LifeBoardTest.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
139
140
141
142
//import static org.junit.Assert.*;
//import org.junit.After;
//import org.junit.Before;
//import org.junit.Test;
/**
* The test class LifeBoardTest.
*
* @author (Mike Roam)
* @version (a version number or a date)
*/
public class LifeBoardTest extends junit.framework.TestCase
{
/**
* Default constructor for test class LifeBoardTest
*/
public LifeBoardTest()
{
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
//@Before
public void setUp()
{
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
//@After
public void tearDown()
{
}
public void test1()
{
LifeBoard lifeBoard10x10 = new LifeBoard(10, 10, new OurRules(),true);
}
public void testInstantiate()
{
LifeBoard lifeBoar1 = new LifeBoard(2, 3, new OurRules(),true);
assertEquals(false, lifeBoar1.equals(null));
assertEquals(2, lifeBoar1.getCellsAcross());
assertEquals(3, lifeBoar1.getCellsDown());
}
//@Test
public void testBoardsize()
{
LifeBoard lifeBoar1 = new LifeBoard(2, 3, new OurRules(),true);
assertEquals(false, lifeBoar1.badGridLoc(new java.awt.Point(0,1)));
assertEquals(false, lifeBoar1.badGridLoc(new java.awt.Point(0,0)));
assertEquals(true, lifeBoar1.badGridLoc(new java.awt.Point(-1,1)));
assertEquals(true, lifeBoar1.badGridLoc(new java.awt.Point(1,-1)));
assertEquals(true, lifeBoar1.badGridLoc(new java.awt.Point(1,3)));
}
public void testInstance0()
{
LifeBoard lifeBoar1 = new LifeBoard(0, 0, new OurRules(),true);
assertEquals(false, lifeBoar1==null);
assertEquals(true, lifeBoar1.badGridLoc(new java.awt.Point(0,1)));
assertEquals(true, lifeBoar1.badGridLoc(new java.awt.Point(0,0)));
assertEquals(true, lifeBoar1.badGridLoc(new java.awt.Point(-1,1)));
assertEquals(true, lifeBoar1.badGridLoc(new java.awt.Point(1,-1)));
assertEquals(true, lifeBoar1.badGridLoc(new java.awt.Point(1,3)));
}
public void test1a()
{
LifeBoard lifeBoar1 = new LifeBoard(2, 3, new OurRules(),true);
assertEquals(2, lifeBoar1.getCellsAcross());
assertEquals(3, lifeBoar1.getCellsDown());
}
public void testNegativeBoardSize()
{
// oops, brutal: perhaps do try catch
String errStr=null;
try{
new LifeBoard(1,-7, new OurRules(),true);
}catch(java.lang.ArrayIndexOutOfBoundsException e){
errStr=e.toString();
}
assertEquals(true, errStr!=null);
errStr=null;
try{
new LifeBoard(-3,4, new OurRules(),true);
}catch(java.lang.ArrayIndexOutOfBoundsException e){
errStr=e.toString();
}
assertEquals(true, errStr!=null);
}
public void testAutumn() // may not work with rules
{
LifeBoard lifeBoar1 = new LifeBoard(4, 4, new OurRules(),false);
assertEquals(0, lifeBoar1.getCellData(new java.awt.Point(1,1)));
}
public void testCellDataSetGetAndNeighborCount() // may not work with rules
{
LifeBoard lifeBoar1 = new LifeBoard(2, 3, new OurRules(),false);
lifeBoar1.setCellData(new java.awt.Point(1,2), 1);
assertEquals(1, lifeBoar1.getCellData(new java.awt.Point(1,2)));
assertEquals(0, lifeBoar1.neighborCount(1, 2));
assertEquals(0, lifeBoar1.getCellData(new java.awt.Point(1,1)));
lifeBoar1.getCellsAcross();
lifeBoar1.getCellsDown();
}
}
// class LifeBoardTest