shithub: mc

Download patch

ref: 966ededa0bd38d48d2759088e5a3f1ac583602e2
parent: beec45c577268917e3eee0454876b356c6f7249c
author: Ori Bernstein <[email protected]>
date: Thu Jan 23 13:45:53 EST 2014

Add and fix bigint tests.

    Division is hairy. Test it better.

--- a/test/bigint.myr
+++ b/test/bigint.myr
@@ -24,6 +24,7 @@
 	n = std.bigfmt(buf[:], a)
 	std.put("%s\n", buf[:n])
 
+	/* smoke test */
 	match std.bigparse("1234_5678_1234_6789_6666_7777_8888")
 	| `std.Some val: a = val
 	| `std.None: std.die("Failed to parse a\n")
@@ -34,9 +35,49 @@
 	;;
 
 	n = std.bigfmt(buf[:], a)
+	std.put("%s / ", buf[:n])
+	n = std.bigfmt(buf[:], b)
+	std.put("%s == ", buf[:n])
+
+	std.bigdiv(a, b)
+
+	n = std.bigfmt(buf[:], a)
 	std.put("%s\n", buf[:n])
+
+	/* no shifting */
+	match std.bigparse("0xffff_1234_1234_1234_1234")
+	| `std.Some val: a = val
+	| `std.None: std.die("Failed to parse a\n")
+	;;
+	match std.bigparse("0xf010_1234_2314")
+	| `std.Some val: b = val
+	| `std.None: std.die("Failed to parse b\n")
+	;;
+
+	n = std.bigfmt(buf[:], a)
+	std.put("%s / ", buf[:n])
 	n = std.bigfmt(buf[:], b)
+	std.put("%s == ", buf[:n])
+
+	std.bigdiv(a, b)
+
+	n = std.bigfmt(buf[:], a)
 	std.put("%s\n", buf[:n])
+
+	/* no shifting */
+	match std.bigparse("0xffff_1234_1234_1234_1234")
+	| `std.Some val: a = val
+	| `std.None: std.die("Failed to parse a\n")
+	;;
+	match std.bigparse("0x0ff_1234_2314")
+	| `std.Some val: b = val
+	| `std.None: std.die("Failed to parse b\n")
+	;;
+
+	n = std.bigfmt(buf[:], a)
+	std.put("%s / ", buf[:n])
+	n = std.bigfmt(buf[:], b)
+	std.put("%s == ", buf[:n])
 
 	std.bigdiv(a, b)
 
--- /dev/null
+++ b/test/data/bigint-expected
@@ -1,0 +1,4 @@
+517347321949036993306
+1234567812346789666677778888 / 123456781234678966667777 == 10000
+5192296858534810493479828944327220 / 1208925819597106013545236 == 4294967296
+5192296858534810493479828944327220 / 75557863709417659441940 == 68719476751
--- a/test/tests
+++ b/test/tests
@@ -116,7 +116,7 @@
 B strsplit	C
 B strfind	C
 B strjoin	C
-B bigint	P	517347321949036993306
+B bigint	C
 # B local-labels	E	10 ## BUGGERED
 F declmismatch
 F infermismatch