Skip to content

Commit

Permalink
Separate Tests into one test file per mzn file
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidPratten committed Jan 4, 2023
1 parent 74de3ff commit 405e215
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 133 deletions.
2 changes: 1 addition & 1 deletion Birthday Money.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
" where age = 10\n",
" and birthday_money = 200;\n",
"\"\"\", 'data')\n",
" assert sorted_res(res) == sorted_res((('good_behaviour',), [(True,)]))\n"
" assert idr_test_res_sort(res) == idr_test_res_sort((('good_behaviour',), [(True,)]))\n"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ COPY jetisu/query_idr_magic.py /home/${NB_USER}/jetisu/
COPY jetisu/idr_query.py /home/${NB_USER}/jetisu/
COPY jetisu/*.mzn /home/${NB_USER}/jetisu/
COPY *.ipynb /home/${NB_USER}
COPY jetisu/test_idr_query.py /home/${NB_USER}/jetisu/
COPY jetisu/test_*.py /home/${NB_USER}/jetisu/
RUN rmdir /home/${NB_USER}/work
# Return to User level
USER ${NB_UID}
Expand Down
2 changes: 2 additions & 0 deletions jetisu/idr_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def idr_read_model(canonical_table_name):
with open('jetisu/' + canonical_table_name + '.mzn', 'r') as file:
return file.read()

def idr_test_res_sort(res):
return (res[0], sorted(res[1], key=lambda element: "".join([str(x) for x in element])))

def mzn_quote(k, v, typed_parameters_dict):
if typed_parameters_dict[k] == 'bool':
Expand Down
2 changes: 1 addition & 1 deletion jetisu/query_idr_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def jetisu_query(line, cell):
def jetisu_testcase(line, cell):
print("""def test_idr_""" + hashlib.sha1(cell.strip().encode()).hexdigest()[:10] + """():
res = idr_query(\"\"\"""" + cell + """\"\"\", 'data')
assert sorted_res(res) == sorted_res(""" + str(idr_query(cell, 'data')) + """)""")
assert idr_test_res_sort(res) == idr_test_res_sort(""" + str(idr_query(cell, 'data')) + """)""")


def jetisu_show(line, cell):
Expand Down
85 changes: 85 additions & 0 deletions jetisu/test_ACT_Conveyance_Duty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from jetisu.idr_query import idr_query, idr_test_res_sort


def test_idr_d750d38a4a():
res = idr_query("""select price, duty from ACT_Conveyance_Duty where price = 1200000 and eligible_owner_occupier;
""", 'data')
assert idr_test_res_sort(res) == idr_test_res_sort((('price', 'duty'), [(1200000.0, 47590)]))


def test_idr_0a5180a61c():
res = idr_query("""select price, duty from ACT_Conveyance_Duty where price = 1200000 and not non_commercial;
""", 'data')
assert idr_test_res_sort(res) == idr_test_res_sort((('price', 'duty'), [(1200000.0, 0.0)]))


def test_idr_65378a8e35():
res = idr_query("""select eligible_owner_occupier, duty
from ACT_Conveyance_Duty
where price = 1200000 and non_commercial;
""", 'data')
assert idr_test_res_sort(res) == idr_test_res_sort((('eligible_owner_occupier', 'duty'), [(True, 47590), (False, 49750)]))


def test_idr_347d205d95():
res = idr_query("""
select * from ACT_Conveyance_Duty where price = 1200000;
""", 'data')
assert idr_test_res_sort(res) == idr_test_res_sort((('non_commercial', 'eligible_owner_occupier', 'price', 'duty'),
[(False, False, 1200000.0, 0), (True, True, 1200000.0, 47590),
(True, False, 1200000.0, 49750)]))


def test_idr_689c1ce3d5():
res = idr_query("""
select * from ACT_Conveyance_Duty where price = 2000000;
""", 'data')
assert idr_test_res_sort(res) == idr_test_res_sort((('non_commercial', 'eligible_owner_occupier', 'price', 'duty'),
[(True, True, 2000000.0, 90800), (True, False, 2000000.0, 90800),
(False, False, 2000000.0, 100000)]))


def test_idr_4ab4e9269f():
res = idr_query("""
select price from ACT_Conveyance_Duty where duty = 50150 and eligible_owner_occupier;
""", 'data')
assert idr_test_res_sort(res) == idr_test_res_sort((('price',),
[(1240000,), (1239901,), (1239902,), (1239903,), (1239904,), (1239905,),
(1239906,), (1239907,), (1239908,), (1239909,), (1239910,), (1239911,),
(1239912,), (1239913,), (1239914,), (1239915,), (1239916,), (1239917,),
(1239918,), (1239919,), (1239920,), (1239921,), (1239922,), (1239923,),
(1239924,), (1239925,), (1239926,), (1239927,), (1239928,), (1239929,),
(1239930,), (1239931,), (1239932,), (1239933,), (1239934,), (1239935,),
(1239936,), (1239937,), (1239938,), (1239939,), (1239940,), (1239941,),
(1239942,), (1239943,), (1239944,), (1239945,), (1239946,), (1239947,),
(1239948,), (1239949,), (1239950,), (1239951,), (1239952,), (1239953,),
(1239954,), (1239955,), (1239956,), (1239957,), (1239958,), (1239959,),
(1239960,), (1239961,), (1239962,), (1239963,), (1239964,), (1239965,),
(1239966,), (1239967,), (1239968,), (1239969,), (1239970,), (1239971,),
(1239972,), (1239973,), (1239974,), (1239975,), (1239976,), (1239977,),
(1239978,), (1239979,), (1239980,), (1239981,), (1239982,), (1239983,),
(1239984,), (1239985,), (1239986,), (1239987,), (1239988,), (1239989,),
(1239990,), (1239991,), (1239992,), (1239993,), (1239994,), (1239995,),
(1239996,), (1239997,), (1239998,), (1239999,)]))


def test_idr_fe0f141905():
res = idr_query("""
select non_commercial,
eligible_owner_occupier,
min(price) min_price,
max(price) max_price
from ACT_Conveyance_Duty
where duty = 140740
group by non_commercial,
eligible_owner_occupier;
""", 'data')
assert idr_test_res_sort(res) == idr_test_res_sort((('non_commercial', 'eligible_owner_occupier', 'min_price', 'max_price'),
[(False, False, 2814701, 2814800), (True, False, 3099901, 3100000),
(True, True, 3099901, 3100000)]))


13 changes: 13 additions & 0 deletions jetisu/test_Australian_GST.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from jetisu.idr_query import idr_query, idr_test_res_sort

def test_idr_60cade641e():
res = idr_query("""select * from australian_gst where price = 110;
""", 'data')
assert idr_test_res_sort(res) == idr_test_res_sort((('price', 'ex_gst_amount', 'gst_amount'), [(110.0, 100.0, 10.0)]))


def test_idr_c46f0fe5f7():
res = idr_query("""select * from Australian_GST where price=100 and ex_gst_amount=1 and gst_amount=1;
""", 'data')
assert idr_test_res_sort(res) == idr_test_res_sort((('price', 'ex_gst_amount', 'gst_amount'), []))

Loading

0 comments on commit 405e215

Please sign in to comment.