def test_1_marble_equals_0_or_2(self): odd_marble_options = [2,4] marble_set = MarbleSet(marble_options = odd_marble_options) marbles_not_1 = [x for x in marble_set.marbles if x in [2, 4] ] self.assertEqual(len(marbles_not_1), 1)
def test_shuffle_is_called(self): fake_shuffle = FakeShuffle() marble_set = MarbleSet(shuffle=fake_shuffle.shuffle) self.assertEqual(fake_shuffle.times_called, 1)
def setUp(self): self.marble_set = MarbleSet()
class MarbleSetTestCase(unittest.TestCase): def setUp(self): self.marble_set = MarbleSet() def test_has_12_marbles(self): self.assertEqual(len(self.marble_set.marbles), 12) def test_11_marbles_equal_to_1(self): marbles_equal_1 = [x for x in self.marble_set.marbles if x == 1] self.assertEqual(len(marbles_equal_1), 11) def test_1_marble_equals_0_or_2(self): odd_marble_options = [2,4] marble_set = MarbleSet(marble_options = odd_marble_options) marbles_not_1 = [x for x in marble_set.marbles if x in [2, 4] ] self.assertEqual(len(marbles_not_1), 1) def test_choice_is_called(self): fake_choice = FakeChoice() odd_marble_options = [2,4] marble_set = MarbleSet(marble_options=odd_marble_options, choice = fake_choice.choice) self.assertEqual(fake_choice.times_called, 1) def test_shuffle_is_called(self): fake_shuffle = FakeShuffle() marble_set = MarbleSet(shuffle=fake_shuffle.shuffle) self.assertEqual(fake_shuffle.times_called, 1) def test_shuffle_modifies_marbles(self): fake_shuffle = FakeShuffle() marble_set = MarbleSet(shuffle=fake_shuffle.shuffle) self.assertEqual(marble_set.marbles[0], 'foobar') def test_checkSolution_returns_true_if_index_and_is_heavier_are_correct(self): self.marble_set.marbles = [1 for x in range(12)] self.marble_set.marbles[5] = 2 self.assertTrue(self.marble_set.checkSolution([5, True])) self.marble_set.marbles = [1 for x in range(12)] self.marble_set.marbles[3] = 2 self.assertTrue(self.marble_set.checkSolution([3, True])) self.marble_set.marbles = [1 for x in range(12)] self.marble_set.marbles[8] = 2 self.assertTrue(self.marble_set.checkSolution([8, True])) self.marble_set.marbles = [1 for x in range(12)] self.marble_set.marbles[3] = 0 self.assertTrue(self.marble_set.checkSolution([3, False])) self.marble_set.marbles = [1 for x in range(12)] self.marble_set.marbles[9] = 0 self.assertTrue(self.marble_set.checkSolution([9, False]))
def test_solve_return_list_of_two_items(self): result = solve(MarbleSet(), BalanceScale()) self.assertEqual(len(result), 2)
def test_solve_returns_the_correct_solution(self): marble_set = MarbleSet() result = solve(marble_set, BalanceScale()) self.assertTrue(marble_set.checkSolution(result))
def test_shuffle_modifies_marbles(self): fake_shuffle = FakeShuffle() marbles_set = MarbleSet(shuffle=fake_shuffle.shuffle) self.assertEqual(marble_set.marbles[0], 'foobar')