示例#1
0
 def test_two_green_pegs_equal(self):
     peg_a = Peg("Green")
     peg_b = Peg("Green")
     self.assertEqual(
         peg_a,
         peg_b,
         msg=f"Two Green Pegs should be equal: {peg_a} {peg_b}")
示例#2
0
 def test_pegs_different_color_not_equal(self):
     peg_a = Peg("Green")
     peg_b = Peg("Blue")
     self.assertNotEqual(
         peg_a,
         peg_b,
         msg=f"Two Pegs of different color should be equal: {peg_a} {peg_b}"
     )
示例#3
0
 def test_guess_with_correct_color_and_position_returns_black_peg(self):
   # Black key peg is placed for each code peg from the guess which is correct in both color and position
   solution = [Peg("Blue"), Peg("Blue"), Peg("Pink"), Peg("Pink")]
   game = Game(solution)
   result, hint = game.make_guess([Peg("Green"), Peg("Green"), Peg("Green"), Peg("Pink")])
   self.assertEqual(hint, [None, None, None, Peg("Black")],
     msg=f'Answer with correct color and position should return black peg')
示例#4
0
 def test_correct_answer_fourth_try_wins(self):
   solution = [Peg("Green"), Peg("Blue"), Peg("Pink"), Peg("Yellow")]
   game = Game(solution)
   incorrect_guess = [Peg("Green"), Peg("Green"), Peg("Green"), Peg("Green")]
   for i in range(0, 3):
     result = game.make_guess(incorrect_guess)
   result, _ = game.make_guess(solution)
   self.assertEqual("Win!!!", result)
示例#5
0
 def test_peg_equals_itself(self):
     peg_a = Peg("Green")
     self.assertEqual(peg_a, peg_a, msg="Peg does not Equal itself")
     peg_a = Peg(1)
     self.assertEqual(peg_a, peg_a, msg="Peg does not Equal itself")
示例#6
0
 def test_peg_string_representation_is_readable(self):
     peg_a = Peg("Green")
     self.assertEqual("Green", str(peg_a))
     self.assertEqual("Blue", str(Peg("Blue")))
示例#7
0
 def test_guess_with_duplicate_colors_gives_hint(self):
   solution = [Peg("Blue"), Peg("Blue"), Peg("Pink"), Peg("Blue")]
   game = Game(solution)
   result, hint = game.make_guess([Peg("Blue"), Peg("Blue"), Peg("Blue"), Peg("Yellow")])
   self.assertEqual(hint, [Peg("Black"), Peg("Black"), Peg("White"), None])
示例#8
0
 def test_correct_answer_wins(self):
   guess = [Peg("Green"), Peg("Green"), Peg("Green"), Peg("Green")]
   result, _ = Game(guess).make_guess(guess)
   self.assertEqual("Win!!!", result)
示例#9
0
 def test_no_hint_when_guess_colors_exceed_solution(self):
   solution = [Peg("Blue"), Peg("Blue"), Peg("Pink"), Peg("Pink")]
   game = Game(solution)
   result, hint = game.make_guess([Peg("Blue"), Peg("Blue"), Peg("Blue"), Peg("Pink")])
   correct_hint = [Peg("Black"), Peg("Black"), None, Peg("Black")]
   self.assertEqual(hint, correct_hint, msg=f"Answer with more than correct color matches should not return white peg")
示例#10
0
 def test_guess_with_correct_color_returns_white_peg(self):
   solution = [Peg("Blue"), Peg("Blue"), Peg("Pink"), Peg("Pink")]
   game = Game(solution)
   result, hint = game.make_guess([Peg("Green"), Peg("Green"), Peg("Blue"), Peg("Green")])
   self.assertEqual(hint, [None, None, Peg("White"), None],
     msg=f'Answer with correct color should return white peg: {hint}')
示例#11
0
 def test_incorrect_answer_returns_hint(self):
   result, hint = Game().make_guess([Peg("Blue"), Peg("Blue"), Peg("Blue"), Peg("Pink")])
   self.assertIsNotNone(hint)
示例#12
0
 def test_fifteen_incorrect_guesses_is_loss(self):
   game = Game([Peg("Green"), Peg("Blue"), Peg("Pink"), Peg("Yellow")])
   incorrect_guess = [Peg("Green"), Peg("Green"), Peg("Green"), Peg("Green")]
   for i in range(0, 15):
     result, _ = game.make_guess(incorrect_guess)
   self.assertEqual("Loss, too many guesses", result)
示例#13
0
 def test_ten_incorrect_guesses_is_loss(self):
   game_two = Game([Peg("Green"), Peg("Blue"), Peg("Pink"), Peg("Yellow")])
   for i in range(0, 10):
     result, _ = game_two.make_guess([Peg("Green"), Peg("Green"), Peg("Green"), Peg("Green")])
   self.assertEqual("Loss, too many guesses", result)
示例#14
0
 def test_generate_random_answer(self):
   game_two = Game() # game without solution
   guess = [Peg("Green"), Peg("Green"), Peg("Blue"), Peg("Blue")]
   result, _ = game_two.make_guess(guess)
   self.assertNotEqual("Win!!!", result)
示例#15
0
 def test_incorrect_answer_does_not_win(self):
   game_one = Game([Peg("Green"), Peg("Green"), Peg("Blue"), Peg("Blue")])
   result, _ = game_one.make_guess([Peg("Green"), Peg("Green"), Peg("Green"), Peg("Green")])
   self.assertNotEqual("Win!!!", result)
示例#16
0
 def __init__(self, solution=None):
     self.classes = [Peg("Green"), Peg("Blue"), Peg("Pink"), Peg("Yellow")]
     self.hints = [Peg("Black"), Peg("White")]
     self.num_spaces = 4  # number of places/ spaces
     self.solution = solution if solution else self.__generate_solution()
     self.guesses = []