summaryrefslogtreecommitdiff
path: root/src/test/lib/tests/test_div.sail
diff options
context:
space:
mode:
authorRobert Norton2017-07-19 18:08:02 +0100
committerRobert Norton2017-07-19 18:08:02 +0100
commit632b10c0d4b01dc1af8593b8ae1f088fbfd9e342 (patch)
treeac566808213125670da5f4dc3d702fe663333f7e /src/test/lib/tests/test_div.sail
parentd8969b1f9631dc15d5fb6b3b33a4a69dbfb7358a (diff)
split library tests into separate files to avoid risk of sail compiler stack overflow.
Diffstat (limited to 'src/test/lib/tests/test_div.sail')
-rw-r--r--src/test/lib/tests/test_div.sail39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/lib/tests/test_div.sail b/src/test/lib/tests/test_div.sail
new file mode 100644
index 00000000..1af58d20
--- /dev/null
+++ b/src/test/lib/tests/test_div.sail
@@ -0,0 +1,39 @@
+function unit test () = {
+ test_assert ("divpospos_exact", (21 div 7) == 3);
+ test_assert ("divposneg_exact", (21 div -7) == -3);
+ test_assert ("divnegpos_exact", (-21 div 7) == -3);
+ test_assert ("divnegneg_exact", (-21 div -7) == 3);
+
+ test_assert ("divpospos_approx", (21 div 8) == 2);
+ test_assert ("divposneg_approx", (21 div -8) == -2);
+ test_assert ("divnegpos_approx", (-21 div 8) == -2);
+ test_assert ("divnegneg_approx", (-21 div -8) == 2);
+
+ (* quot and div are synonyms but let's check... *)
+ test_assert ("quotpospos_exact", (21 quot 7) == 3);
+ test_assert ("quotposneg_exact", (21 quot -7) == -3);
+ test_assert ("quotnegpos_exact", (-21 quot 7) == -3);
+ test_assert ("quotnegneg_exact", (-21 quot -7) == 3);
+
+ test_assert ("quotpospos_approx", (21 quot 8) == 2);
+ test_assert ("quotposneg_approx", (21 quot -8) == -2);
+ test_assert ("quotnegpos_approx", (-21 quot 8) == -2);
+ test_assert ("quotnegneg_approx", (-21 quot -8) == 2);
+
+ (* XXX currently crashes on shallow embedding
+ test_assert ("div_overflow", ((bit[8])(0x80 quot_s 0xff)) == 0x80);
+ *)
+ test_assert ("quot_vec_pospos_exact", ((bit[8])(0x15 quot 0x07)) == 0x03);
+ test_assert ("quot_vec_posneg_exact", ((bit[8])(0x15 quot 0xf9)) == 0x00);
+ test_assert ("quot_vec_negpos_exact", ((bit[8])(0xeb quot 0x07)) == 0x21);
+ test_assert ("quot_vec_negneg_exact", ((bit[8])(0xeb quot 0xf9)) == 0x00);
+
+ test_assert ("quot_vec_pospos_approx", ((bit[8])(0x15 quot 0x08)) == 0x02);
+ test_assert ("quot_vec_posneg_approx", ((bit[8])(0x15 quot 0xf8)) == 0x00);
+ test_assert ("quot_vec_negpos_approx", ((bit[8])(0xeb quot 0x08)) == 0x1d);
+ test_assert ("quot_vec_negneg_approx", ((bit[8])(0xeb quot 0xf8)) == 0x00);
+
+ test_assert ("quot_overflow_vec", (((bit[8], bit, bit))(0x15 quot 0x08)) == (0x02, false, false));
+ test_assert ("quot_overflow_vec", (((bit[8], bit, bit))(0x80 quot 0xff)) == (0x00, false, false));
+}
+