Exemplo n.º 1
0
    def test_incrementVariable(self):

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp18))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table)

        self.assertEqual(machine.memory[machine.registers[SP] - 1], 2)
        self.assertEqual(machine.registers[SP], 0xF000)
Exemplo n.º 2
0
    def test_palinString(self):

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp23))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table, str_table)

        self.assertEqual(machine.memory[20], 0)
        self.assertEqual(machine.memory[21], 1)
Exemplo n.º 3
0
    def test_memFactorial(self):

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp17))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table)

        self.assertEqual(machine.memory[100], 40320)

        self.assertEqual(machine.registers[SP], 0xF000)
Exemplo n.º 4
0
    def tests_memoryAccessWithVariable(self):
        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp14))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table)

        for i in range(5, 25):
            self.assertEqual(machine.memory[i], 0, i)

        self.assertEqual(machine.registers[SP], 0xF000)
Exemplo n.º 5
0
    def test_moreRecursiveFunctionsWithFiller(self):

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp9))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table)

        self.assertEqual(machine.memory[100], 1)

        self.assertEqual(machine.registers[SP], 0xF000)
Exemplo n.º 6
0
    def test_assignmentSingleFunctionCallNestedMem(self):

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp4))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table)

        self.assertEqual(machine.memory[50], 50)

        self.assertEqual(machine.registers[SP], 0xF000)
Exemplo n.º 7
0
    def tests_memorySorted(self):
        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp15))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table)

        for i in range(20, 99):
            self.assertTrue(machine.memory[i] <= machine.memory[i + 1],
                            'Mem loc: {}'.format(i))

        self.assertEqual(machine.registers[SP], 0xF000)
Exemplo n.º 8
0
    def test_bullshitFunctionCallsIsPrime(self):

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp5))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table)

        self.assertEqual(machine.memory[50], 1)
        self.assertEqual(machine.memory[51], 0)

        self.assertEqual(machine.registers[SP], 0xF000)
Exemplo n.º 9
0
    def test_noAssignmentInFunctionsRecursive(self):

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp3))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()

        machine.run(pure, table)

        self.assertEqual(machine.memory[100], 210)
        self.assertEqual(machine.memory[101], 40320)

        self.assertEqual(machine.registers[SP], 0xF000)
Exemplo n.º 10
0
    def test_makeAscending(self):
        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp20))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table)

        ptr_a = machine.memory[100]

        self.assertEqual(machine.memory[ptr_a - 1], 10)

        for i in range(10):
            self.assertEqual(machine.memory[ptr_a + i], i)
Exemplo n.º 11
0
    def test_memString2D(self):
        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp28))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table, str_table)

        for i in range(5):
            if i % 2 == 0:
                for j in range(5):
                    self.assertEqual(machine.memory[5 + i * 5 + j], ord('a'))
            else:
                for j in range(5):
                    self.assertEqual(machine.memory[5 + i * 5 + j], ord('t'))
Exemplo n.º 12
0
    def test_memArrAssign(self):
        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp26))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table)

        arr = machine.memory[100]

        # machine.print_memory(0, 120)
        self.assertEqual(machine.memory[arr - 1], 20)

        for i in range(0, 20):
            self.assertTrue(machine.memory[arr + i] == i, i)
Exemplo n.º 13
0
    def test_basicMath2(self):

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp2))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()

        machine.run(pure, table)

        self.assertEqual(machine.memory[50], -90)
        self.assertEqual(machine.memory[51], 1700)
        self.assertEqual(machine.memory[52], 80)
        self.assertEqual(machine.memory[53], 1700)
        self.assertEqual(machine.memory[54], 1)

        self.assertEqual(machine.registers[SP], 0xF000)
Exemplo n.º 14
0
    def test_mergeSort(self):

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp22))
        lc3_conv = LC3Converter(instructions, labels, inv_lbl, func_help)

        tree, table, str_table = lc3_conv.convert()
        pure = flatten(tree)

        machine = Machine()
        machine.run(pure, table)

        arr = machine.memory[150]

        # machine.print_memory(0, 120)
        self.assertEqual(machine.memory[arr - 1], 100)

        for i in range(0, 99):
            self.assertTrue(
                machine.memory[arr + i] <= machine.memory[arr + i + 1],
                'Mem loc: {}, seed: {}'.format(arr + i, machine.seed))

        self.assertEqual(machine.registers[SP], 0xF000)