def test_parse(self): mod = cirparser.from_c(source) verify(mod) func = mod.get_function('myfunc') result = interp.run(func, args=[10.0]) self.assertEqual(result, 12)
Int32 loop() { Int32 i, sum = 0; for (i = 0; i < 10; i = i + 1) { sum = sum + i; } return sum; } Int32 raise() { Exception exc = new_exc("TypeError", ""); exc_throw(exc); return 0; } """ mod = cirparser.from_c(source) verify(mod) class TestInterp(unittest.TestCase): def test_simple(self): f = mod.get_function('simple') result = interp.run(f, args=[10.0]) assert result == 100.0, result def test_loop(self): loop = mod.get_function('loop') result = interp.run(loop) assert result == 45, result def test_exceptions(self):
int loop() { int i, sum = 0; for (i = 0; i < 10; i = i + 1) { sum = sum + i; } return sum; } int raise() { Exception exc = new_exc("TypeError", list()); exc_throw(exc); return 0; } """ mod = cirparser.from_c(source) verify(mod) class TestInterp(unittest.TestCase): def test_simple(self): f = mod.get_function('simple') result = interp.run(f, args=[10.0]) assert result == 100.0, result def test_loop(self): loop = mod.get_function('loop') result = interp.run(loop) assert result == 45, result def test_exceptions(self):