def test_text_init(self): """Test the generators object creation from text""" # 1. Create generators object from text mygens = generator.Generators(text=aoc_15.from_text(EXAMPLE_INPUT), part2=True) # 2. Make sure it has the default values self.assertEqual(mygens.part2, True) self.assertEqual(len(mygens.text), 2) self.assertEqual(mygens.judge, 16) self.assertEqual(mygens.modulo, 2**16) self.assertEqual(mygens.count, 0) self.assertEqual(len(mygens.generators), 2) # 3. Check generator A self.assertEqual(mygens['A'].factor, generator.FACTOR_A) self.assertEqual(mygens['A'].modulo, generator.MODULO) self.assertEqual(mygens['A'].start, START_A) self.assertEqual(mygens['A'].value, START_A) self.assertEqual(mygens['A'].count, 0) self.assertEqual(mygens['A'].name, 'A') self.assertEqual(mygens['A'].part2, True) self.assertEqual(mygens['A'].multiple, generator.MULTIPLE_A) # 4. Check generator B self.assertEqual(mygens['B'].factor, generator.FACTOR_B) self.assertEqual(mygens['B'].modulo, generator.MODULO) self.assertEqual(mygens['B'].start, START_B) self.assertEqual(mygens['B'].value, START_B) self.assertEqual(mygens['B'].count, 0) self.assertEqual(mygens['B'].name, 'B') self.assertEqual(mygens['B'].part2, True) self.assertEqual(mygens['B'].multiple, generator.MULTIPLE_B)
def test_part_one_judge_40m(self): """Test generators matches from example""" # 1. Create the generator object mygens = generator.Generators(text=aoc_15.from_text(EXAMPLE_INPUT)) # 2. Check the number of matches after six iterations self.assertEqual(mygens.part_one(verbose=False), EXAMPLE_JUDGE_40M)
def test_part_two_judge_5m(self): """Test generators matches from example""" # 1. Create the generator object mygens = generator.Generators(text=aoc_15.from_text(EXAMPLE_INPUT), part2=True) # 2. Check the number of matches after six iterations self.assertEqual(mygens.part_two(verbose=False), PART_TWO_JUDGE_5M)
def test_empty_init(self): """Test the generators creation""" # 1. Create default generators object mygens = generator.Generators() # 2. Make sure it has the default values self.assertEqual(mygens.part2, False) self.assertEqual(mygens.text, None) self.assertEqual(mygens.judge, 16) self.assertEqual(mygens.modulo, 2**16) self.assertEqual(mygens.count, 0) self.assertEqual(mygens.generators, {})
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = generator.Generators(part2=True, text=input_lines) # 2. Determine the judge's count solution = solver.part_two(verbose=args.verbose) if solution is None: print("There is no solution") else: print("After 5 million pairs, the judge's final count is %d" % (solution)) # 3. Return result return solution is not None
def test_part_one_values(self): """Test generators output from example""" # 1. Create the generator object mygens = generator.Generators(text=aoc_15.from_text(EXAMPLE_INPUT)) # 2. Loop for all of the example output rows for row in aoc_15.from_text(EXAMPLE_VALUES): if row[0] == '-': continue # 3. Get the expected values expected = [int(_) for _ in row.split()] # 4. Advance the generators mygens.next_values() # 5. Check the values self.assertEqual(expected[0], mygens['A'].value) self.assertEqual(expected[1], mygens['B'].value)