🐐 DORMI
This commit is contained in:
89
tests.py
89
tests.py
@@ -2,6 +2,7 @@ import os
|
||||
import random
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
from io import StringIO
|
||||
from unittest.mock import patch
|
||||
@@ -2217,5 +2218,93 @@ class TestFvnctio(unittest.TestCase):
|
||||
run_test(self, source, nodes, value, output)
|
||||
|
||||
|
||||
# --- DORMI ---
|
||||
|
||||
dormi_tests = [
|
||||
("DORMI(NVLLVS)",
|
||||
Program([], [ExpressionStatement(BuiltIn("DORMI", [Nullus()]))]),
|
||||
ValNul()),
|
||||
]
|
||||
|
||||
class TestDormi(unittest.TestCase):
|
||||
@parameterized.expand(dormi_tests)
|
||||
def test_dormi(self, source, nodes, value, output=""):
|
||||
run_test(self, source, nodes, value, output)
|
||||
|
||||
def test_dormi_timing_int(self):
|
||||
source = "DORMI(I)\n"
|
||||
lexer = Lexer().get_lexer()
|
||||
tokens = lexer.lex(source)
|
||||
program = Parser().parse(tokens)
|
||||
|
||||
start = time.time()
|
||||
program.eval()
|
||||
elapsed = time.time() - start
|
||||
self.assertAlmostEqual(elapsed, 1.0, delta=0.5)
|
||||
|
||||
def test_dormi_timing_int_compiled(self):
|
||||
source = "DORMI(I)\n"
|
||||
lexer = Lexer().get_lexer()
|
||||
tokens = lexer.lex(source)
|
||||
program = Parser().parse(tokens)
|
||||
|
||||
c_source = compile_program(program)
|
||||
with tempfile.NamedTemporaryFile(suffix=".c", delete=False, mode="w") as tmp_c:
|
||||
tmp_c.write(c_source)
|
||||
tmp_c_path = tmp_c.name
|
||||
with tempfile.NamedTemporaryFile(suffix="", delete=False) as tmp_bin:
|
||||
tmp_bin_path = tmp_bin.name
|
||||
try:
|
||||
subprocess.run(
|
||||
["gcc", "-O2", tmp_c_path, _RUNTIME_C, "-o", tmp_bin_path],
|
||||
check=True, capture_output=True,
|
||||
)
|
||||
start = time.time()
|
||||
proc = subprocess.run([tmp_bin_path], capture_output=True, text=True)
|
||||
elapsed = time.time() - start
|
||||
self.assertEqual(proc.returncode, 0)
|
||||
self.assertAlmostEqual(elapsed, 1.0, delta=0.5)
|
||||
finally:
|
||||
os.unlink(tmp_c_path)
|
||||
os.unlink(tmp_bin_path)
|
||||
|
||||
def test_dormi_timing_frac(self):
|
||||
source = "CVM FRACTIO\nDORMI(S)\n"
|
||||
lexer = Lexer().get_lexer()
|
||||
tokens = lexer.lex(source)
|
||||
program = Parser().parse(tokens)
|
||||
|
||||
start = time.time()
|
||||
program.eval()
|
||||
elapsed = time.time() - start
|
||||
self.assertAlmostEqual(elapsed, 0.5, delta=0.5)
|
||||
|
||||
def test_dormi_timing_frac_compiled(self):
|
||||
source = "CVM FRACTIO\nDORMI(S)\n"
|
||||
lexer = Lexer().get_lexer()
|
||||
tokens = lexer.lex(source)
|
||||
program = Parser().parse(tokens)
|
||||
|
||||
c_source = compile_program(program)
|
||||
with tempfile.NamedTemporaryFile(suffix=".c", delete=False, mode="w") as tmp_c:
|
||||
tmp_c.write(c_source)
|
||||
tmp_c_path = tmp_c.name
|
||||
with tempfile.NamedTemporaryFile(suffix="", delete=False) as tmp_bin:
|
||||
tmp_bin_path = tmp_bin.name
|
||||
try:
|
||||
subprocess.run(
|
||||
["gcc", "-O2", tmp_c_path, _RUNTIME_C, "-o", tmp_bin_path],
|
||||
check=True, capture_output=True,
|
||||
)
|
||||
start = time.time()
|
||||
proc = subprocess.run([tmp_bin_path], capture_output=True, text=True)
|
||||
elapsed = time.time() - start
|
||||
self.assertEqual(proc.returncode, 0)
|
||||
self.assertAlmostEqual(elapsed, 0.5, delta=0.5)
|
||||
finally:
|
||||
os.unlink(tmp_c_path)
|
||||
os.unlink(tmp_bin_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user