more test

This commit is contained in:
Peter McGoron 2023-02-11 17:36:15 +00:00
parent b80cb225a4
commit 18ad8f03c6
1 changed files with 30 additions and 12 deletions

View File

@ -185,7 +185,7 @@ class AddTest(unittest.TestCase):
self.assertEqual(ex.cenv.reg[0], 30) self.assertEqual(ex.cenv.reg[0], 30)
self.assertEqual(ex.cenv.reg[1], word_2c(10)) self.assertEqual(ex.cenv.reg[1], word_2c(10))
def test_exec_mul_throw_imm(self): def test_exec_add_throw_imm(self):
p = Program() p = Program()
with self.assertRaises(TypecheckException) as cm: with self.assertRaises(TypecheckException) as cm:
p.parse_asm_line("add 5 6 7") p.parse_asm_line("add 5 6 7")
@ -194,16 +194,7 @@ class AddTest(unittest.TestCase):
self.assertEqual(cm.exception.i, 0) self.assertEqual(cm.exception.i, 0)
self.assertEqual(cm.exception.opcode, 3) self.assertEqual(cm.exception.opcode, 3)
def test_exec_mul_throw_imm(self): def test_exec_add_throw_lab_1(self):
p = Program()
with self.assertRaises(TypecheckException) as cm:
p.parse_asm_line("add 5 6 7")
self.assertEqual(cm.exception.argtype, ArgType.REG)
self.assertEqual(cm.exception.sarg, '5')
self.assertEqual(cm.exception.i, 0)
self.assertEqual(cm.exception.opcode, 3)
def test_exec_mul_throw_lab_1(self):
p = Program() p = Program()
with self.assertRaises(TypecheckException) as cm: with self.assertRaises(TypecheckException) as cm:
p.parse_asm_line("add r0 l6 7") p.parse_asm_line("add r0 l6 7")
@ -212,7 +203,7 @@ class AddTest(unittest.TestCase):
self.assertEqual(cm.exception.i, 1) self.assertEqual(cm.exception.i, 1)
self.assertEqual(cm.exception.opcode, 3) self.assertEqual(cm.exception.opcode, 3)
def test_exec_mul_throw_lab_2(self): def test_exec_add_throw_lab_2(self):
p = Program() p = Program()
with self.assertRaises(TypecheckException) as cm: with self.assertRaises(TypecheckException) as cm:
p.parse_asm_line("add r0 12 l24") p.parse_asm_line("add r0 12 l24")
@ -240,6 +231,33 @@ class MulTest(unittest.TestCase):
self.assertEqual(ex.cenv.reg[0], word_2c(25)) self.assertEqual(ex.cenv.reg[0], word_2c(25))
self.assertEqual(ex.cenv.reg[1], 125) self.assertEqual(ex.cenv.reg[1], 125)
def test_exec_mul_throw_imm(self):
p = Program()
with self.assertRaises(TypecheckException) as cm:
p.parse_asm_line("mul 942 6 7")
self.assertEqual(cm.exception.argtype, ArgType.REG)
self.assertEqual(cm.exception.sarg, '942')
self.assertEqual(cm.exception.i, 0)
self.assertEqual(cm.exception.opcode, 4)
def test_exec_mul_throw_lab_1(self):
p = Program()
with self.assertRaises(TypecheckException) as cm:
p.parse_asm_line("mul r9 l2 1991")
self.assertEqual(cm.exception.argtype, ArgType.VAL)
self.assertEqual(cm.exception.sarg, 'l2')
self.assertEqual(cm.exception.i, 1)
self.assertEqual(cm.exception.opcode, 4)
def test_exec_mul_throw_lab_2(self):
p = Program()
with self.assertRaises(TypecheckException) as cm:
p.parse_asm_line("mul r0 -11 l48")
self.assertEqual(cm.exception.argtype, ArgType.VAL)
self.assertEqual(cm.exception.sarg, 'l48')
self.assertEqual(cm.exception.i, 2)
self.assertEqual(cm.exception.opcode, 4)
class ProgramTest(unittest.TestCase): class ProgramTest(unittest.TestCase):
def test_exec_simple_reg(self): def test_exec_simple_reg(self):
p = Program() p = Program()