Exemplo n.º 1
0
 def test_symmetry(self):
     """
     Check that calculated key is symmetric in code/guess - 2x5 times on random code and guess in 2 dims
     """
     dims = [[2, 3], [4, 6]]
     for dim in dims:
         for times in range(5):
             code = mami.make_code(*dim)
             guess = mami.make_code(*dim)
             self.assertEqual(mami.calculate_key(code, guess),
                              mami.calculate_key(guess, code))
Exemplo n.º 2
0
 def test_valid_key(self):
     """
     Check the calculated key is a valid key - 10 times on random code and guess in standard game
     """
     dim = [4, 6]
     for times in range(10):
         key = mami.calculate_key(mami.make_code(*dim),
                                  mami.make_code(*dim))
         self.assertEqual(type(key[0]), int)
         self.assertEqual(type(key[1]), int)
         self.assertFalse(key[0] == dim[0] - 1 and key[1] == 1)
         self.assertTrue(key[0] + key[1] <= dim[0])
         self.assertTrue(key[0] >= 0)
         self.assertTrue(key[1] >= 0)
Exemplo n.º 3
0
 def test_number_of_pegs(self):
     """
     Check that the returned random code has the correct number of entries (pegs)
     """
     test_dims = [[4, 6], [5, 7], [1, 1]]
     for test_dim in test_dims:
         self.assertEqual(len(mami.make_code(*test_dim)), test_dim[0],
                          'Wrong number of pegs in code')
Exemplo n.º 4
0
 def test_number_of_colors(self):
     """
     Check that the returned random code has the correct number of colors
     """
     test_dims = [[4, 6], [5, 7], [1, 1]]
     for test_dim in test_dims:
         self.assertTrue(
             max(mami.make_code(*test_dim)) < test_dim[1],
             'Too high color number in code')
Exemplo n.º 5
0
def game():
    pegs = int(input("Type the number of pegs: "))
    colors = int(input("Type the number of colors: "))
    code = make_code(pegs, colors)
    black = 0
    guesses = []
    keys = []
    while black < pegs:
        guess = get_guess(pegs, colors)
        print("Your guesses:")
        for index in range(len(guesses)):  # print previous guesses and keys
            print("Guess: {} (black pegs: {}, white pegs: {})".format(
                guesses[index], *keys[index]))
        guesses.append(guess)
        black, white = calculate_key(code, guess)
        keys.append([black, white])
        if black == pegs:
            print("Correct! You guessed that it was {} in {} attempts.".format(
                code, len(guesses)))
        else:
            print("Guess: {} (black pegs: {}, white pegs: {})".format(
                guess, black, white))
Exemplo n.º 6
0
 def setUp(self):
     self.randomcode = mami.make_code()