-
Notifications
You must be signed in to change notification settings - Fork 0
tests, small comments and modifications, and start of new strategy #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
.idea/vcs.xml | ||
.idea/workspace.xml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
"""Unit tests for C4Game.py""" | ||
|
||
import unittest | ||
from C4Game import * | ||
|
||
class TestC4Game(unittest.TestCase): | ||
|
||
def test_init(self): | ||
"""Tests for C4Game.__init__ (therefore includes some testing of C4Game.createBoard and Player class""" | ||
game = C4Game(2, 3, 2, 1, 0, "Maya", "Joey") | ||
# Tests basic attributes | ||
self.assertEqual(game.players, 2) | ||
self.assertEqual(game.boardWidth, 3) | ||
self.assertEqual(game.boardHeight, 2) | ||
self.assertEqual(game.winLength, 1) | ||
self.assertEqual(game.turn, 0) | ||
self.assertEqual(len(game.playerArray), game.players) | ||
# Tests that playerArray comes out as expected | ||
player0Exp = Player(0, "Maya") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Exp on the end of this variable name seems confusing, also would be better to Hard code the test values instead of running them through a Player constructor, just incase the error is int he Player constructor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah I see, but the Color comes from the Game, so maybe something like this makes more sense. and then reuse the testPXNames at the top too. But not a big deal :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain to me why naming the strings like that is better? :) |
||
player1Exp = Player(1, "Joey") | ||
self.assertEqual(game.playerArray[0].name, player0Exp.name) | ||
self.assertEqual(game.playerArray[0].color, player0Exp.color) | ||
self.assertEqual(game.playerArray[1].name, player1Exp.name) | ||
self.assertEqual(game.playerArray[1].color, player1Exp.color) | ||
# Tests that board comes out as expected | ||
boardExp = [['-','-','-'],['-','-','-']] | ||
self.assertEqual(game.board, boardExp) | ||
|
||
def test_play_turns(self): | ||
"""Tests that C4Game.play advances turns properly""" | ||
game = C4Game(2, 3, 4, 2, 0, "Joey", "Maya") | ||
self.assertEqual(game.turn, 0) | ||
game.play(1) | ||
self.assertEqual(game.turn, 1) | ||
game.play(2) | ||
self.assertEqual(game.turn, 0) | ||
game.play(1) | ||
self.assertEqual(game.turn, 1) | ||
game.play(3) | ||
self.assertEqual(game.turn, 0) | ||
|
||
def test_play(self): | ||
"""Tests that C4Game.play changes the board properly""" | ||
game = C4Game(2, 3, 4, 2, 0, "Maya", "Joey") | ||
b = colored('O', 'blue') | ||
r = colored('O', 'red') | ||
turn0Exp = [ | ||
['-','-','-'], | ||
['-','-','-'], | ||
['-','-','-'], | ||
['-','-','-'] | ||
] | ||
self.assertEqual(game.board, turn0Exp) | ||
game.play(1) | ||
turn1Exp = [ | ||
[b, '-', '-'], | ||
['-', '-', '-'], | ||
['-', '-', '-'], | ||
['-', '-', '-'] | ||
] | ||
self.assertEqual(game.board, turn1Exp) | ||
game.play(1) | ||
turn2Exp = [ | ||
[ b,'-','-'], | ||
[ r,'-','-'], | ||
['-','-','-'], | ||
['-','-','-'] | ||
] | ||
self.assertEqual(game.board, turn2Exp) | ||
game.play(2) | ||
turn3Exp = [ | ||
[b, b, '-'], | ||
[r, '-', '-'], | ||
['-', '-', '-'], | ||
['-', '-', '-'] | ||
] | ||
self.assertEqual(game.board, turn3Exp) | ||
game.play(3) | ||
turn4Exp = [ | ||
[ b, b, r], | ||
[ r,'-','-'], | ||
['-','-','-'], | ||
['-','-','-'] | ||
] | ||
self.assertEqual(game.board, turn4Exp) | ||
game.play(2) | ||
turn5Exp = [ | ||
[ b, b, r], | ||
[ r, b,'-'], | ||
['-','-','-'], | ||
['-','-','-'] | ||
] | ||
self.assertEqual(game.board, turn5Exp) | ||
game.play(1) | ||
turn6Exp = [ | ||
[b, b, r], | ||
[r, b, '-'], | ||
[r, '-', '-'], | ||
['-', '-', '-'] | ||
] | ||
self.assertEqual(game.board, turn6Exp) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
|
Uh oh!
There was an error while loading. Please reload this page.