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

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp17))
        machine.run(instructions, labels, inv_lbl, func_help)

        self.assertEqual(machine.memory[100], 40320)
Exemplo n.º 2
0
    def test_incrementVariable(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp18))
        machine.run(instructions, labels, inv_lbl, func_help)

        self.assertEqual(machine.memory[0], 2)
Exemplo n.º 3
0
    def test_nestedMemCalls(self):
        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp6))
        machine.run(instructions, labels, inv_lbl, func_help)

        self.assertEqual(machine.memory[10], 400)

        self.assertEqual(machine.sp, -1)
Exemplo n.º 4
0
    def test_swap(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp16))
        machine.run(instructions, labels, inv_lbl, func_help)

        self.assertEqual(machine.memory[50], 100)
        self.assertEqual(machine.memory[51], -1)
Exemplo n.º 5
0
    def test_assignmentSingleFunctionCallNestedMem(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp4))
        machine.run(instructions, labels, inv_lbl, func_help)

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

        self.assertEqual(machine.sp, -1)
Exemplo n.º 6
0
    def tests_memorySorted(self):
        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp15))
        machine.run(instructions, labels, inv_lbl, func_help)

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

        self.assertEqual(machine.sp, -1)
Exemplo n.º 7
0
    def tests_memoryAccessWithVariable(self):
        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp14))
        machine.run(instructions, labels, inv_lbl, func_help)

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

        self.assertEqual(machine.sp, -1)
Exemplo n.º 8
0
    def test_moreCondsInFunctions(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp10))
        machine.run(instructions, labels, inv_lbl, func_help)

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

        self.assertEqual(machine.sp, -1)
Exemplo n.º 9
0
    def test_moreRecursiveFunctionsWithFiller(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp9))
        machine.run(instructions, labels, inv_lbl, func_help)

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

        self.assertEqual(machine.sp, -1)
Exemplo n.º 10
0
    def test_bullshitFunctionCallsIsPrime(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp5))
        machine.run(instructions, labels, inv_lbl, func_help)

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

        self.assertEqual(machine.sp, -1)
Exemplo n.º 11
0
    def test_noAssignmentInFunctionsRecursive(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp3))
        machine.run(instructions, labels, inv_lbl, func_help)

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

        self.assertEqual(machine.sp, -1)
Exemplo n.º 12
0
    def test_palinString(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp23))
        machine.run(instructions, labels, inv_lbl, func_help)

        self.assertTrue(machine.memory[20] == 0)
        self.assertTrue(machine.memory[21] == 1)

        print('hello world.')
Exemplo n.º 13
0
    def test_incrementedMemory(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp12))
        machine.run(instructions, labels, inv_lbl, func_help)

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

        self.assertEqual(machine.sp, -1)
Exemplo n.º 14
0
    def test_makeAscending(self):
        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp20))
        machine.run(instructions, labels, inv_lbl, func_help)

        a = machine.memory[0]

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

        for i in range(10):
            self.assertEqual(machine.memory[a + i], i)
Exemplo n.º 15
0
    def test_basicMath(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp1))
        machine.run(instructions, labels, inv_lbl, func_help)

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

        self.assertEqual(machine.sp, -1)
Exemplo n.º 16
0
    def test_mergeSort(self):

        machine = IRMachine1()

        instructions, labels, inv_lbl, func_help = parse(tokenize(sp.samp22))
        machine.run(instructions, labels, inv_lbl, func_help)

        arr = machine.memory[0]

        # 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.sp, -1)