def test_part_two(self): "Test part two example of Turing object" # 1. Create Turing object from text myobj = turing.Turing(part2=True, text=aoc_25.from_text(PART_TWO_TEXT)) # 2. Check the part two self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def test_part_one(self): "Test part one example of Constellations object" # 1. Create Constellations object from text myobj = constellations.Constellations(text=aoc_25.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
def test_part_one(self): "Test part one example of Turing object" # 1. Create Turing object from text myobj = turing.Turing(text=aoc_25.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 Codes object" # 1. Create Codes object from text myobj = codes.Codes(part2=True, text=aoc_25.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def test_examples(self): "Test multiple examples" myobj = constellations.Constellations(text=aoc_25.from_text(EXAMPLE_TWO)) myobj.form_constellations() self.assertEqual(len(myobj.constellations), 2) myobj = constellations.Constellations(text=aoc_25.from_text(EXAMPLE_FOUR)) myobj.form_constellations() self.assertEqual(len(myobj.constellations), 4) myobj = constellations.Constellations(text=aoc_25.from_text(EXAMPLE_THREE)) myobj.form_constellations() self.assertEqual(len(myobj.constellations), 3) myobj = constellations.Constellations(text=aoc_25.from_text(EXAMPLE_EIGHT)) myobj.form_constellations() self.assertEqual(len(myobj.constellations), 8)
def test_text_init(self): "Test the Turing object creation from text" # 1. Create Turing object from text myobj = turing.Turing(text=aoc_25.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 20) self.assertEqual(len(myobj.tape), 0) self.assertEqual(myobj.position, 0) self.assertEqual(myobj.state, 'A') self.assertEqual(myobj.steps, 6) self.assertEqual(len(myobj.rules), 2) # 3. Check the rules self.assertTrue('A' in myobj.rules) self.assertTrue('B' in myobj.rules) self.assertEqual(len(myobj.rules['A']), 2) self.assertEqual(len(myobj.rules['B']), 2) self.assertEqual(myobj.rules['A'][0], turing.Rule('A', 0, 1, turing.RIGHT, 'B')) self.assertEqual(myobj.rules['A'][1], turing.Rule('A', 1, 0, turing.LEFT, 'B')) self.assertEqual(myobj.rules['B'][0], turing.Rule('B', 0, 1, turing.LEFT, 'A')) self.assertEqual(myobj.rules['B'][1], turing.Rule('B', 1, 1, turing.RIGHT, 'A')) # 3. Check the step and ones methods self.assertEqual(myobj.position, 0) self.assertEqual(myobj.state, 'A') self.assertEqual(myobj.ones(), 0) myobj.step() self.assertEqual(myobj.position, 1) self.assertEqual(myobj.state, 'B') self.assertEqual(myobj.ones(), 1) myobj.step() self.assertEqual(myobj.position, 0) self.assertEqual(myobj.state, 'A') self.assertEqual(myobj.ones(), 2) myobj.step() self.assertEqual(myobj.position, -1) self.assertEqual(myobj.state, 'B') self.assertEqual(myobj.ones(), 1) myobj.step() self.assertEqual(myobj.position, -2) self.assertEqual(myobj.state, 'A') self.assertEqual(myobj.ones(), 2) myobj.step() self.assertEqual(myobj.position, -1) self.assertEqual(myobj.state, 'B') self.assertEqual(myobj.ones(), 3) myobj.step() self.assertEqual(myobj.position, 0) self.assertEqual(myobj.state, 'A') self.assertEqual(myobj.ones(), 3)
def test_part_one(self): "Test part one example of Handshake object" # 1. Create Handshake object from text myobj = handshake.Handshake(text=aoc_25.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False, limit=99), PART_ONE_RESULT)
def not_test_part_two(self): "Test part two example of Handshake object" # 1. Create Handshake object from text myobj = handshake.Handshake(part2=False, text=aoc_25.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=True, limit=99), PART_TWO_RESULT)
def test_text_init(self): "Test the Codes object creation from text" # 1. Create Codes object from text myobj = codes.Codes(text=aoc_25.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.row, 4) self.assertEqual(myobj.col, 6)
def test_text_init(self): "Test the Assembunny object creation from text" # 1. Create Assembunny object from text myobj = assembunny.Assembunny(text=aoc_25.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 30) self.assertEqual(myobj.registers, {'a': 0, 'b': 0, 'c': 0, 'd': 0}) self.assertEqual(myobj.program_counter, 0)
def test_text_init(self): "Test the Constellations object creation from text" # 1. Create Constellations object from text myobj = constellations.Constellations(text=aoc_25.from_text(EXAMPLE_TWO)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 8) self.assertEqual(len(myobj.points), 8) self.assertEqual(myobj.points[0], [0,0,0,0]) self.assertEqual(myobj.points[1], [3,0,0,0]) self.assertEqual(myobj.constellations, []) # 3. Join into constallations myobj.form_constellations() self.assertEqual(len(myobj.points), 8) self.assertEqual(len(myobj.constellations), 2)
def test_text_init(self): "Test the Handshake object creation from text" # 1. Create Handshake object from text myobj = handshake.Handshake(text=aoc_25.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(myobj.card_public, 5764801) self.assertEqual(myobj.door_public, 17807724) self.assertEqual(myobj.card_private, None) self.assertEqual(myobj.door_private, None) # 3. Check methods self.assertEqual(myobj.transform_number(17807724, 8), 14897079) self.assertEqual(myobj.transform_number(5764801, 11), 14897079) self.assertEqual(myobj.guess_private(5764801, limit=20), 8) self.assertEqual(myobj.guess_private(17807724, limit=20), 11) self.assertEqual(myobj.guess_encryption_key(verbose=False, limit=20), 14897079)
def test_text_init(self): "Test the Seafloor object creation from text" # 1. Create Seafloor object from text myobj = seafloor.Seafloor(text=aoc_25.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.eastern), 23) self.assertEqual(len(myobj.southern), 26) self.assertEqual(myobj.rows, 9) self.assertEqual(myobj.cols, 10) self.assertEqual(myobj.steps, 0) self.assertEqual(myobj.moved, True) self.assertFalse((0, 0) in myobj.eastern) self.assertTrue((0, 0) in myobj.southern) self.assertFalse((1, 0) in myobj.eastern) self.assertFalse((1, 0) in myobj.southern) self.assertFalse((2, 1) in myobj.eastern) self.assertTrue((2, 1) in myobj.southern) self.assertTrue((3, 1) in myobj.eastern) self.assertFalse((3, 1) in myobj.southern) self.assertTrue((9, 0) in myobj.eastern) self.assertFalse((9, 0) in myobj.southern) self.assertTrue((9, 8) in myobj.eastern) self.assertFalse((9, 8) in myobj.southern) # 3. Check methods self.assertEqual(myobj.in_front_of((0, 0), seafloor.SOUTH), (0, 1)) self.assertEqual(myobj.in_front_of((4, 0), seafloor.EAST), (5, 0)) self.assertEqual(myobj.in_front_of((9, 0), seafloor.EAST), (0, 0)) self.assertEqual(myobj.in_front_of((9, 8), seafloor.EAST), (0, 8)) self.assertEqual(myobj.in_front_of((4, 8), seafloor.SOUTH), (4, 0)) self.assertEqual(myobj.run(), 58)