def test_constructor(): ''' test constructor''' cw = Check_Win(matrix) assert cw.matrix[5][5] == 0 and \ cw.matrix[1][2] == 0 and \ len(cw.matrix) == 7 and \ len(cw.matrix[5]) == 6 and \ len(cw.matrix[6]) == 6
def test_check_win_increasing_diaganol(): # initiate the disk objects cw = Check_Win(matrix) dk1 = Disk("test") dk2 = Disk("test") dk3 = Disk("test") dk4 = Disk("test") # test increasing diaganol by placing the disks cw.matrix[2][2] = dk1 cw.matrix[5][5] = dk2 cw.matrix[4][4] = dk3 cw.matrix[3][3] = dk4 # get result re = cw.check_win() assert len(cw.matrix) == 7 and \ len(cw.matrix[5]) == 6 and \ len(cw.matrix[6]) == 6 and \ cw.matrix[2][2] != 0 and \ matrix[5][5] != 0 and \ matrix[4][4] != 0 and \ matrix[3][3] != 0 and \ matrix[2][2].color == "test" and \ matrix[5][5].color == "test" and \ matrix[4][4].color == "test" and \ matrix[3][3].color == "test" and \ re == "test"
def test_check_win_horizontal(): # initiate disk objects cw = Check_Win(matrix) dk1 = Disk("test") dk2 = Disk("test") dk3 = Disk("test") dk4 = Disk("test") # test horizontal by placing the disks cw.matrix[3][5] = dk1 cw.matrix[4][5] = dk2 cw.matrix[5][5] = dk3 cw.matrix[6][5] = dk4 # get result re = cw.check_win() assert len(cw.matrix) == 7 and \ len(cw.matrix[5]) == 6 and \ len(cw.matrix[6]) == 6 and \ cw.matrix[3][5] != 0 and \ matrix[4][5] != 0 and \ matrix[5][5] != 0 and \ matrix[6][5] != 0 and \ matrix[3][5].color == "test" and \ matrix[4][5].color == "test" and \ matrix[5][5].color == "test" and \ matrix[6][5].color == "test" and \ re == "test"
def test_update(): # call check function cw = Check_Win(matrix) dk1 = Disk("test") dk2 = Disk("test") dk3 = Disk("test") dk4 = Disk("test") # test horizontal cw.matrix[3][5] = dk1 cw.matrix[4][5] = dk2 cw.matrix[5][5] = dk3 cw.matrix[6][5] = dk4 # check the returned result result = cw.check_win() assert result == "test"
def update(self): '''display disks in the current matrix and check winning status''' # display the disks in the list matrix for column in self.matrix: for disk in column: if disk != ZERO: disk.draw_me(disk.x, disk.y) # check tie if the matrix is full of disks if self.total_disk == COLUMN * ROW: fill(TEXT_FILL) textSize(TEXT_SIZE) text("TIE!", self.SPACE['w']/TWO - ONE_HUDR, self.SPACE['h']/TEN) # end loop noLoop() # check result's status result = Check_Win(self.matrix).check_win() # if human side win: if result == "R": fill(TEXT_FILL) textSize(TEXT_SIZE) text("YOU WIN!", self.SPACE['w']/TWO - ONE_HUDR, self.SPACE['h']/TEN) # trigger to update winner's score.txt self.winning = True # if machine side win: if result == "Y": fill(TEXT_FILL) textSize(TEXT_SIZE) text("MACHINE WIN! YOU LOSE!", self.SPACE['w']/FOUR - (ONE_HUDR + HALF_HUDR), self.SPACE['h']/TEN) # end loop noLoop()