Exemple #1
0
 def testOutboxWithoutPointerRaiseException(self):
     inbox = iter([])
     ops = [
         ["OUTBOX"]
     ]
     state = cpu.create_state(inbox, ops)
     with self.assertRaises(ExecutionExceptin):
         cpu.tick(state)
Exemple #2
0
    def testBumpdnWithoutValue(self):
        inbox = iter([])
        ops = [
            ["BUMPDN", '0']
        ]
        state = cpu.create_state(inbox, ops)

        with self.assertRaises(ExecutionExceptin):
            cpu.tick(state)
Exemple #3
0
    def testJumpWithoutLabel(self):
        inbox = iter([])
        ops = [
            ["JUMP", 'a'],
        ]
        state = cpu.create_state(inbox, ops)

        with self.assertRaises(ExecutionExceptin):
            cpu.tick(state)
Exemple #4
0
 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)
Exemple #5
0
    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)
Exemple #6
0
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)
Exemple #7
0
    def testBumpdnWithCharacter(self):
        inbox = iter([])
        ops = [
            ["BUMPDN", '0']
        ]
        state = cpu.create_state(inbox, ops)
        state.regs = ['A']

        with self.assertRaises(ExecutionExceptin):
            cpu.tick(state)
Exemple #8
0
    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))
Exemple #9
0
    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)
Exemple #10
0
    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)
Exemple #11
0
    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))
Exemple #12
0
    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)
Exemple #13
0
    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)
Exemple #14
0
    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)
Exemple #15
0
    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)
Exemple #16
0
    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)
Exemple #17
0
    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)
Exemple #18
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)
Exemple #19
0
    def test_level_mechanic(self):
        state = cpu.create_state(iter([]), [])

        test_level = level.get_test_level()
        self.assertTrue(test_level.check_function(state))
Exemple #20
0
    __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)
Exemple #21
0
        __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)