Пример #1
0
    def test_part_two(self):
        "Test part two example of Homework object"

        # 1. Create Homework object from text
        myobj = homework.Homework(part2=True, text=aoc_18.from_text(PART_TWO_TEXT))

        # 2. Check the part two result
        self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
Пример #2
0
    def test_part_one(self):
        "Test part one example of Homework object"

        # 1. Create Homework object from text
        myobj = homework.Homework(text=aoc_18.from_text(PART_ONE_TEXT))

        # 2. Check the part one result
        self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
Пример #3
0
    def test_text_init(self):
        "Test the Homework object creation from text"

        # 1. Create Homework object from text
        myobj = homework.Homework(text=aoc_18.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 4)
Пример #4
0
    def test_empty_init(self):
        "Test the default Homework creation"

        # 1. Create default Homework object
        myobj = homework.Homework()

        # 2. Make sure it has the default values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(myobj.text, None)
Пример #5
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the puzzle solver
    solver = homework.Homework(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
Пример #6
0
    def test_text_init_one(self):
        "Test the Homework object creation from text"

        # 1. Create Homework object from text
        myobj = homework.Homework(text=aoc_18.from_text(EXAMPLE_ONE))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 10)
        self.assertEqual(len(myobj.pairs), 10)
        self.assertEqual(myobj.sumation, [])

        # 3. Check addition
        myobj.sum_them_up()
        self.assertEqual(
            str(myobj.sumation),
            "[[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]]")
        self.assertEqual(myobj.sumation.magnitude(), 3488)