Esempio n. 1
0
    def test_new(self):
        # default flip_count
        puzzle = new()
        self.assertIsInstance(puzzle, Puzzle)
        self.assertEqual((len(puzzle.deck), puzzle.flip_count), (52, 4))
        self.assertEqual(Counter(puzzle.deck)[FaceUp], 4)

        # custom flip_count
        puzzle = new(flip_count=10)
        self.assertEqual((len(puzzle.deck), puzzle.flip_count), (52, 10))
        self.assertEqual(Counter(puzzle.deck)[FaceUp], 10)

        # flip_count >= 52 -> 51
        puzzle = new(flip_count=100)
        self.assertEqual((len(puzzle.deck), puzzle.flip_count), (52, 51))
        self.assertEqual(Counter(puzzle.deck)[FaceUp], 51)

        # flip_count <= 1 -> abs(flip_count)
        puzzle = new(flip_count=-10)
        self.assertEqual((len(puzzle.deck), puzzle.flip_count), (52, 10))
        self.assertEqual(Counter(puzzle.deck)[FaceUp], 10)

        # flip_count == 0 -> 1
        puzzle = new(flip_count=0)
        self.assertEqual((len(puzzle.deck), puzzle.flip_count), (52, 1))
        self.assertEqual(Counter(puzzle.deck)[FaceUp], 1)
Esempio n. 2
0
 def test_solve(self):
     # solve for all allowed flip_count values
     for flip_count in range(1, 52):
         puzzle = new(flip_count)
         stack_one, stack_two = solve(puzzle)
         self.assertEqual(Counter(stack_one)[FaceUp], Counter(stack_two)[FaceUp])