def test2x2SquareFullOfLiveCellsSurviveNewGeneration(self): resultBoard = """ # # # # """ self.board.setCellAlive(0, 0) self.board.setCellAlive(1, 0) self.board.setCellAlive(1, 1) self.board.setCellAlive(0, 1) self.assertEquals(Board.newFromStr(resultBoard, self.evManager), self.board) self.board.newGeneration() self.assertEquals(Board.newFromStr(resultBoard, self.evManager), self.board)
def testBlinkerPaternWithStrBoardAsResult(self): resultBoard = """ . . . . . . . . . . . # # # . . . . . . . . . . . """ self.board = Board.new(5, 5, self.evManager) self.board.setCellAlive(1, 2) self.board.setCellAlive(2, 2) self.board.setCellAlive(3, 2) self.board.newGeneration() self.assertTrue(Board.newFromStr(resultBoard, self.evManager) == self.board)
def testLiveCellWithFourNeighboursDies(self): resultBoard = """ . . . . . . . # . # . # . # # # """ startBoard = """ . . . . . . . # . # # # . . # . """ self.board = Board.newFromStr(startBoard, self.evManager) self.board.newGeneration() self.assertTrue(Board.newFromStr(resultBoard, self.evManager) == self.board)
def testFirstRuleAnyLiveCellDiesWithLessThanTwoNeighbors(self): resultBoard = """ . . . . . . . . . . . . . . . . . . . . . . . . . """ self.board = Board.new(5, 5, self.evManager) self.board.setCellAlive(1, 2) self.board.setCellAlive(3, 2) self.board.setCellAlive(0, 4) self.board.setCellAlive(4, 4) self.board.newGeneration() self.assertEquals(Board.newFromStr(resultBoard, self.evManager), self.board)
def testEquals2x2OnGeneration(self): strBoard1 = """ . # # # """ strBoard2 = """ # # # # """ board1 = Board.newFromStr(strBoard1, self.evManager) board1.newGeneration() board2 = Board.newFromStr(strBoard2, self.evManager) self.assertTrue(board1 == board2)
def testEquals(self): strBoard1 = """ . . . # """ strBoard2 = """ . # . # """ board1 = Board.newFromStr(strBoard1, self.evManager) board2 = Board.newFromStr(strBoard1, self.evManager) self.assertTrue(board1 == board2) board3 = Board.newFromStr(strBoard2, self.evManager) self.assertFalse(board1 == board3)
def testShouldBeAbleToDefineBoardWithString(self): strBoard = """ . . . . """ self.board = Board.newFromStr(strBoard, self.evManager) self.assertEquals(4, len(self.board.fields))
def test3x3SquareWith4Neighbors(self): self.board = Board.new(3, 3, self.evManager) self.board.setCellAlive(0, 0) self.board.setCellAlive(1, 1) self.board.setCellAlive(2, 1) self.board.setCellAlive(0, 1) self.board.setCellAlive(1, 2) self.assertEquals(4, self.board.getNumLiveNeighbours(1, 1))
def testShouldBeAbleToDetermineLiveCellsWithString(self): strBoard = """ . . . # """ self.board = Board.newFromStr(strBoard, self.evManager) self.assertEquals(4, len(self.board.fields)) self.assertTrue(self.board.isCellAlive(1, 1))
def testGetFieldIJ(self): self.board.setCellAlive(0, 0) self.board.setCellAlive(1, 0) strBoard = """ # . # . """ self.assertEquals(Board.newFromStr(strBoard, self.evManager), self.board)
def test4x4SquareWithe2LiveCellsBug(self): self.board = Board.new(4, 4, self.evManager) self.board.setCellAlive(1, 1) self.board.setCellAlive(2, 1) self.board.newGeneration() self.assertFalse(self.board.isCellAlive(1, 1)) self.assertFalse(self.board.isCellAlive(2, 1)) self.assertFalse(self.board.isCellAlive(1, 2)) self.assertFalse(self.board.isCellAlive(2, 2)) self.assertFalse(self.board.isCellAlive(0, 0)) self.assertFalse(self.board.isCellAlive(1, 0)) self.assertFalse(self.board.isCellAlive(2, 0)) self.assertFalse(self.board.isCellAlive(0, 2))
def startBlinkerPatternWithStrDefinition(self): strBoard = """ . . . . . . . # . . . . # . . . . # . . . . . . . """ self.board = Board.newFromStr(strBoard) self.board.setCellAlive(1, 2) self.board.setCellAlive(2, 2) self.board.setCellAlive(3, 2)
def testACellShouldKnowSelfPosition(self): self.board = Board.new(4, 4, self.evManager) self.assertEquals(1, self.board.getCell(0, 1).index)
def startBlinkerPattern(self): self.board = Board.new(5, 5, self.evManager) self.board.setCellAlive(1, 2) self.board.setCellAlive(2, 2) self.board.setCellAlive(3, 2)
def setUp(self): self.evManager = EventManager() self.board = Board.new(2, 2, self.evManager)