def test_immediate_two(self): memory = [1101, 5, 4, 0, 99] pos = 0 memory, pos, cont = execute_add(memory, pos) self.assertEqual(pos, 4) self.assertEqual(cont, True) self.assertEqual(memory, [9, 5, 4, 0, 99])
def test_immediate_one(self): memory = [1001, 0, 4, 0, 99] pos = 0 memory, pos, cont = execute_add(memory, pos) self.assertEqual(pos, 4) self.assertEqual(cont, True) self.assertEqual(memory, [1005, 0, 4, 0, 99])
def test_inplace(self): memory = [1, 0, 0, 0, 99] pos = 0 memory, pos, cont = execute_add(memory, pos) self.assertEqual(pos, 4) self.assertEqual(cont, True) self.assertEqual(memory, [2, 0, 0, 0, 99])
def test_simple(self): memory = [1, 4, 5, 6, 1, 1, 0] pos = 0 memory, pos, cont = execute_add(memory, pos) self.assertEqual(pos, 4) self.assertEqual(cont, True) self.assertEqual(memory, [1, 4, 5, 6, 1, 1, 2])
def test_immediate_result_error(self): memory = [10001, 0, 0, 0, 99] pos = 0 with self.assertRaises(AssertionError): execute_add(memory, pos)
def test_wrong_operator(self): memory = [2, 0, 0, 0, 99] pos = 0 with self.assertRaises(AssertionError): execute_add(memory, pos)
def test_out_of_range(self): memory = [1, 0, 0, 100, 99] pos = 0 with self.assertRaises(IndexError): execute_add(memory, pos)