def test_text_init(self): "Test the Monad object creation from text" # 1. Create Monad object from text myobj = monad.Monad(text=aoc_24.from_text(EXAMPLE_TEXT), inp=EXAMPLE_DIGITS) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 252) self.assertEqual(len(myobj.alu.inst), 252) self.assertEqual(len(myobj.constants), 3) self.assertEqual(len(myobj.constants[0]), 14) self.assertEqual(myobj.constants[0][0], 1) self.assertEqual(myobj.constants[1][0], 14) self.assertEqual(myobj.constants[2][0], 12) self.assertEqual(myobj.constants[0][7], 26) self.assertEqual(myobj.constants[1][7], -13) self.assertEqual(myobj.constants[2][7], 5) self.assertEqual(myobj.constants[0][13], 26) self.assertEqual(myobj.constants[1][13], -4) self.assertEqual(myobj.constants[2][13], 11) self.assertEqual(len(myobj.alu.inp), 14) self.assertEqual(myobj.alu.inp[0], 1) self.assertEqual(myobj.alu.inp[13], 9) # 3. Check methods result = myobj.alu.run() self.assertEqual(myobj.run(EXAMPLE_DIGITS), result) self.assertEqual(myobj.unrun(digits=monad.DIGITS), PART_ONE_RESULT) self.assertEqual(myobj.unrun(digits=monad.STIGID), PART_TWO_RESULT)
def test_part_two(self): "Test part two example of Monad object" # 1. Create Monad object from text myobj = monad.Monad(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_part_one(self): "Test part one example of Monad object" # 1. Create Monad object from text myobj = monad.Monad(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_empty_init(self): "Test the default Monad creation" # 1. Create default Monad object myobj = monad.Monad() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.alu, None)
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = monad.Monad(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