def test_text_init(self): "Test the Reindeer object creation from text" # 1. Create Reindeer object from text myobj = reindeer.Reindeer(text=aoc_24.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 6) self.assertEqual(len(myobj.armies), 2) self.assertEqual(myobj.armies[0].name, 'Immune System') self.assertEqual(myobj.armies[1].name, 'Infection') self.assertEqual(len(myobj.armies[0].groups), 2) self.assertEqual(len(myobj.armies[1].groups), 2) self.assertEqual(myobj.armies[0].groups[0].number, 17) self.assertEqual(myobj.armies[0].groups[1].number, 989) self.assertEqual(myobj.armies[1].groups[0].number, 801) self.assertEqual(myobj.armies[1].groups[1].number, 4485) # 3. Check str() self.assertEqual(str(myobj), EXAMPLE_STR.strip()) # 4. Fight one round myobj.round() self.assertEqual(str(myobj), AFTER_ONE_ROUND.strip()) # 5. And then a couple more result = myobj.fight() self.assertEqual(result, PART_ONE_RESULT) # 6. Give the raindeer a boast myobj.boast(1570) result = myobj.fight() self.assertEqual(result, PART_TWO_RESULT)
def test_part_one(self): "Test part one example of Reindeer object" # 1. Create Reindeer object from text myobj = reindeer.Reindeer(text=aoc_24.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 Reindeer object" # 1. Create Reindeer object from text myobj = reindeer.Reindeer(part2=True, text=aoc_24.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def test_empty_init(self): "Test the default Reindeer creation" # 1. Create default Reindeer object myobj = reindeer.Reindeer() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.armies, [])
def __init__(self, text=None, part2=False): # 1. Set the initial values self.part2 = part2 self.text = text self.reindeer = {} # 2. Process text (if any) if text is not None and len(text) > 0: for line in self.text: new_deer = reindeer.Reindeer(text=line, part2=self.part2) self.reindeer[new_deer.name] = new_deer
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = reindeer.Reindeer(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_text_init(self): "Test the Reindeer object creation from text" # 1. Create Reindeer object from text myobj = reindeer.Reindeer(text=EXAMPLE_TEXT) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 73) self.assertEqual(myobj.name, "Comet") self.assertEqual(myobj.speed, 14) self.assertEqual(myobj.active, 10) self.assertEqual(myobj.passive, 127) self.assertEqual(myobj.flying, False) self.assertEqual(myobj.until, 0) self.assertEqual(myobj.points, 0) self.assertEqual(myobj.time, 0)
def test_empty_init(self): "Test the default Reindeer creation" # 1. Create default Reindeer object myobj = reindeer.Reindeer() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.name, "") self.assertEqual(myobj.speed, 0) self.assertEqual(myobj.active, 0) self.assertEqual(myobj.passive, 0) self.assertEqual(myobj.flying, False) self.assertEqual(myobj.until, 0) self.assertEqual(myobj.distance, 0) self.assertEqual(myobj.points, 0) self.assertEqual(myobj.time, 0)