コード例 #1
0
    def test_invalid_move_piece(self):
        from towers import Tower, Rod, Piece, TowerError

        tower = Tower()
        tower.rods = [Rod() for i in range(3)]

        tower.rods[0].pieces = [Piece(3 - i) for i in range(3)]
        tower.rods[1].pieces = [Piece(4)]

        with self.assertRaises(TowerError):
            tower.move_piece(1, 0)
コード例 #2
0
    def test_get_biggest_size(self):
        from towers import Tower, Rod, Piece
        from towersvisualizer import Visualizer

        tower = Tower()
        tower.rods = [Rod() for i in range(3)]
        tower.rods[1].pieces = [Piece(2), Piece(1)]
        tower.rods[2].pieces = [Piece(3)]

        visualizer = Visualizer(tower)

        self.assertEqual(visualizer._get_biggest_size(), 3)
コード例 #3
0
    def test_move_piece(self):
        from towers import Tower, Rod, Piece

        tower = Tower()
        tower.rods = [Rod() for i in range(3)]

        tower.rods[0].pieces = [Piece(3 - i) for i in range(3)]

        tower.move_piece(0, 2)
        self.assertEqual(len(tower.rods[0].pieces), 2)
        self.assertEqual(len(tower.rods[2].pieces), 1)

        tower.move_piece(2, 0)
        self.assertEqual(len(tower.rods[0].pieces), 3)
        self.assertEqual(len(tower.rods[2].pieces), 0)