Last active
December 6, 2018 09:10
-
-
Save mackwic/668cfa64c191f61e8407ad000fb3cb89 to your computer and use it in GitHub Desktop.
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
import unittest | |
YELLOW = 1 | |
RED =2 | |
EMPTY =0 | |
COL = 7 | |
ROW = 6 | |
class Board: | |
def __init__(self): | |
self.state = [] | |
for i in range(COL): | |
self.state.append([]) | |
def get_state(self): | |
return self.state | |
def add_chip(self,col,color): | |
self.state[col].append(color) | |
def convert_state_to_string(self): | |
for i in range(COL): | |
for j in range(ROW): | |
self.state[j][i] = str(self.state[j][i]) | |
class TestBoard(unittest.TestCase): | |
def test_get_initial_state(self): | |
# given | |
board = Board() | |
# when | |
state = board.get_state() | |
# then | |
self.assertEqual(state, [[], [], [], [], [], [], []]) | |
def test_get_state(self): | |
# given | |
board = Board() | |
col = 0 | |
color = YELLOW | |
#action | |
board.add_chip(col, color) | |
state = board.get_state() | |
#assertion | |
self.assertAlmostEqual(state[0][0], YELLOW) | |
def test_board_to_string(self): | |
# given | |
board = Board() | |
#when | |
for i in range(COL): | |
board.add_chip(i, RED) | |
board.convert_state_to_string1() | |
state = board.get_state() | |
#then | |
for i in | |
self.assertIsInstance() | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment