def test_part_two(self): "Test part two example of Rules object" # 1. Create Rules object from text myobj = rules.Rules(part2=True, text=aoc_07.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def test_part_two(self): "Test part two example of Cpm object" # 1. Create Cpm object from text myobj = cpm.Cpm(part2=True, text=aoc_07.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(number=2, seconds=0, verbose=False), PART_TWO_RESULT)
def test_part_one(self): "Test part one example of Rules object" # 1. Create Rules object from text myobj = rules.Rules(text=aoc_07.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
def test_text_init(self): "Test the Rules object creation from text" # 1. Create Rules object from text myobj = rules.Rules(text=aoc_07.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 9) self.assertEqual(len(myobj.rules), 9)
def test_text_init_two(self): "Test the Crabs object creation from text for part2" # 1. Create Crabs object from text myobj = crabs.Crabs(text=aoc_07.from_text(EXAMPLE_TEXT), part2=True) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, True) self.assertEqual(len(myobj.text), 1) self.assertEqual(len(myobj.crabs), 10) # 3. Check methods self.assertEqual(myobj.cost(16, 5), 66) self.assertEqual(myobj.need(2), 206) self.assertEqual(myobj.need(5), 168) self.assertEqual(myobj.align_median(), 206) self.assertEqual(myobj.align_search(), 168)
def test_text_init(self): "Test the Crabs object creation from text" # 1. Create Crabs object from text myobj = crabs.Crabs(text=aoc_07.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(len(myobj.crabs), 10) # 3. Check methods self.assertEqual(myobj.cost(16, 2), 14) self.assertEqual(myobj.need(2), 37) self.assertEqual(myobj.need(1), 41) self.assertEqual(myobj.need(10), 71) self.assertEqual(myobj.align_median(), 37) self.assertEqual(myobj.align_search(), 37)
def test_text_init(self): "Test the Cpm object creation from text" # 1. Create Cpm object from text myobj = cpm.Cpm(text=aoc_07.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 7) self.assertEqual(len(myobj.letters), 6) self.assertEqual(len(myobj.steps), 5) self.assertEqual(len(myobj.completed), 0) self.assertEqual(len(myobj.ordered), 0) self.assertTrue('A' in myobj.steps) self.assertEqual(myobj.steps['A'].letter, 'A') self.assertEqual(myobj.steps['A'].before, set('C')) self.assertTrue('E' in myobj.steps) self.assertEqual(myobj.steps['E'].letter, 'E') self.assertEqual(myobj.steps['E'].before, set(['B', 'D', 'F'])) self.assertTrue('C' not in myobj.steps) # 3. Get the starting letter self.assertEqual(myobj.get_start(), set(['C'])) self.assertEqual(myobj.next_step(), set(['C'])) # 4. Walk through the steps myobj.complete('C') self.assertEqual(myobj.next_step(), set(['A', 'F'])) myobj.complete('A') self.assertEqual(myobj.next_step(), set(['B', 'D', 'F'])) myobj.complete('B') self.assertEqual(myobj.next_step(), set(['D', 'F'])) myobj.complete('D') self.assertEqual(myobj.next_step(), set(['F'])) myobj.complete('F') self.assertEqual(myobj.next_step(), set(['E'])) myobj.complete('E') self.assertEqual(myobj.ordered, ['C', 'A', 'B', 'D', 'F', 'E'])
def test_part_two(self): """Test Discs creation from text""" # 1. Create Jumps object from text mydiscs = discs.Discs(text=aoc_07.from_text(P1_EXAMPLES_TEXT), part2=True) # 2. Make sure it has the specified values self.assertEqual(mydiscs.part2, True) self.assertEqual(len(mydiscs.discs), 13) self.assertEqual("pbga" in mydiscs.discs, True) self.assertEqual("xxxx" in mydiscs.discs, False) self.assertEqual(mydiscs.discs["pbga"].name, "pbga") self.assertEqual(mydiscs.discs["pbga"].weight, 66) self.assertEqual(mydiscs.discs["pbga"].above, []) self.assertEqual(mydiscs.discs["fwft"].name, "fwft") self.assertEqual(mydiscs.discs["fwft"].weight, 72) self.assertEqual(mydiscs.discs["fwft"].above, ["ktlj", "cntj", "xhth"]) # 3. Check methods self.assertEqual(mydiscs.number_above("pbga"), 0) self.assertEqual(mydiscs.number_above("xhth"), 0) self.assertEqual(mydiscs.number_above("fwft"), 3) self.assertEqual(mydiscs.number_above("tknk"), 12) self.assertEqual(mydiscs.bottom(), "tknk") # 4. Check part two methods # ugml + (gyxo + ebii + jptl) = 68 + (61 + 61 + 61) = 251 # padx + (pbga + havc + qoyq) = 45 + (66 + 66 + 66) = 243 # fwft + (ktlj + cntj + xhth) = 72 + (57 + 57 + 57) = 243 self.assertEqual(mydiscs.weight_above("gyxo"), 61) self.assertEqual(mydiscs.weight_above("ugml"), 251) self.assertEqual(mydiscs.weight_above("padx"), 243) self.assertEqual(mydiscs.weight_above("fwft"), 243) self.assertEqual(mydiscs.adjustment("tknk"), 243 - 251) self.assertEqual(mydiscs.adjustment("ugml"), 0) self.assertEqual(mydiscs.balance(), 60)
def test_text_init(self): """Test Discs creation from text""" # 1. Create Jumps object from text mydiscs = discs.Discs(text=aoc_07.from_text(P1_EXAMPLES_TEXT)) # 2. Make sure it has the specified values self.assertEqual(mydiscs.part2, False) self.assertEqual(len(mydiscs.discs), 13) self.assertEqual("pbga" in mydiscs.discs, True) self.assertEqual("xxxx" in mydiscs.discs, False) self.assertEqual(mydiscs.discs["pbga"].name, "pbga") self.assertEqual(mydiscs.discs["pbga"].weight, 66) self.assertEqual(mydiscs.discs["pbga"].above, []) self.assertEqual(mydiscs.discs["fwft"].name, "fwft") self.assertEqual(mydiscs.discs["fwft"].weight, 72) self.assertEqual(mydiscs.discs["fwft"].above, ["ktlj", "cntj", "xhth"]) # 3. Check methods self.assertEqual(mydiscs.number_above("pbga"), 0) self.assertEqual(mydiscs.number_above("xhth"), 0) self.assertEqual(mydiscs.number_above("fwft"), 3) self.assertEqual(mydiscs.number_above("tknk"), 12) self.assertEqual(mydiscs.bottom(), "tknk")
def test_text_init(self): "Test the Gates object creation from text" # 1. Create Gates object from text myobj = gates.Gates(text=aoc_07.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 10) self.assertEqual(len(myobj.wires), 0) # 3. Check methods self.assertEqual(myobj.execute(["SET", 1, 1, "aa"]), 1) self.assertEqual(myobj.execute(["SET", 123, 123, "bb"]), 123) myobj.run_once() self.assertEqual(myobj.wires["d"], 72) self.assertEqual(myobj.wires["e"], 507) self.assertEqual(myobj.wires["f"], 492) self.assertEqual(myobj.wires["g"], 114) self.assertEqual(myobj.wires["h"], 65412) self.assertEqual(myobj.wires["i"], 65079) self.assertEqual(myobj.wires["x"], 123) self.assertEqual(myobj.wires["y"], 456) self.assertEqual(myobj.wires["a"], 114)