def test_part_two(self): "Test part two example of Conflagration object" # 1. Create Conflagration object from text myobj = conflagration.Conflagration( part2=True, text=aoc_23.from_text(PART_TWO_TEXT)) # 2. Make it easier for the slow method to complete inst = myobj.instructions[4] myobj.instructions[4] = (inst[0], inst[1], 1) inst = myobj.instructions[5] myobj.instructions[5] = (inst[0], inst[1], 0) inst = myobj.instructions[7] myobj.instructions[7] = (inst[0], inst[1], -10) # 2. Find the solution for numbers between 4 and 8 for number in range(2, 2): # 3. Set the instruction value inst = myobj.instructions[0] myobj.instructions[0] = (inst[0], inst[1], number) # 4. Reset the co-processor myobj.reset() # 5. Check the part two result self.assertEqual(myobj.part_two(verbose=False), myobj.part_two_slow(verbose=False))
def test_empty_init(self): "Test the default Conflagration creation" # 1. Create default Conflagration object myobj = conflagration.Conflagration() # 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.position, 0) self.assertEqual(len(myobj.registers), len(conflagration.REGS)) self.assertEqual(myobj.terminated, False) self.assertEqual(myobj.mul_knt, 0)
def test_text_init(self): "Test the Conflagration object creation from text" # 1. Create Conflagration object from text myobj = conflagration.Conflagration( text=aoc_23.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 32) self.assertEqual(len(myobj.instructions), 32) self.assertEqual(myobj.position, 0) self.assertEqual(len(myobj.registers), len(conflagration.REGS)) self.assertEqual(myobj.terminated, False) self.assertEqual(myobj.mul_knt, 0)
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = conflagration.Conflagration(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_part_one(self): "Test part one example of Conflagration object" # 1. Create Conflagration object from text myobj = conflagration.Conflagration( text=aoc_23.from_text(PART_ONE_TEXT)) # 2. Find the solution for numbers between 10 and 20 for number in range(10, 20): # 3. Set the instruction value inst_zero = myobj.instructions[0] myobj.instructions[0] = (inst_zero[0], inst_zero[1], number) # 4. Reset the co-processor myobj.reset() # 5. Check the part one result self.assertEqual(myobj.part_one(verbose=False), myobj.part_one_slow(verbose=False))