def test_text_init(self): "Test the Taxicab object creation from text" # 1. Create Taxicab object from text myobj = taxicab.Taxicab(text=aoc_01.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.instructions, ['R2', 'L3']) self.assertEqual(myobj.location, [0, 0]) self.assertEqual(myobj.facing, "N") # 3. Check methods self.assertEqual(myobj.from_start(), 0) myobj.follow_instructions() self.assertEqual(myobj.location, [2, 3]) self.assertEqual(myobj.facing, "N") self.assertEqual(myobj.from_start(), 5) # 4. Example 2 myobj = taxicab.Taxicab(text=aoc_01.from_text(EXAMPLE_TWO)) myobj.follow_instructions() self.assertEqual(myobj.from_start(), 2) self.assertEqual(myobj.location, [0, -2]) # 5. Example 3 myobj = taxicab.Taxicab(text=aoc_01.from_text(EXAMPLE_THREE)) myobj.follow_instructions() self.assertEqual(myobj.from_start(), 12) # 6. Example 4 myobj = taxicab.Taxicab(text=aoc_01.from_text(EXAMPLE_FOUR)) myobj.find_hq() self.assertEqual(myobj.from_start(), 4)
def test_part_one(self): "Test part one example of Taxicab object" # 1. Create Taxicab object from text myobj = taxicab.Taxicab(text=aoc_01.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 Taxicab object" # 1. Create Taxicab object from text myobj = taxicab.Taxicab(part2=True, text=aoc_01.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = taxicab.Taxicab(part2=True, text=input_lines) # 2. Determine the solution for part two solution = solver.part_two(verbose=args.verbose, limit=args.limit) if solution is None: print("There is no solution") else: print("The solution for part two is %s" % (solution)) # 3. Return result return solution is not None
def test_empty_init(self): "Test the default Taxicab creation" # 1. Create default Taxicab object myobj = taxicab.Taxicab() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.instructions, []) self.assertEqual(myobj.location, [0, 0]) self.assertEqual(myobj.facing, "N") # 3. Check methods self.assertEqual(myobj.from_start(), 0) myobj.follow_instructions() self.assertEqual(myobj.from_start(), 0)