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)
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)
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)
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)
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)
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())
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())