-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vivek Dagar
committed
Apr 5, 2024
1 parent
c1d9b94
commit 9dafcb0
Showing
10 changed files
with
95 additions
and
32 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import unittest | ||
from tictacai.game import Game | ||
from tictacai.game import empty_cells, wins | ||
|
||
|
||
class TestGame(unittest.TestCase): | ||
def setUp(self): | ||
self.game = Game() | ||
|
||
def test_wins(self): | ||
# Test wins function | ||
state = [['X', ' ', ' '], ['O', 'X', 'O'], [' ', ' ', 'X']] | ||
self.assertTrue(wins(state, 'X')) | ||
self.assertFalse(wins(state, 'O')) | ||
|
||
def test_empty_cells(self): | ||
# Test empty_cells function | ||
state = [['X', ' ', ' '], ['O', 'X', 'O'], [' ', ' ', 'X']] | ||
self.assertEqual(empty_cells(state), [[0, 1], [0, 2], [2, 0], [2, 1]]) | ||
|
||
def test_evaluate(self): | ||
# Test evaluate function | ||
state1 = [['X', 'X', 'X'], [' ', 'O', 'O'], [' ', ' ', ' ']] | ||
state2 = [['O', 'O', 'O'], [' ', 'X', 'X'], [' ', ' ', ' ']] | ||
state3 = [['X', 'O', 'X'], [' ', 'O', 'X'], [' ', 'X', 'O']] | ||
self.assertEqual(self.game.evaluate(state1), -1) # X wins | ||
self.assertEqual(self.game.evaluate(state2), 1) # O winner | ||
self.assertEqual(self.game.evaluate(state3), 0) # No winner | ||
|
||
def test_game_over(self): | ||
# Test game_over function | ||
state1 = [['X', 'X', 'X'], [' ', 'O', 'O'], [' ', ' ', ' ']] | ||
state2 = [['O', 'O', ' '], ['X', 'X', 'X'], [' ', ' ', ' ']] | ||
state3 = [['X', 'O', 'X'], [' ', 'O', 'X'], [' ', 'X', 'O']] | ||
self.assertTrue(self.game.game_over(state1)) # X wins | ||
self.assertTrue(self.game.game_over(state2)) # X wins | ||
self.assertFalse(self.game.game_over(state3)) # No winner | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |