/
ReversiTester.java
114 lines (103 loc) · 2.96 KB
/
ReversiTester.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
import org.junit.*;
import static org.junit.Assert.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
/** this class tests the methods in Reversi
* @author Nate Celeste */
public class ReversiTester{
/** tests setPressedButton and getPressedButton */
@Test
public void testPressedButton(){
Reversi test = new Reversi();
test.setVisible(false);
JButton test1 = new JButton();
test.setPressedButton(test1);
assertEquals( test1, test.getPressedButton());
}
/** tests the setPressedButtonX and getPressedButtonX */
@Test
public void testPressedButtonX(){
Reversi test = new Reversi();
test.setVisible(false);
int test1 = 1;
test.setPressedButtonX(test1);
assertEquals(test1, test.getPressedButtonX());
}
/** tests the setPressedButtonY and getPressedButtonY */
@Test
public void testPressedButtonY(){
Reversi test = new Reversi();
test.setVisible(false);
int test1 = 1;
test.setPressedButtonY(test1);
assertEquals(test1, test.getPressedButtonY());
}
/** tests the setWhiteTurn and getWhiteTurn */
@Test
public void testWhiteTurn(){
Reversi test = new Reversi();
test.setVisible(false);
boolean test1 = true;
test.setWhiteTurn(test1);
assertEquals(test1, test.getWhiteTurn());
}
/** tests isLegalMove */
@Test
public void testIsLegalMove(){
Reversi test = new Reversi();
test.setVisible(false);
assertTrue(test.isLegalMove(3, 2)); // a legal starting move
assertFalse(test.isLegalMove(0,0)); // an illegal starting move
}
/** tests legalMoveExists */
@Test
public void testLegalMoveExists(){
Reversi test = new Reversi();
test.setVisible(false);
assertTrue(test.legalMoveExists());
}
/** tests reverseColor */
@Test
public void testReverseColor(){
Reversi test = new Reversi();
test.setVisible(false);
JButton test1 = new JButton();
test1.setBackground(Color.WHITE);
JButton test2 = new JButton();
test2.setBackground(Color.BLACK);
test.reverseColor(test1);
test.reverseColor(test2);
assertEquals(Color.BLACK, test1.getBackground());
assertEquals(Color.WHITE, test2.getBackground());
}
/** tests switchTurns */
@Test
public void testSwitchTurns(){
Reversi test = new Reversi();
test.setVisible(false);
test.setPressedButton(new JButton());
test.switchTurns();
assertTrue(test.getWhiteTurn());
test.switchTurns();
assertFalse(test.getWhiteTurn());
}
/** tests testBounds */
@Test
public void testTestBounds(){
Reversi test = new Reversi();
test.setVisible(false);
assertTrue(test.testBounds(4, 4));
assertFalse(test.testBounds(9,9));
}
/** test testXY */
@Test
public void testTestXY(){
Reversi test = new Reversi();
test.setVisible(false);
assertTrue(test.testXY(4, 4, Color.BLACK));
assertFalse(test.testXY(4, 4, Color.WHITE));
assertFalse(test.testXY(9, 9, Color.GREEN));
}
}