def testOutboxWithoutPointerRaiseException(self): inbox = iter([]) ops = [ ["OUTBOX"] ] state = cpu.create_state(inbox, ops) with self.assertRaises(ExecutionExceptin): cpu.tick(state)
def testBumpdnWithoutValue(self): inbox = iter([]) ops = [ ["BUMPDN", '0'] ] state = cpu.create_state(inbox, ops) with self.assertRaises(ExecutionExceptin): cpu.tick(state)
def testJumpWithoutLabel(self): inbox = iter([]) ops = [ ["JUMP", 'a'], ] state = cpu.create_state(inbox, ops) with self.assertRaises(ExecutionExceptin): cpu.tick(state)
def testInbox(self): inbox = iter([1]) ops = [ ["INBOX"] ] state = cpu.create_state(inbox, ops) state = cpu.tick(state) self.assertEqual(list(state.inbox), []) self.assertEqual(state.pointer, 1) self.assertEqual(state.pc, 1)
def testAddWithoutPointerRaiseException(self): inbox = iter([]) ops = [ ["ADD", '0'] ] state = cpu.create_state(inbox, ops) state.regs[0] = 2 with self.assertRaises(ExecutionExceptin): cpu.tick(state)
def main(filepath): ops = parse_file(filepath) inbox = (n for n in "0123") state = cpu.create_state(inbox, ops) while cpu.tick(state) != -1: pass print("Result:") print(state.outbox)
def testBumpdnWithCharacter(self): inbox = iter([]) ops = [ ["BUMPDN", '0'] ] state = cpu.create_state(inbox, ops) state.regs = ['A'] with self.assertRaises(ExecutionExceptin): cpu.tick(state)
def test_level_4(self): state = cpu.create_state(iter([]), []) l = level.get_level_4() self.assertFalse(l.check_function(state)) state.outbox = (n for n in "74OL74") self.assertTrue(l.check_function(state)) state.outbox = [6, 7, 6, 7] self.assertFalse(l.check_function(state))
def testSubWithNumberAndCharRaiseException(self): inbox = iter([]) ops = [ ["SUB", '0'] ] state = cpu.create_state(inbox, ops) state.pointer = 1 state.regs[0] = 'A' with self.assertRaises(ExecutionExceptin): cpu.tick(state)
def test_state_contains_prev_state(self): inbox = iter([]) ops = [ ["BUMPUP", '3'] ] state = cpu.create_state(inbox, ops) state.regs[3] = 4 new_state = cpu.tick(state) self.assertEquals(state.prev_state, None) self.assertEquals(state, new_state.prev_state)
def test_tick_return_new_state(self): inbox = iter([]) ops = [ ["BUMPUP", '3'] ] state = cpu.create_state(inbox, ops) state.regs[3] = 4 new_state = cpu.tick(state) self.assertNotEquals(state.pointer, new_state.pointer) self.assertNotEquals(state.regs[3], new_state.regs[3]) self.assertNotEquals(str(state), str(new_state))
def testAddWithNegativeValue(self): inbox = iter([]) ops = [ ["ADD", '0'] ] state = cpu.create_state(inbox, ops) state.pointer = 1 state.regs[0] = -2 state = cpu.tick(state) self.assertEqual(list(state.outbox), []) self.assertEqual(state.pointer, -1) self.assertEqual(state.pc, 1)
def testSub(self): inbox = iter([]) ops = [ ["SUB", '0'] ] state = cpu.create_state(inbox, ops) state.pointer = 1 state.regs[0] = 2 state = cpu.tick(state) self.assertEqual(list(state.outbox), []) self.assertEqual(state.pointer, -1) self.assertEqual(state.pc, 1)
def testBumpdn(self): inbox = iter([]) ops = [ ["BUMPDN", '0'] ] state = cpu.create_state(inbox, ops) state.regs[0] = 2 state = cpu.tick(state) self.assertEqual(list(state.outbox), []) self.assertEqual(state.pointer, 1) self.assertEqual(state.regs[0], 1) self.assertEqual(state.pc, 1)
def testSubWithSmallerChars(self): inbox = iter([]) ops = [ ["SUB", '0'] ] state = cpu.create_state(inbox, ops) state.pointer = 'X' state.regs[0] = 'B' state = cpu.tick(state) self.assertEqual(list(state.outbox), []) self.assertEqual(state.pointer, 22) self.assertEqual(state.pc, 1)
def testCopyFromToWithNormalIndex(self): inbox = iter([]) ops = [ ["COPYFROM", '0'], ["COPYTO", '1'] ] state = cpu.create_state(inbox, ops) state.regs[0] = 2 while state.pc != -1: state = cpu.tick(state) self.assertEqual(list(state.outbox), []) self.assertEqual(state.regs[0], 2) self.assertEqual(state.regs[1], 2)
def testJump(self): inbox = iter([]) ops = [ ["JUMP", 'a'], ["BUMPUP", '0'], ["a:"] ] state = cpu.create_state(inbox, ops) state.regs[0] = 0 while state.pc != -1: state = cpu.tick(state) self.assertEqual(list(state.outbox), []) self.assertEqual(state.pointer, None) self.assertEqual(state.regs[0], 0)
def testOutbox(self): inbox = iter([1]) ops = [ ["OUTBOX"], ["OUTBOX"] ] state = cpu.create_state(inbox, ops) state.pointer = 1 state = cpu.tick(state) state.pointer = "A" state = cpu.tick(state) self.assertEqual(list(state.outbox), [1, "A"]) self.assertEqual(state.pointer, None) self.assertEqual(state.pc, 2)
def test_level_mechanic(self): state = cpu.create_state(iter([]), []) test_level = level.get_test_level() self.assertTrue(test_level.check_function(state))
__reset_modified = True __code_items.edit_modified(False) __reset_modified = False def __clear_children(widget): for s in widget.pack_slaves(): s.pack_forget() s.destroy() # this will force tk to refresh the widgets and remove slaves from view widget.configure(bd=0) if __name__ == "__main__": inbox = iter([]) ops = [ ] state = cpu.create_state(inbox, ops) inbox = iter(['0', 'A']) ops = [ ["ADD", '0'] ] state = cpu.create_state(inbox, ops) state.outbox = ['0', 'A'] state.pointer = 'A' state.regs[0] = 'A' main(state)
__code_items.tag_configure("KEYWORD", foreground="blue") __code_items.tag_configure("ERROR", foreground="red") __reset_modified = True __code_items.edit_modified(False) __reset_modified = False def __clear_children(widget): for s in widget.pack_slaves(): s.pack_forget() s.destroy() # this will force tk to refresh the widgets and remove slaves from view widget.configure(bd=0) if __name__ == "__main__": inbox = iter([]) ops = [] state = cpu.create_state(inbox, ops) inbox = iter(['0', 'A']) ops = [["ADD", '0']] state = cpu.create_state(inbox, ops) state.outbox = ['0', 'A'] state.pointer = 'A' state.regs[0] = 'A' main(state)