def test_part_one(self):
        "Test part one example of Packets object"

        # 1. Create Packets object from text
        myobj = packets.Packets(text=aoc_16.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 Packets object"

        # 1. Create Packets object from text
        myobj = packets.Packets(part2=True,
                                text=aoc_16.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 Packets creation"

        # 1. Create default Packets object
        myobj = packets.Packets()

        # 2. Make sure it has the default values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(myobj.text, None)
    def test_examples_two(self):
        "Test the examples for part 2"

        # 1. Loop for all of the examples
        for example in EXAMPLES_TWO:

            # 2. Decode the packet
            myobj = packets.Packets(text=[example['text']], part2=True)

            # 3. Check the results
            self.assertEqual(myobj.packet.execute(), example['value'])
    def test_text_init(self):
        "Test the Packets object creation from text"

        # 1. Create Packets object from text
        myobj = packets.Packets(text=aoc_16.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 1)

        # 3. Check methods
        self.assertEqual(myobj.packet.versions(), [6])
    def test_examples(self):
        "Test the examples"

        # 1. Loop for all of the examples
        for example in EXAMPLES:

            # 2. Decode the packet
            myobj = packets.Packets(text=[example['text']])

            # 3. Check the results
            self.assertEqual(myobj.packet.length, example['length'])
            self.assertEqual(len(myobj.packet.packets), example['packets'])
            self.assertEqual(sum(myobj.packet.versions()), example['versions'])
Example #7
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the puzzle solver
    solver = packets.Packets(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