Beispiel #1
0
    def testWritesCurrentData(self):
        location = MockSquare(x=1, y=1, has_nbrs=True)
        out = MockFile()

        knight = tour.Knight(location=location, initial_rule=self.rule)
        knight.write_current_data(out)

        self.assertEquals("{'square':(1,1), 'tiebreak':False}", out.s)

        location = MockSquare(x=2, y=2, has_nbrs=True)
        out = MockFile()

        knight = tour.Knight(location=location, initial_rule=self.rule)
        knight.write_current_data(out)

        self.assertEquals("{'square':(2,2), 'tiebreak':False}", out.s)
Beispiel #2
0
    def testMoveInvokesRuleOnCurrentSquare(self):
        location = MockSquare(x=1, y=1, has_nbrs=True)
        out = MockFile()

        knight = tour.Knight(location=location, initial_rule=self.rule)
        knight.move()
        knight.write_current_data(out)

        self.assertEquals(location, self.rule.invoked_on)
Beispiel #3
0
    def testMoveUpdatesTiebreak(self):
        location = MockSquare(x=1, y=1, has_nbrs=True)
        square33 = MockSquare(x=3, y=3, has_nbrs=True)
        rule2 = MockRule(new_location=square33, tiebreak=True)
        knight = tour.Knight(location=location, initial_rule=rule2)

        out = MockFile()
        knight.move()
        knight.write_current_data(out)
        self.assertEquals("{'square':(3,3), 'tiebreak':True}", out.s)
Beispiel #4
0
    def testMoveUpdatesRule(self):
        location = MockSquare(x=1, y=1, has_nbrs=True)
        square41 = MockSquare(x=4, y=1, has_nbrs=True)
        rule2 = MockRule(new_location=square41, tiebreak=False)
        rule2.next_rule = rule2
        knight = tour.Knight(location=location, initial_rule=rule2)

        out = MockFile()
        knight.move()
        knight.write_current_data(out)
        self.assertEquals("{'square':(4,1), 'tiebreak':False}", out.s)

        rule2.next_rule = self.rule
        out = MockFile()
        knight.move()
        knight.write_current_data(out)
        self.assertEquals("{'square':(2,1), 'tiebreak':False}", out.s)

        out = MockFile()
        knight.move()
        knight.write_current_data(out)
        self.assertEquals("{'square':(2,1), 'tiebreak':False}", out.s)
Beispiel #5
0
 def testMoveMarksSquareVisited(self):
     location = MockSquare(x=1, y=1, has_nbrs=True)
     knight = tour.Knight(location=location, initial_rule=self.rule)
     knight.move()
     self.assertTrue(self.square21.visited)
Beispiel #6
0
 def testMovesWhenPossible(self):
     location = MockSquare(x=1, y=1, has_nbrs=True)
     knight = tour.Knight(location=location, initial_rule=self.rule)
     self.assertTrue(knight.move())
Beispiel #7
0
 def testMoveReturnsFalseIfDone(self):
     location = MockSquare(x=1, y=1, has_nbrs=False)
     knight = tour.Knight(location=location, initial_rule=self.rule)
     self.assertFalse(knight.move())