summaryrefslogtreecommitdiff
path: root/lib/std/test/bigint.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/test/bigint.myr')
-rw-r--r--lib/std/test/bigint.myr46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/std/test/bigint.myr b/lib/std/test/bigint.myr
index c87f1f3..d50b0ff 100644
--- a/lib/std/test/bigint.myr
+++ b/lib/std/test/bigint.myr
@@ -23,6 +23,7 @@ const main = {
[.name = "modulo", .fn = smokemod],
[.name = "add-negatives", .fn = addneg],
[.name = "sub-negatives", .fn = subneg],
+ [.name = "bigdivmod", .fn = somebigdivmod],
][:])
}
@@ -314,3 +315,48 @@ generic try = {x : std.option(@a)
| `std.None: std.die("failed to get val")
;;
}
+
+const somebigdivmod = {c
+ var inputs : (byte[:], byte[:], byte[:], byte[:])[:] = [
+ /* ( a, b, a/b, a%b), */
+ ("6185103187", "3519152458", "1", "2665950729"),
+ ("6980766832", "3087864937", "2", "805036958"),
+ ("4991855479", "6447381549", "0", "4991855479"),
+ ("6119892968", "8374603717", "0", "6119892968"),
+ ("7442542736", "5989044918", "1", "1453497818"),
+ ("4580939187", "4661174670", "0", "4580939187"),
+ ("4935237814", "3140079933", "1", "1795157881"),
+ ("1010425087", "446887574", "2", "116649939"),
+ ("1892124804", "4011235814", "0", "1892124804"),
+ ("2457899196", "1885658848", "1", "572240348"),
+ ("262030672", "1329267171", "0", "262030672"),
+ ("8430016289", "6215302855", "1", "2214713434"),
+ ("3347587073", "3855445301", "0", "3347587073"),
+ ("8014059310", "4622364950", "1", "3391694360"),
+ ("2934470708", "6439081239", "0", "2934470708"),
+ ("420917856", "5020252044", "0", "420917856"),
+ ("3862040257", "4601227994", "0", "3862040257"),
+ ("4439858911", "4387180962", "1", "52677949"),
+ ("165706876", "7452574618", "0", "165706876"),
+ ("268686047", "3047271875", "0", "268686047"),
+ ("83484791", "4899367309", "0", "83484791"),
+ ("1242378916", "4909326080", "0", "1242378916"),
+ ("980437482", "2305509838", "0", "980437482"),
+ ("118982655", "5051748984", "0", "118982655"),
+ ("8521162809", "2888108066", "2", "2744946677"),
+ ("4600797553", "7579789288", "0", "4600797553"),
+ ("5533774720", "3320264831", "1", "2213509889"),
+ ][:]
+
+ for (aS, bS, qS, rS) : inputs
+ var a = try(std.bigparse(aS))
+ var b = try(std.bigparse(bS))
+ var q_exp = try(std.bigparse(qS))
+ var r_exp = try(std.bigparse(rS))
+
+ var q_act, r_act
+ (q_act, r_act) = std.bigdivmod(a, b)
+ testr.check(c, std.bigeq(q_exp, q_act), "expected {} / {} to be {}, was {}", a, b, q_exp, q_act)
+ testr.check(c, std.bigeq(r_exp, r_act), "expected {} % {} to be {}, was {}", a, b, r_exp, r_act)
+ ;;
+}