예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
 def testLiveCellWithFourNeighboursDies(self):
     resultBoard = """
                 . . . . 
                 . . . # 
                 . # . # 
                 . # # # 
               """
     startBoard = """
                 . . . . 
                 . . . # 
                 . # # # 
                 . . # . 
               """
     self.board = Board.newFromStr(startBoard, self.evManager)
     self.board.newGeneration()
     self.assertTrue(Board.newFromStr(resultBoard, self.evManager) == self.board)
예제 #4
0
 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)
예제 #5
0
 def testEquals2x2OnGeneration(self):
     strBoard1 = """
                 . #
                 # #
             
                 """
     
     strBoard2 = """
                 # #
                 # #
             
                 """
     
     board1 = Board.newFromStr(strBoard1, self.evManager)
     board1.newGeneration()
     board2 = Board.newFromStr(strBoard2, self.evManager)
     self.assertTrue(board1 == board2)
예제 #6
0
 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)
예제 #7
0
 def testShouldBeAbleToDefineBoardWithString(self):
     strBoard = """
                 . .
                 . .
             
                 """
     self.board = Board.newFromStr(strBoard, self.evManager)
     self.assertEquals(4, len(self.board.fields))
예제 #8
0
 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))
예제 #9
0
 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))
예제 #10
0
 def testGetFieldIJ(self):
     self.board.setCellAlive(0, 0)    
     self.board.setCellAlive(1, 0)   
     
     strBoard = """
                 # .
                 # .
             
                 """
     self.assertEquals(Board.newFromStr(strBoard, self.evManager), self.board)
예제 #11
0
 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))
예제 #12
0
 def startBlinkerPatternWithStrDefinition(self):
     strBoard = """
                 . . . . .
                 . . # . .
                 . . # . .
                 . . # . .
                 . . . . .
             
                 """
     self.board = Board.newFromStr(strBoard)
     self.board.setCellAlive(1, 2)
     self.board.setCellAlive(2, 2)
     self.board.setCellAlive(3, 2)
예제 #13
0
 def testACellShouldKnowSelfPosition(self):
     self.board = Board.new(4, 4, self.evManager)
     self.assertEquals(1, self.board.getCell(0, 1).index)
예제 #14
0
 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)
예제 #15
0
 def setUp(self):
     self.evManager = EventManager()
     self.board = Board.new(2, 2, self.evManager)