Skip to content

Commit

Permalink
more exponentiation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Nov 9, 2024
1 parent f10bbf8 commit 8af675c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 22 deletions.
18 changes: 0 additions & 18 deletions tests/tests/src/exponentiation_precedence_test.mjs

This file was deleted.

4 changes: 0 additions & 4 deletions tests/tests/src/exponentiation_precedence_test.res

This file was deleted.

45 changes: 45 additions & 0 deletions tests/tests/src/exponentiation_test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Mt from "./mt.mjs";

let suites = {
contents: /* [] */0
};

let test_id = {
contents: 0
};

function eq(loc, x, y) {
Mt.eq_suites(test_id, suites, loc, x, y);
}

let intPow = ((a, b) => Math.pow(a, b) | 0);

eq("File \"exponentiation_test.res\", line 10, characters 5-12", 2 ** 3 ** 2, Math.pow(2, Math.pow(3, 2)));

eq("File \"exponentiation_test.res\", line 11, characters 5-12", 2 ** (-3) ** 2, Math.pow(2, Math.pow(-3, 2)));

eq("File \"exponentiation_test.res\", line 12, characters 5-12", (2 ** 3) ** 2, Math.pow(Math.pow(2, 3), 2));

eq("File \"exponentiation_test.res\", line 13, characters 5-12", (-2) ** 2, Math.pow(-2, 2));

eq("File \"exponentiation_test.res\", line 15, characters 5-12", 512, intPow(2, intPow(3, 2)));

eq("File \"exponentiation_test.res\", line 16, characters 5-12", 512, intPow(2, intPow(-3, 2)));

eq("File \"exponentiation_test.res\", line 17, characters 5-12", 64, intPow(intPow(2, 3), 2));

eq("File \"exponentiation_test.res\", line 18, characters 5-12", -2147483648, intPow(-2, 31));

eq("File \"exponentiation_test.res\", line 19, characters 5-12", 0, intPow(2, 32));

Mt.from_pair_suites("Exponentiation_test", suites.contents);

export {
suites,
test_id,
eq,
intPow,
}
/* Not a pure module */
22 changes: 22 additions & 0 deletions tests/tests/src/exponentiation_test.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let suites: ref<Mt.pair_suites> = ref(list{})
let test_id = ref(0)
let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y)

external jsPow: (float, float) => float = "Math.pow"

let intPow: (int, int) => int = %raw(`(a, b) => Math.pow(a, b) | 0`)

let () = {
eq(__LOC__, 2. ** 3. ** 2., jsPow(2., jsPow(3., 2.)))
eq(__LOC__, 2. ** -3. ** 2., jsPow(2., jsPow(-3., 2.)))
eq(__LOC__, (2. ** 3.) ** 2., jsPow(jsPow(2., 3.), 2.))
eq(__LOC__, -2. ** 2., jsPow(-2., 2.))

eq(__LOC__, 2 ** 3 ** 2, intPow(2, intPow(3, 2)))
eq(__LOC__, 2 ** -3 ** 2, intPow(2, intPow(-3, 2)))
eq(__LOC__, (2 ** 3) ** 2, intPow(intPow(2, 3), 2))
eq(__LOC__, -2 ** 31, intPow(-2, 31))
eq(__LOC__, 2 ** 32, intPow(2, 32))
}

let () = Mt.from_pair_suites(__MODULE__, suites.contents)

0 comments on commit 8af675c

Please sign in to comment.