def test_part_one(self): "Test part one example of Recipes object" # 1. Create Recipes object from text myobj = recipes.Recipes(text=aoc_14.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
def test_part_two(self): "Test part two example of Recipes object" # 1. Create Recipes object from text myobj = recipes.Recipes(part2=True, text=aoc_14.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def test_text_init(self): "Test the Recipes object creation from text" # 1. Create Recipes object from text myobj = recipes.Recipes(text=aoc_14.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 1) self.assertEqual(myobj.scores, [3, 7]) self.assertEqual(myobj.elves, [0, 1]) self.assertEqual(myobj.after, 9)
def test_empty_init(self): "Test the default Recipes creation" # 1. Create default Recipes object myobj = recipes.Recipes() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.scores, [3, 7]) self.assertEqual(myobj.elves, [0, 1]) self.assertEqual(myobj.after, None)
def part_one(args, input_lines): "Process part one of the puzzle" # 1. Create the puzzle solver solver = recipes.Recipes(part2=False, text=input_lines) # 2. Determine the solution for part one solution = solver.part_one(verbose=args.verbose, limit=args.limit) if solution is None: print("There is no solution") else: print("The solution for part one is %s" % (solution)) # 3. Return result return solution is not None
def test_first_appears_by_parts(self): "Test the Recipes object first_appears" # 1. Check lengths of EXAMPLE DATA self.assertEqual(len(EXAMPLE_PART2_PARTS), len(EXAMPLE_PART2_AFTER)) # 2. Loop for the examples for index in range(len(EXAMPLE_PART2_PARTS)): # 3. Create Recipes object from text myobj = recipes.Recipes([EXAMPLE_PART2_PARTS[index]]) # 4. Checkout next 10 scores self.assertEqual(myobj.first_appears(EXAMPLE_PART2_PARTS[index]), EXAMPLE_PART2_AFTER[index])
def test_next_ten(self): "Test the Recipes object next_ten" # 1. Check lengths of EXAMPLE DATA self.assertEqual(len(EXAMPLE_AFTER), len(EXAMPLE_NXT10)) # 2. Loop for the examples for index in range(len(EXAMPLE_AFTER)): # 3. Create Recipes object from text myobj = recipes.Recipes(text=aoc_14.from_text(EXAMPLE_TEXT)) # 4. Checkout next 10 scores self.assertEqual(myobj.next_ten(EXAMPLE_AFTER[index]), EXAMPLE_NXT10[index])
def test_steps(self): "Test the Recipes object steps" # 1. Check lengths of EXAMPLE DATA self.assertEqual(len(EXAMPLE_LAST), len(EXAMPLE_ELF1)) self.assertEqual(len(EXAMPLE_LAST), len(EXAMPLE_ELF2)) # 2. Create Recipes object from text myobj = recipes.Recipes(text=aoc_14.from_text(EXAMPLE_TEXT)) # 3. Loop for several steps for step in range(len(EXAMPLE_LAST)): self.assertEqual(myobj.scores[-1], EXAMPLE_LAST[step]) self.assertEqual(myobj.elves[0], EXAMPLE_ELF1[step]) self.assertEqual(myobj.elves[1], EXAMPLE_ELF2[step]) myobj.step()