diff --git a/TODO.md b/TODO.md index 57d8b536..d89380ff 100644 --- a/TODO.md +++ b/TODO.md @@ -73,6 +73,8 @@ ### Week 2: (30 Oct 23) +- [ ] Test on multiple py version +- [ ] Fixed size list support - [ ] Groover algorithm tests - [ ] Slideshow for UF midterm @@ -111,7 +113,7 @@ - [ ] Lambda - [ ] FixedList type - [ ] Builtin functions: map, count -- [ ] Ast2logic: fixed size loops unrolling +- [x] Ast2logic: fixed size loops unrolling - [ ] Builtin functions: sum(), all(), any() - [ ] First beta release @@ -127,7 +129,7 @@ - [ ] Datatype: Fixed - [ ] Datatype: Enum - [ ] While loop -- [ ] For loop +- [x] For loop - [ ] Recursion - [ ] Parameter bind diff --git a/test/test_qlassf.py b/test/test_qlassf.py index c9dcfcb8..8a814390 100644 --- a/test/test_qlassf.py +++ b/test/test_qlassf.py @@ -14,6 +14,8 @@ import unittest +from parameterized import parameterized_class + from qlasskit import Qint, Qint4, Qint12, QlassF, exceptions, qlassf from . import utils @@ -26,17 +28,29 @@ def test_decorator(self): self.assertTrue(isinstance(c, QlassF)) +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestQlassfCustomTypes(unittest.TestCase): def test_custom_qint3(self): qf = qlassf( - utils.test_qint3, types=[utils.Qint3], to_compile=COMPILATION_ENABLED + utils.test_qint3, + types=[utils.Qint3], + to_compile=COMPILATION_ENABLED, + compiler=self.compiler, ) compute_and_compare_results(self, qf) def test_custom_qint3_notfound(self): self.assertRaises( exceptions.UnknownTypeException, - lambda f: qlassf(f, types=[], to_compile=COMPILATION_ENABLED), + lambda f: qlassf( + f, types=[], to_compile=COMPILATION_ENABLED, compiler=self.compiler + ), utils.test_qint3, ) diff --git a/test/test_qlassf_bool.py b/test/test_qlassf_bool.py index b9dfc36f..b033cd9e 100644 --- a/test/test_qlassf_bool.py +++ b/test/test_qlassf_bool.py @@ -14,6 +14,7 @@ import unittest +from parameterized import parameterized_class from sympy import Symbol, symbols from sympy.logic import ITE, And, Not, Or, false, simplify_logic, true @@ -25,6 +26,13 @@ _ret = Symbol("_ret") +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestQlassfBoolean(unittest.TestCase): def test_unbound(self): f = "def test() -> bool:\n\treturn a" @@ -40,7 +48,7 @@ def test_no_return_type(self): def test_bool_const(self): f = "def test(a: bool) -> bool:\n\tc=True\n\treturn c" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], True) @@ -49,7 +57,7 @@ def test_bool_const(self): def test_arg_identity(self): ex = a f = "def test(a: bool) -> bool:\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], ex) @@ -58,7 +66,7 @@ def test_arg_identity(self): def test_not_arg(self): ex = Not(a) f = "def test(a: bool) -> bool:\n\treturn not a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], ex) @@ -67,7 +75,7 @@ def test_not_arg(self): def test_and(self): ex = And(Not(a), b) f = "def test(a: bool, b: bool) -> bool:\n\treturn not a and b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], ex) @@ -75,14 +83,14 @@ def test_and(self): def test_bool_eq(self): f = "def test(a: bool, b: bool) -> bool:\n\treturn a == b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) def test_bool_neq(self): f = "def test(a: bool, b: bool) -> bool:\n\treturn a != b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) @@ -90,7 +98,7 @@ def test_bool_neq(self): def test_or_not(self): ex = Or(Not(a), b) f = "def test(a: bool, b: bool) -> bool:\n\treturn not a or b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], ex) @@ -99,7 +107,7 @@ def test_or_not(self): def test_multiple_arg(self): ex = And(a, And(Not(b), c)) f = "def test(a: bool, b: bool, c: bool) -> bool:\n\treturn a and (not b) and c" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], ex) @@ -108,7 +116,7 @@ def test_multiple_arg(self): def test_multiple_arg2(self): ex = And(a, And(Not(b), Or(a, c))) f = "def test(a: bool, b: bool, c: bool) -> bool:\n\treturn a and (not b) and (a or c)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], ex) @@ -117,7 +125,7 @@ def test_multiple_arg2(self): def test_ifexp(self): ex = ITE(a, true, false) f = "def test(a: bool) -> bool:\n\treturn True if a else False" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], ex) @@ -126,7 +134,7 @@ def test_ifexp(self): def test_ifexp2(self): ex = ITE(And(a, And(Not(b), c)), true, false) f = "def test(a: bool, b: bool, c: bool) -> bool:\n\treturn True if a and (not b) and c else False" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], ex) @@ -142,7 +150,7 @@ def test_ifexp3(self): "def test(a: bool, b: bool, c: bool) -> bool:\n" + "\treturn (c and not b) if a and ((not b) and c) else (a and not c)" ) - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], exp) @@ -150,7 +158,7 @@ def test_ifexp3(self): def test_assign(self): f = "def test(a: bool, b: bool) -> bool:\n\tc = a and b\n\treturn c" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], And(a, b)) @@ -162,7 +170,7 @@ def test_assign2(self): + "\td = a and (not b) and c\n" + "\treturn True if d else False" ) - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][1], And(a, And(Not(b), c))) self.assertEqual(qf.expressions[0][0], _ret) @@ -177,7 +185,7 @@ def test_assign3(self): + "\th = (not a) and b and (not c)\n" + "\treturn g if d and e else h" ) - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 5) self.assertEqual(qf.expressions[-1][1], ITE(d & e, g, h)) compute_and_compare_results(self, qf) @@ -197,18 +205,25 @@ def test_assign3(self): # self.assertEqual(qf.expressions[-1][1], ITE(d & e, g, h)) +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestQlassfBoolBitwise(unittest.TestCase): def test_bitwise_and(self): f = f"def test(a: bool, b: bool) -> bool:\n\treturn a & b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_bitwise_or(self): f = f"def test(a: bool, b: bool) -> bool:\n\treturn a | b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_bitwise_xor(self): f = f"def test(a: bool, b: bool) -> bool:\n\treturn a ^ b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_qlassf_builtin.py b/test/test_qlassf_builtin.py index 0ffc837e..5ca0ae81 100644 --- a/test/test_qlassf_builtin.py +++ b/test/test_qlassf_builtin.py @@ -15,6 +15,7 @@ import unittest from typing import Tuple +from parameterized import parameterized_class from sympy import Symbol, symbols from sympy.logic import ITE, And, Not, Or, false, simplify_logic, true @@ -23,30 +24,37 @@ from .utils import COMPILATION_ENABLED, compute_and_compare_results +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestQlassfBuiltinFunctions(unittest.TestCase): def test_print_call(self): f = "def test(a: bool) -> bool:\n\tprint(a)\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) compute_and_compare_results(self, qf) def test_len(self): f = "def test(a: Tuple[bool, bool]) -> Qint2:\n\treturn len(a)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(qf.expressions[0][1], False) self.assertEqual(qf.expressions[1][1], True) compute_and_compare_results(self, qf) def test_len2(self): f = "def test(a: Tuple[bool, bool]) -> Qint2:\n\tc=a\n\treturn len(c)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(qf.expressions[-2][1], False) self.assertEqual(qf.expressions[-1][1], True) compute_and_compare_results(self, qf) def test_len4(self): f = "def test(a: Tuple[bool, bool, bool, bool]) -> Qint4:\n\treturn len(a)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(qf.expressions[0][1], False) self.assertEqual(qf.expressions[1][1], False) self.assertEqual(qf.expressions[2][1], True) @@ -55,41 +63,41 @@ def test_len4(self): def test_min(self): f = "def test(a: Qint2, b: Qint2) -> Qint2:\n\treturn min(a,b)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_min_const(self): f = "def test(a: Qint2) -> Qint2:\n\treturn min(a,3)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_max(self): f = "def test(a: Qint2, b: Qint2) -> Qint2:\n\treturn max(a,b)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_max_of3(self): f = "def test(a: Qint2, b: Qint2) -> Qint2:\n\treturn max(a,b,3)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_max_const(self): f = "def test(a: Qint2) -> Qint2:\n\treturn max(a,3)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) # TODO: fixed by cast # def test_max_const2(self): # f = "def test(a: Qint4) -> Qint2:\n\treturn max(a,3)" - # qf = qlassf(f, to_compile=COMPILATION_ENABLED) + # qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) # compute_and_compare_results(self, qf) def test_max_tuple(self): f = "def test(a: Tuple[Qint2, Qint2]) -> Qint2:\n\treturn max(a)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_max_tuple_const(self): f = "def test(a: Qint2, b: Qint2) -> Qint2:\n\treturn max((a, b))" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_qlassf_for_loop.py b/test/test_qlassf_for_loop.py index 716ee010..7800acea 100644 --- a/test/test_qlassf_for_loop.py +++ b/test/test_qlassf_for_loop.py @@ -26,40 +26,47 @@ _ret = Symbol("_ret") +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestForLoop(unittest.TestCase): def test_for_1it(self): f = "def test(a: Qint2) -> Qint2:\n\tfor x in range(1):\n\t\ta += 1\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_for_4it(self): f = "def test(a: Qint2) -> Qint2:\n\tfor x in range(4):\n\t\ta += 1\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_for_3it(self): f = "def test(a: Qint2) -> Qint2:\n\tfor i in range(3):\n\t\ta += i\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_for_nit_bool(self): f = "def test(a: bool) -> bool:\n\tfor i in range(4):\n\t\ta = not a\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_for_nit_bool_many(self): f = "def test(a: bool) -> bool:\n\tfor i in range(15):\n\t\ta = not a\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) # def test_for_nit_tbool_many(self): # f = "def test(a: Tuple[bool,bool]) -> Tuple[bool,bool]:\n\tfor i in range(32):\n\t\ta[0] = not a[0]\n\t\ta[1] = not a[1]\n\treturn a" - # qf = qlassf(f, to_compile=COMPILATION_ENABLED) + # qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) # compute_and_compare_results(self, qf) def test_for_cond(self): f = "def test(a: Qint2, b: bool) -> Qint2:\n\tfor i in range(2):\n\t\ta += (i if b else 1)\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_qlassf_functiondef.py b/test/test_qlassf_functiondef.py index f645ce0a..ef10d751 100644 --- a/test/test_qlassf_functiondef.py +++ b/test/test_qlassf_functiondef.py @@ -15,6 +15,7 @@ import unittest from typing import Tuple +from parameterized import parameterized_class from sympy import Symbol, symbols from sympy.logic import ITE, And, Not, Or, false, simplify_logic, true @@ -23,11 +24,18 @@ from .utils import COMPILATION_ENABLED, compute_and_compare_results +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestQlassfFunctionDef(unittest.TestCase): def test_pass_another_function(self): f = "def neg(b: bool) -> bool:\n\treturn not b" g = "def test(a: bool) -> bool:\n\treturn neg(a)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) qg = qlassf(g, to_compile=COMPILATION_ENABLED, defs=[qf]) compute_and_compare_results(self, qf) compute_and_compare_results(self, qg, test_original_f=False) @@ -35,7 +43,7 @@ def test_pass_another_function(self): def test_pass_multiarg_function(self): f = "def neg(b: bool, c: bool) -> bool:\n\treturn not b and c" g = "def test(a: bool, ff: bool) -> bool:\n\treturn neg(a, ff)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) qg = qlassf(g, to_compile=COMPILATION_ENABLED, defs=[qf]) compute_and_compare_results(self, qf) compute_and_compare_results(self, qg, test_original_f=False) @@ -43,7 +51,7 @@ def test_pass_multiarg_function(self): def test_pass_tuplearg_function(self): f = "def neg(b: Tuple[bool, bool]) -> bool:\n\treturn not b[0] and b[1]" g = "def test(a: bool, ff: bool) -> bool:\n\treturn neg((a, ff))" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) qg = qlassf(g, to_compile=COMPILATION_ENABLED, defs=[qf]) compute_and_compare_results(self, qf) compute_and_compare_results(self, qg, test_original_f=False) @@ -51,7 +59,7 @@ def test_pass_tuplearg_function(self): def test_pass_multires_function(self): f = "def neg(b: bool) -> Tuple[bool, bool]:\n\treturn (not b, b)" g = "def test(a: bool) -> bool:\n\tc = neg(a)\n\treturn c[0]" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) qg = qlassf(g, to_compile=COMPILATION_ENABLED, defs=[qf]) compute_and_compare_results(self, qf) compute_and_compare_results(self, qg, test_original_f=False) @@ -59,7 +67,7 @@ def test_pass_multires_function(self): def test_pass_multi_stmt_function(self): f = "def neg(b: bool) -> bool:\n\tc=not b\n\td=not c\n\treturn d" g = "def test(a: bool) -> bool:\n\treturn neg(a)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) qg = qlassf(g, to_compile=COMPILATION_ENABLED, defs=[qf]) compute_and_compare_results(self, qf) compute_and_compare_results(self, qg, test_original_f=False) @@ -69,5 +77,5 @@ def test_inner_function(self): def test2(b:bool) -> bool: return not b return test2(a)""" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_qlassf_int.py b/test/test_qlassf_int.py index b0aa1edb..7fd644d9 100644 --- a/test/test_qlassf_int.py +++ b/test/test_qlassf_int.py @@ -39,17 +39,19 @@ def test_qint2_to_bin(self): @parameterized_class( - ("ttype", "ttype_str", "ttype_size"), + ("ttype", "ttype_str", "ttype_size", "compiler"), [ - (Qint2, "Qint2", 2), - (Qint4, "Qint4", 4), + (Qint2, "Qint2", 2, "internal"), + (Qint4, "Qint4", 4, "internal"), + (Qint2, "Qint2", 2, "tweedledum"), + (Qint4, "Qint4", 4, "tweedledum"), # (Qint8, "Qint8", 8), ], ) class TestQlassfIntParametrized_2_4_8(unittest.TestCase): def test_int_arg(self): f = f"def test(a: {self.ttype_str}) -> bool:\n\treturn a[0]" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], Symbol("a.0")) @@ -57,7 +59,7 @@ def test_int_arg(self): def test_int_arg2(self): f = f"def test(a: {self.ttype_str}, b: bool) -> bool:\n\treturn a[1] if (a[0] and b) else a[0]" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual( @@ -74,13 +76,13 @@ def test_int_arg_unbound_index(self): def test_int_return_tuple(self): f = f"def test(a: {self.ttype_str}) -> Tuple[{self.ttype_str}, bool]:\n\tb = a[0] and a[1]\n\treturn (a, b)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), self.ttype_size + 2) compute_and_compare_results(self, qf) def test_int_tuple(self): f = f"def test(a: Tuple[{self.ttype_str}, {self.ttype_str}]) -> bool:\n\treturn a[0][0] and a[1][1]" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], And(Symbol("a.0.0"), Symbol("a.1.1"))) @@ -88,7 +90,7 @@ def test_int_tuple(self): def test_int_identity(self): f = f"def test(a: {self.ttype_str}) -> {self.ttype_str}:\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), self.ttype_size) for i in range(self.ttype_size): self.assertEqual(qf.expressions[i][0], Symbol(f"_ret.{i}")) @@ -97,53 +99,62 @@ def test_int_identity(self): def test_int_const_compare_eq(self): f = f"def test(a: {self.ttype_str}) -> bool:\n\treturn a == {int(self.ttype_size/2-1)}" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) @parameterized_class( - ("ttype", "ttype_str", "ttype_size"), + ("ttype", "ttype_str", "ttype_size", "compiler"), [ - (Qint2, "Qint2", 2), - (Qint4, "Qint4", 4), + (Qint2, "Qint2", 2, "internal"), + (Qint4, "Qint4", 4, "internal"), + (Qint2, "Qint2", 2, "tweedledum"), + (Qint4, "Qint4", 4, "tweedledum"), ], ) class TestQlassfIntParametrized_2_4(unittest.TestCase): def test_int_int_compare_eq(self): f = f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> bool:\n\treturn a == b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) def test_int_int_compare_neq(self): f = f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> bool:\n\treturn a != b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) def test_const_int_compare_gt(self): f = f"def test(a: {self.ttype_str}) -> bool:\n\treturn a > 1" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) def test_const_int_compare_lt(self): f = f"def test(a: {self.ttype_str}) -> bool:\n\treturn a < 2" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestQlassfInt(unittest.TestCase): def test_int_const(self): f = "def test(a: Qint2) -> Qint2:\n\tc=2\n\treturn c" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 2) self.assertEqual(qf.expressions[-2][1], False) self.assertEqual(qf.expressions[-1][1], True) @@ -151,7 +162,7 @@ def test_int_const(self): def test_int_const_compare_eq(self): f = "def test(a: Qint2) -> bool:\n\treturn a == 2" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], And(Symbol("a.1"), Not(Symbol("a.0")))) @@ -159,7 +170,7 @@ def test_int_const_compare_eq(self): def test_int_const_compare_eq_different_type(self): f = "def test(a: Qint4) -> bool:\n\treturn a == 2" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual( @@ -175,7 +186,7 @@ def test_int_const_compare_eq_different_type(self): def test_const_int_compare_eq_different_type(self): f = "def test(a: Qint4) -> bool:\n\treturn 2 == a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual( @@ -191,7 +202,7 @@ def test_const_int_compare_eq_different_type(self): def test_const_int_compare_neq_different_type(self): f = "def test(a: Qint4) -> bool:\n\treturn 2 != a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual( @@ -207,7 +218,7 @@ def test_const_int_compare_neq_different_type(self): def test_int_int_compare_neq(self): f = "def test(a: Qint2, b: Qint2) -> bool:\n\treturn a != b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual( @@ -221,56 +232,56 @@ def test_int_int_compare_neq(self): def test_const_int_compare_gt(self): f = f"def test(a: Qint4) -> bool:\n\treturn a > 6" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) # def test_int4_int4_compare_gt(self): # f = "def test(a: Qint4, b: Qint4) -> bool:\n\treturn a > b" - # qf = qlassf(f, to_compile=COMPILATION_ENABLED) + # qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) # self.assertEqual(len(qf.expressions), 1) # self.assertEqual(qf.expressions[0][0], _ret) # compute_and_compare_results(self, qf) def test_const_int4_compare_lt(self): f = "def test(a: Qint4) -> bool:\n\treturn a < 6" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) def test_int_int_compare_gt(self): f = "def test(a: Qint2, b: Qint2) -> bool:\n\treturn a > b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) def test_int_int_compare_lt(self): f = "def test(a: Qint2, b: Qint2) -> bool:\n\treturn a < b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) def test_const_int_compare_gte(self): f = "def test(a: Qint2, b: Qint2) -> bool:\n\treturn a >= b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) def test_const_int_compare_lte(self): f = "def test(a: Qint2, b: Qint2) -> bool:\n\treturn a <= b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) compute_and_compare_results(self, qf) def test_ite_return_qint(self): f = "def test(a: bool, b: Qint2, c: Qint2) -> Qint2:\n\treturn b if a else c" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 2) self.assertEqual(qf.expressions[0][0], Symbol("_ret.0")) self.assertEqual(qf.expressions[0][1], ITE(a, Symbol("b.0"), Symbol("c.0"))) @@ -280,117 +291,140 @@ def test_ite_return_qint(self): def test_composed_comparators(self): f = "def f_comp(n: Qint4) -> bool: return n > 3 or n == 7" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_shift_left(self): f = "def test(n: Qint2) -> Qint4: return n << 1" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_shift_right(self): f = "def test(n: Qint2) -> Qint4: return n >> 1" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) # Our Qint are unsigned # def test_invert_bitwise_not(self): # f = "def test(n: Qint4) -> bool: return ~n" - # qf = qlassf(f, to_compile=COMPILATION_ENABLED) + # qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) # compute_and_compare_results(self, qf) # TODO: parameterize +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestQlassfIntAdd(unittest.TestCase): def test_add_tuple(self): f = "def test(a: Tuple[Qint2, Qint2]) -> Qint2: return a[0] + a[1]" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_add(self): f = "def test(a: Qint2, b: Qint2) -> Qint2: return a + b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_add_const(self): f = "def test(a: Qint2) -> Qint2: return a + 1" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_add_const2(self): f = "def test() -> Qint4: return Qint4(3) + 3" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_add_const3(self): f = "def test(a: Qint2, b: Qint2) -> Qint4: return Qint4(3) + a if a == 3 else Qint4(1) + b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_add_const4(self): f = "def test(a: Qint2) -> Qint2: return a + 2" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestQlassfIntSub(unittest.TestCase): def test_sub_const(self): f = "def test(a: Qint2) -> Qint2: return a - 1" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_sub_const2(self): f = "def test(a: Qint2) -> Qint2: return a - 3" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_sub_const3(self): f = "def test(a: Qint4) -> Qint4: return a - 8" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) @parameterized_class( - ("ttype", "ttype_str", "ttype_size"), + ("ttype", "ttype_str", "ttype_size", "compiler"), [ - (Qint2, "Qint2", 2), - (Qint4, "Qint4", 4), + (Qint2, "Qint2", 2, "internal"), + (Qint4, "Qint4", 4, "internal"), + (Qint2, "Qint2", 2, "tweedledum"), + (Qint4, "Qint4", 4, "tweedledum"), ], ) class TestQlassfIntBitwise(unittest.TestCase): def test_bitwise_and(self): f = f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> {self.ttype_str}:\n\treturn a & b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_bitwise_or(self): f = f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> {self.ttype_str}:\n\treturn a | b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_bitwise_xor(self): f = f"def test(a: {self.ttype_str}, b: {self.ttype_str}) -> {self.ttype_str}:\n\treturn a ^ b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestQlassfIntReassign(unittest.TestCase): def test_reassign_newvar(self): f = "def test(a: Qint2) -> Qint2:\n\tb = 0\n\tb = a + 1\n\treturn b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_reassign_arg(self): f = "def test(a: Qint2) -> Qint2:\n\ta = a + 1\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_aug_reassign_newvar(self): f = "def test(a: Qint2) -> Qint2:\n\tb = a\n\tb += 1\n\treturn b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_aug_reassign_arg(self): f = "def test(a: Qint2) -> Qint2:\n\ta += 1\n\treturn a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) diff --git a/test/test_qlassf_tuple.py b/test/test_qlassf_tuple.py index 79724813..d333058f 100644 --- a/test/test_qlassf_tuple.py +++ b/test/test_qlassf_tuple.py @@ -15,6 +15,7 @@ import unittest from typing import Tuple +from parameterized import parameterized_class from sympy import Symbol, symbols from sympy.logic import ITE, And, Not, Or, false, simplify_logic, true @@ -30,15 +31,22 @@ b_1 = Symbol("b.1") +@parameterized_class( + ("compiler"), + [ + ("internal",), + ("tweedledum",), + ], +) class TestQlassfTuple(unittest.TestCase): def test_tuple_const(self): f = "def test() -> Tuple[bool, bool]:\n\treturn (True, True)" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_tuple_arg(self): f = "def test(a: Tuple[bool, bool]) -> bool:\n\treturn a[0] and a[1]" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual(qf.expressions[0][1], And(a_0, a_1)) @@ -46,7 +54,7 @@ def test_tuple_arg(self): def test_tuple_ite(self): f = "def test(b: bool, a: Tuple[bool, bool]) -> Tuple[bool,bool]:\n\treturn (a[1],a[0]) if b else a" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 2) self.assertEqual(qf.expressions[0][1], ITE(b, a_1, a_0)) self.assertEqual(qf.expressions[1][1], ITE(b, a_0, a_1)) @@ -59,7 +67,7 @@ def test_tuple_arg_assign(self): + "\tc = a[1]\n" + "\treturn b and c" ) - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 3) self.assertEqual(qf.expressions[-1][0], _ret) self.assertEqual(qf.expressions[-1][1], And(b, c)) @@ -67,7 +75,7 @@ def test_tuple_arg_assign(self): def test_tuple_of_tuple_arg(self): f = "def test(a: Tuple[Tuple[bool, bool], bool]) -> bool:\n\treturn a[0][0] and a[0][1] and a[1]" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual( @@ -80,7 +88,7 @@ def test_tuple_of_tuple_of_tuple_arg(self): "def test(a: Tuple[Tuple[Tuple[bool, bool], bool], bool]) -> bool:\n" + "\treturn a[0][0][0] and a[0][0][1] and a[0][1] and a[1]" ) - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 1) self.assertEqual(qf.expressions[0][0], _ret) self.assertEqual( @@ -91,7 +99,7 @@ def test_tuple_of_tuple_of_tuple_arg(self): def test_tuple_assign(self): f = "def test(a: Tuple[bool, bool]) -> bool:\n\tb = (a[1],a[0])\n\treturn b[0] and b[1]" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 3) self.assertEqual(qf.expressions[-1][0], _ret) self.assertEqual(qf.expressions[-1][1], And(b_0, b_1)) @@ -103,7 +111,7 @@ def test_tuple_assign2(self): + "\tb = (a[0][1],a[0][0],a[1])\n" + "\treturn b[0] and b[1] and b[2]" ) - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 4) self.assertEqual(qf.expressions[-1][0], _ret) self.assertEqual(qf.expressions[-1][1], And(b_0, And(b_1, Symbol("b.2")))) @@ -115,7 +123,7 @@ def test_tuple_assign3(self): + "\tb = (a[0][1],(a[0][0],a[1]))\n" + "\treturn b[0] and b[1][0] and b[1][1]" ) - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 4) self.assertEqual(qf.expressions[-1][0], _ret) self.assertEqual( @@ -125,22 +133,22 @@ def test_tuple_assign3(self): def test_multi_assign(self): f = "def test(a: bool) -> bool:\n\tc, d = a, not a\n\treturn c and d" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_multi_assign2(self): f = "def test() -> Qint4:\n\tc, d = 1, 2\n\treturn c+d" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_multi_assign3(self): f = "def test() -> Qint4:\n\tc, d, e = 1, 2, 0xa\n\treturn c+d+e" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_tuple_result(self): f = "def test(a: bool, b: bool) -> Tuple[bool,bool]:\n\treturn a,b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) self.assertEqual(len(qf.expressions), 2) self.assertEqual(qf.expressions[0][0], Symbol("_ret.0")) self.assertEqual(qf.expressions[0][1], a) @@ -150,10 +158,10 @@ def test_tuple_result(self): def test_tuple_compare(self): f = "def test(a: Tuple[bool, bool], b: Tuple[bool, bool]) -> bool:\n\treturn a == b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf) def test_tuple_int_compare(self): f = "def test(a: Tuple[Qint2, Qint2], b: Tuple[Qint2, Qint2]) -> bool:\n\treturn a == b" - qf = qlassf(f, to_compile=COMPILATION_ENABLED) + qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler) compute_and_compare_results(self, qf)