summaryrefslogtreecommitdiff
path: root/src/test/lib/tests/test_div.sail
diff options
context:
space:
mode:
authorAlasdair Armstrong2017-07-26 14:12:09 +0100
committerAlasdair Armstrong2017-07-26 14:12:09 +0100
commit678ab0e23ba4a8d95010df2bd2467dae7d544e29 (patch)
tree0b2e02773327b9483f24b2e1ad46b7235ec9633e /src/test/lib/tests/test_div.sail
parent26e59493cde0ffbf1868426fe3bec158f2dbaad0 (diff)
parent18cf235fad35a0e06e26ea91ee0e1c673febddb8 (diff)
Merge remote-tracking branch 'origin/master' into sail_new_tc
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));
+}
+