@@ -42,76 +42,79 @@ describe('ComputerStrategy COMPUTER IS X', function () {
42
42
43
43
it ( 'should be that X wins (1)' , function ( ) {
44
44
computer . start ( ) ;
45
- expect ( computerWon ) . toEqual ( false ) ;
46
- expect ( playerWon ) . toEqual ( false ) ;
47
-
48
- board . setTileXorO ( 0 , 2 , "O" ) ;
49
- expect ( computerWon ) . toEqual ( false ) ;
50
- expect ( playerWon ) . toEqual ( false ) ;
45
+ expect ( computerWon ) . toBeFalsy ( ) ;
46
+ expect ( playerWon ) . toBeFalsy ( ) ;
51
47
52
48
board . setTileXorO ( 1 , 2 , "O" ) ;
53
- expect ( computerWon ) . toEqual ( true ) ;
54
- expect ( playerWon ) . toEqual ( false ) ;
55
- expect ( wasDraw ) . toEqual ( false ) ;
49
+ expect ( computerWon ) . toBeFalsy ( ) ;
50
+ expect ( playerWon ) . toBeFalsy ( ) ;
51
+
52
+ board . setTileXorO ( 2 , 2 , "O" ) ;
53
+ expect ( computerWon ) . toBeFalsy ( ) ;
54
+ expect ( playerWon ) . toBeFalsy ( ) ;
55
+
56
+ board . setTileXorO ( 2 , 0 , "O" ) ;
57
+ expect ( computerWon ) . toBeTruthy ( ) ;
58
+ expect ( playerWon ) . toBeFalsy ( ) ;
56
59
} ) ;
57
60
58
61
it ( 'should be that X wins (2)' , function ( ) {
59
62
computer . start ( ) ;
60
- expect ( computerWon ) . toEqual ( false ) ;
61
- expect ( playerWon ) . toEqual ( false ) ;
63
+ expect ( computerWon ) . toBeFalsy ( ) ;
64
+ expect ( playerWon ) . toBeFalsy ( ) ;
62
65
63
66
board . setTileXorO ( 0 , 2 , "O" ) ;
64
- expect ( computerWon ) . toEqual ( false ) ;
65
- expect ( playerWon ) . toEqual ( false ) ;
66
-
67
- board . setTileXorO ( 2 , 2 , "O" ) ;
68
- expect ( computerWon ) . toEqual ( false ) ;
69
- expect ( playerWon ) . toEqual ( false ) ;
67
+ expect ( computerWon ) . toBeFalsy ( ) ;
68
+ expect ( playerWon ) . toBeFalsy ( ) ;
70
69
71
- board . setTileXorO ( 2 , 1 , "O" ) ;
72
- expect ( computerWon ) . toEqual ( true ) ;
73
- expect ( playerWon ) . toEqual ( false ) ;
70
+ board . setTileXorO ( 1 , 2 , "O" ) ;
71
+ expect ( computerWon ) . toBeTruthy ( ) ;
72
+ expect ( playerWon ) . toBeFalsy ( ) ;
74
73
} ) ;
75
74
76
75
it ( 'should be that we play to a draw (1)' , function ( ) {
77
76
computer . start ( ) ;
78
- expect ( computerWon ) . toEqual ( false ) ;
79
- expect ( playerWon ) . toEqual ( false ) ;
77
+ expect ( computerWon ) . toBeFalsy ( ) ;
78
+ expect ( playerWon ) . toBeFalsy ( ) ;
80
79
81
80
board . setTileXorO ( 1 , 1 , "O" ) ;
82
- expect ( computerWon ) . toEqual ( false ) ;
83
- expect ( playerWon ) . toEqual ( false ) ;
81
+ expect ( computerWon ) . toBeFalsy ( ) ;
82
+ expect ( playerWon ) . toBeFalsy ( ) ;
84
83
85
84
board . setTileXorO ( 0 , 1 , "O" ) ;
86
- expect ( computerWon ) . toEqual ( false ) ;
87
- expect ( playerWon ) . toEqual ( false ) ;
85
+ expect ( computerWon ) . toBeFalsy ( ) ;
86
+ expect ( playerWon ) . toBeFalsy ( ) ;
88
87
89
- board . setTileXorO ( 1 , 2 , "O" ) ;
90
- expect ( computerWon ) . toEqual ( false ) ;
91
- expect ( playerWon ) . toEqual ( false ) ;
88
+ board . setTileXorO ( 1 , 0 , "O" ) ;
89
+ expect ( computerWon ) . toBeFalsy ( ) ;
90
+ expect ( playerWon ) . toBeFalsy ( ) ;
92
91
93
- board . setTileXorO ( 2 , 0 , "O" ) ;
94
- expect ( computerWon ) . toEqual ( false ) ;
95
- expect ( playerWon ) . toEqual ( false ) ;
96
- expect ( wasDraw ) . toEqual ( true ) ;
92
+ board . setTileXorO ( 2 , 2 , "O" ) ;
93
+ expect ( computerWon ) . toBeFalsy ( ) ;
94
+ expect ( playerWon ) . toBeFalsy ( ) ;
95
+ expect ( wasDraw ) . toBeTruthy ( ) ;
97
96
} ) ;
98
97
99
98
it ( 'should be that we play to a draw (2)' , function ( ) {
100
99
computer . start ( ) ;
101
- expect ( computerWon ) . toEqual ( false ) ;
102
- expect ( playerWon ) . toEqual ( false ) ;
103
-
104
- board . setTileXorO ( 1 , 2 , "O" ) ;
105
- expect ( computerWon ) . toEqual ( false ) ;
106
- expect ( playerWon ) . toEqual ( false ) ;
100
+ expect ( computerWon ) . toBeFalsy ( ) ;
101
+ expect ( playerWon ) . toBeFalsy ( ) ;
107
102
108
103
board . setTileXorO ( 0 , 2 , "O" ) ;
109
- expect ( computerWon ) . toEqual ( false ) ;
110
- expect ( playerWon ) . toEqual ( false ) ;
104
+ expect ( computerWon ) . toBeFalsy ( ) ;
105
+ expect ( playerWon ) . toBeFalsy ( ) ;
111
106
112
- board . setTileXorO ( 2 , 0 , "O" ) ;
113
- expect ( computerWon ) . toEqual ( true ) ;
114
- expect ( playerWon ) . toEqual ( false ) ;
107
+ board . setTileXorO ( 2 , 2 , "O" ) ;
108
+ expect ( computerWon ) . toBeFalsy ( ) ;
109
+ expect ( playerWon ) . toBeFalsy ( ) ;
110
+
111
+ board . setTileXorO ( 1 , 0 , "O" ) ;
112
+ expect ( computerWon ) . toBeFalsy ( ) ;
113
+ expect ( playerWon ) . toBeFalsy ( ) ;
114
+
115
+ board . setTileXorO ( 2 , 1 , "O" ) ;
116
+ expect ( computerWon ) . toBeFalsy ( ) ;
117
+ expect ( playerWon ) . toBeFalsy ( ) ;
115
118
} ) ;
116
119
} ) ;
117
120
@@ -156,19 +159,68 @@ describe('ComputerStrategy COMPUTER IS O', function () {
156
159
expect ( playerWon ) . toBeUndefined ( ) ;
157
160
158
161
board . setTileXorO ( 0 , 0 , "X" ) ;
159
- expect ( computerWon ) . toEqual ( false ) ;
160
- expect ( playerWon ) . toEqual ( false ) ;
162
+ expect ( computerWon ) . toBeFalsy ( ) ;
163
+ expect ( playerWon ) . toBeFalsy ( ) ;
161
164
162
165
board . setTileXorO ( 0 , 2 , "X" ) ;
163
- expect ( computerWon ) . toEqual ( false ) ;
164
- expect ( playerWon ) . toEqual ( false ) ;
165
-
166
- board . setTileXorO ( 2 , 1 , "X" ) ;
167
- expect ( computerWon ) . toEqual ( false ) ;
168
- expect ( playerWon ) . toEqual ( false ) ;
166
+ expect ( computerWon ) . toBeFalsy ( ) ;
167
+ expect ( playerWon ) . toBeFalsy ( ) ;
169
168
170
169
board . setTileXorO ( 2 , 0 , "X" ) ;
171
- expect ( computerWon ) . toEqual ( true ) ;
172
- expect ( playerWon ) . toEqual ( false ) ;
170
+ expect ( computerWon ) . toBeTruthy ( ) ;
171
+ expect ( playerWon ) . toBeFalsy ( ) ;
172
+ } ) ;
173
+ } ) ;
174
+
175
+ describe ( 'ComputerStrategy COMPUTER IS X - Tests for tic-tac-toe-0001' , function ( ) {
176
+ var board = new TicTacToeBoard ( ) ;
177
+ var game = new TicTacToeGame ( board ) ;
178
+ var computerPlayer = new Player ( "COMPUTER" , "X" ) ;
179
+ var computer = new ComputerPlayer ( board , game , computerPlayer ) ;
180
+ var computerWon , playerWon , wasDraw ;
181
+
182
+ beforeEach ( function ( ) {
183
+ game . addListener ( function ( event ) {
184
+ computerWon = false ;
185
+ playerWon = false ;
186
+ wasDraw = false ;
187
+
188
+ if ( event . gamestate == TicTacToeGame . WE_HAVE_A_WINNER ) {
189
+ computerWon = event . winner == "X" ;
190
+ playerWon = event . winner == "O" ;
191
+ }
192
+ else if ( event . gamestate == TicTacToeGame . PLAYED_TO_A_DRAW ) {
193
+ wasDraw = true ;
194
+ }
195
+ } ) ;
196
+
197
+ game . addListener ( function ( event ) {
198
+ console . log ( event . toString ( ) ) ;
199
+ console . log ( event . board . toStringBoard ( ) ) ;
200
+ } )
201
+ } ) ;
202
+
203
+ afterEach ( function ( ) {
204
+ board . reset ( ) ;
205
+ game . reset ( ) ;
206
+ computer . reset ( computerPlayer ) ;
207
+ } ) ;
208
+
209
+ it ( 'should be that we play to a draw' , function ( ) {
210
+ computer . start ( ) ;
211
+
212
+ board . setTileXorO ( 1 , 2 , "O" ) ;
213
+ expect ( board . getTile ( 1 , 1 ) . player ) . toEqual ( "X" ) ;
214
+ expect ( computerWon ) . toBeFalsy ( ) ;
215
+ expect ( playerWon ) . toBeFalsy ( ) ;
216
+
217
+ board . setTileXorO ( 2 , 2 , "O" ) ;
218
+ expect ( computerWon ) . toBeFalsy ( ) ;
219
+ expect ( playerWon ) . toBeFalsy ( ) ;
220
+
221
+ board . setTileXorO ( 2 , 0 , "O" ) ;
222
+ expect ( computerWon ) . toBeTruthy ( ) ;
223
+ expect ( playerWon ) . toBeFalsy ( ) ;
224
+
173
225
} ) ;
174
226
} ) ;
0 commit comments