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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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.')
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)
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)
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)
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)