def test_text_init(self): "Test the Mfcsam object creation from text" # 1. Create Mfcsam object from text myobj = mfcsam.Mfcsam(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), 10) self.assertEqual(len(myobj.compounds), 10) # 3. Check methods self.assertEqual(myobj.is_match('katz', 7), False) self.assertEqual(myobj.is_match('cats', 0), False) self.assertEqual(myobj.is_match('cats', 7), True) self.assertEqual(myobj.is_match('cats', 8), False) self.assertEqual(myobj.is_complete_match({'cats': 8}), False) self.assertEqual(myobj.is_complete_match({'cats': 7}), True) self.assertEqual(myobj.is_complete_match({ 'cats': 7, 'trees': 3 }), True) self.assertEqual( myobj.is_complete_match({ 'cats': 7, 'trees': 3, 'perfumes': 2 }), False) self.assertEqual( myobj.is_complete_match({ 'cats': 7, 'trees': 3, 'perfumes': 1 }), True)
def test_part_two(self): "Test part two example of Dragon object" # 1. Create Dragon object from text myobj = dragon.Dragon(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_part_one(self): "Test part one example of Tickets object" # 1. Create Tickets object from text myobj = tickets.Tickets(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_text_init(self): "Test the Device object creation from text" # 1. Create Device object from text myobj = device.Device(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), 9) self.assertEqual(len(myobj.obs), 1) self.assertEqual(len(myobj.program), 3)
def test_text_init(self): "Test the Detective object creation from text" # 1. Create Detective object from text myobj = detective.Detective(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), 9) self.assertEqual(len(myobj.csi.text), 10) self.assertEqual(len(myobj.aunts), 9)
def test_text_init(self): "Test the Tickets object creation from text" # 1. Create Tickets object from text myobj = tickets.Tickets(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), 10) self.assertEqual(len(myobj.rules), 3) self.assertNotEqual(myobj.mine, None) self.assertEqual(len(myobj.nearby), 4)
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_text_init(self): "Test the Dragon object creation from text" # 1. Create Dragon object from text myobj = dragon.Dragon(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) self.assertEqual(myobj.seed, "10000") # 3. Check methods self.assertEqual(myobj.fill_and_check(20), "01100")
def test_text_init(self): "Test the Observation object creation from text" # 1. Create Device object from text myobj = observations.Observations( text=aoc_16.from_text(EXAMPLE_TEXT_MULTIPLE)) # 2. Make sure it has the expected values self.assertEqual(len(myobj.text), 55) self.assertEqual(len(myobj.data), 13) self.assertEqual(myobj.data[0].before, [3, 2, 1, 1]) self.assertEqual(myobj.data[0].instruction, [9, 2, 1, 2]) self.assertEqual(myobj.data[0].after, [3, 2, 2, 1])
def __init__(self, text=None, part2=False): # 1. Set the initial values self.part2 = part2 self.text = text self.csi = mfcsam.Mfcsam(text=aoc_16.from_text(MFCSAM_TEXT), part2=self.part2) self.aunts = {} # 2. Process text (if any) if text is not None and len(text) > 0: for line in text: new_aunt = aunt.Aunt(text=line, part2=self.part2) self.aunts[new_aunt.number] = new_aunt
def test_text_init(self): "Test the Device object creation from text" # 1. Create Device object from text myobj = observations.Observation( text=aoc_16.from_text(EXAMPLE_TEXT_SINGLE)) # 2. Make sure it has the expected values self.assertEqual(len(myobj.text), 3) self.assertEqual(len(myobj.before), 4) self.assertEqual(len(myobj.instruction), 4) self.assertEqual(len(myobj.after), 4) self.assertEqual(myobj.before, [3, 2, 1, 1]) self.assertEqual(myobj.instruction, [9, 2, 1, 2]) self.assertEqual(myobj.after, [3, 2, 2, 1]) self.assertEqual(len(myobj.names), 0) # 3. Test with instructions self.assertEqual(myobj.try_inst('true', inst_true), True) self.assertEqual(myobj.try_inst('false', inst_false), False) self.assertEqual(len(myobj.names), 1) self.assertEqual(myobj.names, set(['true']))
def test_opcodes(self): "Test determining opcodes" # 1. Create Device object from text myobj = observations.Observations( text=aoc_16.from_text(EXAMPLE_TEXT_MULTIPLE)) # 2. Make sure it has the expected values self.assertEqual(len(myobj.text), 55) self.assertEqual(len(myobj.data), 13) # 3. Process the observations myobj.process_observations(device.INSTS) self.assertEqual(myobj.data[0].names, set(['seti', 'addi', 'mulr'])) self.assertEqual( myobj.data[1].names, set([ 'bani', 'eqri', 'gtrr', 'muli', 'borr', 'bori', 'addr', 'setr', 'gtir' ])) self.assertEqual(myobj.data[2].names, set(['seti', 'banr', 'borr', 'setr', 'bani', 'bori'])) # 4. Evaluate the opcodes self.assertEqual(myobj.determine_opcodes(device.INSTS)[15], None)