Skip to content

Instantly share code, notes, and snippets.

@thejoshwolfe
Created September 27, 2017 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejoshwolfe/655728bcbef31bdf60b71a7e61202336 to your computer and use it in GitHub Desktop.
Save thejoshwolfe/655728bcbef31bdf60b71a7e61202336 to your computer and use it in GitHub Desktop.
function assertSameValue(result, expected, resultStr) {
if (result === expected) return;
$ERROR("Expected (" + resultStr + ") to be " + expected + " but it was " + result);
}
function compare(a, aStr, b, bStr, cmp) {
assertSameValue(a < b, cmp < 0, aStr + " < " + bStr);
assertSameValue(a <= b, cmp <= 0, aStr + " <= " + bStr);
assertSameValue(a > b, cmp > 0, aStr + " > " + bStr);
assertSameValue(a >= b, cmp >= 0, aStr + " >= " + bStr);
assertSameValue(b < a, 0 < cmp, aStr + " < " + bStr);
assertSameValue(b <= a, 0 <= cmp, aStr + " <= " + bStr);
assertSameValue(b > a, 0 > cmp, aStr + " > " + bStr);
assertSameValue(b >= a, 0 >= cmp, aStr + " >= " + bStr);
}
compare(1n, "1n", 0, "0", 1);
compare(1n, "1n", 0.999999999999, "0.999999999999", 1);
compare(1, "1", 0n, "0n", 1);
compare(0.000000000001, "0.000000000001", 0n, "0n", 1);
compare(1n, "1n", 1, "1", 0);
compare(1, "1", 1n, "1n", 0);
compare(0n, "0n", 1, "1", -1);
compare(0, "0", 1n, "1n", -1);
compare(0, "0", 0n, "0n", 0);
compare(0n, "0n", 0, "0", 0);
compare(1n, "1n", Number.MAX_VALUE, "Number.MAX_VALUE", -1);
compare(Number.MIN_VALUE, "Number.MIN_VALUE", 0n, "0n", -1);
compare(-10n, "-10n", Number.MIN_VALUE, "Number.MIN_VALUE", 1);
compare(Number.MAX_VALUE, "Number.MAX_VALUE", 10000000000n, "10000000000n", 1);
uncaught exception: Test262Error: Expected (Number.MIN_VALUE < 0n) to be true but it was false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment