Exemplo n.º 1
0
    def test_text_init(self):
        "Test the Polymer object creation from text"

        # 1. Create Polymer object from text
        myobj = polymer.Polymer(text=aoc_14.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 17)
        self.assertEqual(myobj.template, 'NNCB')
        self.assertEqual(len(myobj.rules), 16)

        # 3. Check methods
        self.assertEqual(myobj.element_diff('NNCB'), 2 - 1)
        self.assertEqual(
            myobj.element_diff(
                'NBBNBNBBCCNBCNCCNBBNBBNBBBNBBNBBCBHCBHHNHCBBCBHCB'), 23 - 5)

        self.assertEqual(myobj.expand_once('NNCB'), 'NCNBCHB')
        self.assertEqual(myobj.expand_once('NCNBCHB'), 'NBCCNBBBCBHCB')
        self.assertEqual(myobj.expand_once('NBCCNBBBCBHCB'),
                         'NBBBCNCCNBBNBNBBCHBHHBCHB')
        self.assertEqual(myobj.expand_once('NBBBCNCCNBBNBNBBCHBHHBCHB'),
                         'NBBNBNBBCCNBCNCCNBBNBBNBBBNBBNBBCBHCBHHNHCBBCBHCB')

        self.assertEqual(myobj.expand_template(4),
                         'NBBNBNBBCCNBCNCCNBBNBBNBBBNBBNBBCBHCBHHNHCBBCBHCB')

        self.assertEqual(len(myobj.expand_template(5)), 97)
        self.assertEqual(myobj.element_diff((myobj.expand_template(10))), 1588)
Exemplo n.º 2
0
    def test_part_one(self):
        "Test part one example of Bitmask object"

        # 1. Create Bitmask object from text
        myobj = bitmask.Bitmask(text=aoc_14.from_text(PART_ONE_TEXT))

        # 2. Check the part one result
        self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
Exemplo n.º 3
0
    def test_part_two(self):
        "Test part two example of Bitmask object"

        # 1. Create Bitmask object from text
        myobj = bitmask.Bitmask(part2=True,
                                text=aoc_14.from_text(PART_TWO_TEXT))

        # 2. Check the part two result
        self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
Exemplo n.º 4
0
    def test_part_one(self):
        "Test part one example of Olympics object"

        # 1. Create Olympics object from text
        myobj = olympics.Olympics(text=aoc_14.from_text(PART_ONE_TEXT))

        # 2. Check the part one result
        self.assertEqual(
            myobj.part_one(verbose=False, race_time=EXAMPLE_RACE_TIME),
            PART_ONE_RESULT)
Exemplo n.º 5
0
    def test_text_init(self):
        "Test the Olympics object creation from text"

        # 1. Create Olympics object from text
        myobj = olympics.Olympics(text=aoc_14.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 2)
        self.assertEqual(len(myobj.reindeer), 2)
Exemplo n.º 6
0
    def test_text_init(self):
        "Test the Bitmask object creation from text"

        # 1. Create Bitmask object from text
        myobj = bitmask.Bitmask(text=aoc_14.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 4)
        self.assertEqual(len(myobj.mask), 36)
        self.assertEqual(len(myobj.memory), 0)
Exemplo n.º 7
0
    def test_part_two(self):
        "Test part two example of Olympics object"

        # 1. Create Olympics object from text
        myobj = olympics.Olympics(part2=True,
                                  text=aoc_14.from_text(PART_TWO_TEXT))

        # 2. Check the part two result
        self.assertEqual(
            myobj.part_two(verbose=False, race_time=EXAMPLE_RACE_TIME),
            PART_TWO_RESULT)
Exemplo n.º 8
0
    def test_text_init(self):
        "Test the Recipes object creation from text"

        # 1. Create Recipes object from text
        myobj = recipes.Recipes(text=aoc_14.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 1)
        self.assertEqual(myobj.scores, [3, 7])
        self.assertEqual(myobj.elves, [0, 1])
        self.assertEqual(myobj.after, 9)
Exemplo n.º 9
0
    def test_next_ten(self):
        "Test the Recipes object next_ten"

        # 1. Check lengths of EXAMPLE DATA
        self.assertEqual(len(EXAMPLE_AFTER), len(EXAMPLE_NXT10))

        # 2. Loop for the examples
        for index in range(len(EXAMPLE_AFTER)):

            # 3. Create Recipes object from text
            myobj = recipes.Recipes(text=aoc_14.from_text(EXAMPLE_TEXT))

            # 4. Checkout next 10 scores
            self.assertEqual(myobj.next_ten(EXAMPLE_AFTER[index]),
                             EXAMPLE_NXT10[index])
Exemplo n.º 10
0
    def test_steps(self):
        "Test the Recipes object steps"

        # 1. Check lengths of EXAMPLE DATA
        self.assertEqual(len(EXAMPLE_LAST), len(EXAMPLE_ELF1))
        self.assertEqual(len(EXAMPLE_LAST), len(EXAMPLE_ELF2))

        # 2. Create Recipes object from text
        myobj = recipes.Recipes(text=aoc_14.from_text(EXAMPLE_TEXT))

        # 3. Loop for several steps
        for step in range(len(EXAMPLE_LAST)):
            self.assertEqual(myobj.scores[-1], EXAMPLE_LAST[step])
            self.assertEqual(myobj.elves[0], EXAMPLE_ELF1[step])
            self.assertEqual(myobj.elves[1], EXAMPLE_ELF2[step])
            myobj.step()
Exemplo n.º 11
0
    def test_text_init_two(self):
        "Test the Polymer object creation from text for part two"

        # 1. Create Polymer object from text
        myobj = polymer.Polymer(text=aoc_14.from_text(EXAMPLE_TEXT),
                                part2=True)

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, True)
        self.assertEqual(len(myobj.text), 17)
        self.assertEqual(myobj.template, 'NNCB')
        self.assertEqual(len(myobj.rules), 16)

        # 3. Check methods
        self.assertEqual(myobj.element_diff((myobj.expand_template(1))), 1)
        self.assertEqual(myobj.element_diff((myobj.expand_template(2))), 5)
        self.assertEqual(myobj.element_diff((myobj.expand_template(3))), 7)
        self.assertEqual(myobj.element_diff((myobj.expand_template(10))), 1588)
        self.assertEqual(myobj.element_diff((myobj.expand_template(40))),
                         2188189693529)
Exemplo n.º 12
0
    def test_part_one_example_bits(self):
        """Test Disk Hash Knot bits from example"""

        # 1. Loop for the eight lines of the example
        for lnum, line in enumerate(aoc_14.from_text(EXAMPLE_HASH_KNOT_BITS)):
            if line[0] == '|' or line[0] == 'V':
                continue

            # 2. Create the knot object
            myknot = knots.Knots(length=256, part2=True)

            # 3. Generate the hash key
            hash_key = EXAMPLE_HASH_KNOT_KEY + '-%d' % lnum

            # 4. Get the dense hash
            dense_hash = myknot.process_knots(text=hash_key, verbose=False)

            # 5. Convert the first two digits to bits
            hash_bits = EXAMPLE_HASH_KNOT_HEX[dense_hash[0]] + \
                EXAMPLE_HASH_KNOT_HEX[dense_hash[1]]

            # 6. Compare with example
            self.assertEqual(hash_bits, line[0:8])