Skip to content

Commit

Permalink
Equality comparison tests for bigint (#1257)
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoshwolfe authored and leobalter committed Oct 4, 2017
1 parent b006e1c commit 6443289
Show file tree
Hide file tree
Showing 32 changed files with 1,243 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/language/expressions/does-not-equals/bigint-and-bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Non-strict inequality comparison of BigInt values
esid: sec-abstract-equality-comparison
info: |
1. If Type(x) is the same as Type(y), then
a. Return the result of performing Strict Equality Comparison x === y.
sec-numeric-types-bigint-equal
BigInt::equal (x, y)
The abstract operation BigInt::equal with two arguments x and y of BigInt type returns true if x and y have the same mathematical integer value and false otherwise.
features: [BigInt]
---*/

assert.sameValue(0n != 0n, false, "0n != 0n");
assert.sameValue(1n != 1n, false, "1n != 1n");
assert.sameValue(-1n != -1n, false, "-1n != -1n");
assert.sameValue(0n != -0n, false, "0n != -0n");
assert.sameValue(-0n != 0n, false, "-0n != 0n");
assert.sameValue(0n != 1n, true, "0n != 1n");
assert.sameValue(1n != 0n, true, "1n != 0n");
assert.sameValue(0n != -1n, true, "0n != -1n");
assert.sameValue(-1n != 0n, true, "-1n != 0n");
assert.sameValue(1n != -1n, true, "1n != -1n");
assert.sameValue(-1n != 1n, true, "-1n != 1n");
assert.sameValue(0x1fffffffffffff01n != 0x1fffffffffffff01n, false, "0x1fffffffffffff01n != 0x1fffffffffffff01n");
assert.sameValue(0x1fffffffffffff01n != 0x1fffffffffffff02n, true, "0x1fffffffffffff01n != 0x1fffffffffffff02n");
assert.sameValue(0x1fffffffffffff02n != 0x1fffffffffffff01n, true, "0x1fffffffffffff02n != 0x1fffffffffffff01n");
assert.sameValue(-0x1fffffffffffff01n != -0x1fffffffffffff01n, false, "-0x1fffffffffffff01n != -0x1fffffffffffff01n");
assert.sameValue(-0x1fffffffffffff01n != -0x1fffffffffffff02n, true, "-0x1fffffffffffff01n != -0x1fffffffffffff02n");
assert.sameValue(-0x1fffffffffffff02n != -0x1fffffffffffff01n, true, "-0x1fffffffffffff02n != -0x1fffffffffffff01n");
assert.sameValue(0x10000000000000000n != 0n, true, "0x10000000000000000n != 0n");
assert.sameValue(0n != 0x10000000000000000n, true, "0n != 0x10000000000000000n");
assert.sameValue(0x10000000000000000n != 1n, true, "0x10000000000000000n != 1n");
assert.sameValue(1n != 0x10000000000000000n, true, "1n != 0x10000000000000000n");
assert.sameValue(0x10000000000000000n != -1n, true, "0x10000000000000000n != -1n");
assert.sameValue(-1n != 0x10000000000000000n, true, "-1n != 0x10000000000000000n");
assert.sameValue(0x10000000000000001n != 0n, true, "0x10000000000000001n != 0n");
assert.sameValue(0n != 0x10000000000000001n, true, "0n != 0x10000000000000001n");
assert.sameValue(-0x10000000000000000n != 0n, true, "-0x10000000000000000n != 0n");
assert.sameValue(0n != -0x10000000000000000n, true, "0n != -0x10000000000000000n");
assert.sameValue(-0x10000000000000000n != 1n, true, "-0x10000000000000000n != 1n");
assert.sameValue(1n != -0x10000000000000000n, true, "1n != -0x10000000000000000n");
assert.sameValue(-0x10000000000000000n != -1n, true, "-0x10000000000000000n != -1n");
assert.sameValue(-1n != -0x10000000000000000n, true, "-1n != -0x10000000000000000n");
assert.sameValue(-0x10000000000000001n != 0n, true, "-0x10000000000000001n != 0n");
assert.sameValue(0n != -0x10000000000000001n, true, "0n != -0x10000000000000001n");
assert.sameValue(0x10000000000000000n != 0x100000000n, true, "0x10000000000000000n != 0x100000000n");
assert.sameValue(0x100000000n != 0x10000000000000000n, true, "0x100000000n != 0x10000000000000000n");
33 changes: 33 additions & 0 deletions test/language/expressions/does-not-equals/bigint-and-boolean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Non-strict inequality comparison of BigInt and Boolean values
esid: sec-abstract-equality-comparison
info: |
8. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
9. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
...
12. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt,
...
b. If the mathematical value of x is equal to the mathematical value of y, return true, otherwise return false.
features: [BigInt]
---*/

assert.sameValue(-1n != false, true, "-1n != false");
assert.sameValue(false != -1n, true, "false != -1n");
assert.sameValue(-1n != true, true, "-1n != true");
assert.sameValue(true != -1n, true, "true != -1n");
assert.sameValue(0n != false, false, "0n != false");
assert.sameValue(false != 0n, false, "false != 0n");
assert.sameValue(0n != true, true, "0n != true");
assert.sameValue(true != 0n, true, "true != 0n");
assert.sameValue(1n != false, true, "1n != false");
assert.sameValue(false != 1n, true, "false != 1n");
assert.sameValue(1n != true, false, "1n != true");
assert.sameValue(true != 1n, false, "true != 1n");
assert.sameValue(2n != false, true, "2n != false");
assert.sameValue(false != 2n, true, "false != 2n");
assert.sameValue(2n != true, true, "2n != true");
assert.sameValue(true != 2n, true, "true != 2n");
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Non-strict inequality comparison of BigInt and miscellaneous primitive values
esid: sec-equality-operators-runtime-semantics-evaluation
info: |
EqualityExpression : EqualityExpression != RelationalExpression
...
5. Return the result of performing Abstract Equality Comparison rval == lval.
6. If r is true, return false. Otherwise, return true.
features: [BigInt, Symbol]
---*/

assert.sameValue(0n != undefined, true, "0n != undefined");
assert.sameValue(undefined != 0n, true, "undefined != 0n");
assert.sameValue(1n != undefined, true, "1n != undefined");
assert.sameValue(undefined != 1n, true, "undefined != 1n");
assert.sameValue(0n != null, true, "0n != null");
assert.sameValue(null != 0n, true, "null != 0n");
assert.sameValue(1n != null, true, "1n != null");
assert.sameValue(null != 1n, true, "null != 1n");
assert.sameValue(0n != Symbol("1"), true, "0n != Symbol(\"1\")");
assert.sameValue(Symbol("1") != 0n, true, "Symbol(\"1\") != 0n");
assert.sameValue(1n != Symbol("1"), true, "1n != Symbol(\"1\")");
assert.sameValue(Symbol("1") != 1n, true, "Symbol(\"1\") != 1n");
31 changes: 31 additions & 0 deletions test/language/expressions/does-not-equals/bigint-and-non-finite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Non-strict inequality comparison of BigInt and non-finite Number values
esid: sec-abstract-equality-comparison
info: |
12. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt,
a. If x or y are any of NaN, +∞, or -∞, return false.
features: [BigInt]
---*/

assert.sameValue(0n != Infinity, true, "0n != Infinity");
assert.sameValue(Infinity != 0n, true, "Infinity != 0n");
assert.sameValue(1n != Infinity, true, "1n != Infinity");
assert.sameValue(Infinity != 1n, true, "Infinity != 1n");
assert.sameValue(-1n != Infinity, true, "-1n != Infinity");
assert.sameValue(Infinity != -1n, true, "Infinity != -1n");
assert.sameValue(0n != -Infinity, true, "0n != -Infinity");
assert.sameValue(-Infinity != 0n, true, "-Infinity != 0n");
assert.sameValue(1n != -Infinity, true, "1n != -Infinity");
assert.sameValue(-Infinity != 1n, true, "-Infinity != 1n");
assert.sameValue(-1n != -Infinity, true, "-1n != -Infinity");
assert.sameValue(-Infinity != -1n, true, "-Infinity != -1n");
assert.sameValue(0n != NaN, true, "0n != NaN");
assert.sameValue(NaN != 0n, true, "NaN != 0n");
assert.sameValue(1n != NaN, true, "1n != NaN");
assert.sameValue(NaN != 1n, true, "NaN != 1n");
assert.sameValue(-1n != NaN, true, "-1n != NaN");
assert.sameValue(NaN != -1n, true, "NaN != -1n");
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Non-strict inequality comparison of BigInt and large Number values
esid: sec-abstract-equality-comparison
info: |
12. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt,
b. If the mathematical value of x is equal to the mathematical value of y, return true, otherwise return false.
features: [BigInt]
---*/

assert.sameValue(1n != Number.MAX_VALUE, true, "1n != Number.MAX_VALUE");
assert.sameValue(Number.MAX_VALUE != 1n, true, "Number.MAX_VALUE != 1n");
assert.sameValue(1n != -Number.MAX_VALUE, true, "1n != -Number.MAX_VALUE");
assert.sameValue(-Number.MAX_VALUE != 1n, true, "-Number.MAX_VALUE != 1n");
assert.sameValue(
0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn != Number.MAX_VALUE,
true,
"0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn != Number.MAX_VALUE");
assert.sameValue(
Number.MAX_VALUE != 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,
true,
"Number.MAX_VALUE != 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn");
assert.sameValue(
0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n != Number.MAX_VALUE,
false,
"0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n != Number.MAX_VALUE");
assert.sameValue(
Number.MAX_VALUE != 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n,
false,
"Number.MAX_VALUE != 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n");
assert.sameValue(
0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n != Number.MAX_VALUE,
true,
"0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n != Number.MAX_VALUE");
assert.sameValue(
Number.MAX_VALUE != 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n,
true,
"Number.MAX_VALUE != 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n");
33 changes: 33 additions & 0 deletions test/language/expressions/does-not-equals/bigint-and-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Non-strict inequality comparison of BigInt and Number values
esid: sec-abstract-equality-comparison
info: |
12. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt,
b. If the mathematical value of x is equal to the mathematical value of y, return true, otherwise return false.
features: [BigInt]
---*/

assert.sameValue(0n != 0, false, "0n != 0");
assert.sameValue(0 != 0n, false, "0 != 0n");
assert.sameValue(0n != -0, false, "0n != -0");
assert.sameValue(-0 != 0n, false, "-0 != 0n");
assert.sameValue(0n != 0.000000000001, true, "0n != 0.000000000001");
assert.sameValue(0.000000000001 != 0n, true, "0.000000000001 != 0n");
assert.sameValue(0n != 1, true, "0n != 1");
assert.sameValue(1 != 0n, true, "1 != 0n");
assert.sameValue(1n != 0, true, "1n != 0");
assert.sameValue(0 != 1n, true, "0 != 1n");
assert.sameValue(1n != 0.999999999999, true, "1n != 0.999999999999");
assert.sameValue(0.999999999999 != 1n, true, "0.999999999999 != 1n");
assert.sameValue(1n != 1, false, "1n != 1");
assert.sameValue(1 != 1n, false, "1 != 1n");
assert.sameValue(0n != Number.MIN_VALUE, true, "0n != Number.MIN_VALUE");
assert.sameValue(Number.MIN_VALUE != 0n, true, "Number.MIN_VALUE != 0n");
assert.sameValue(0n != -Number.MIN_VALUE, true, "0n != -Number.MIN_VALUE");
assert.sameValue(-Number.MIN_VALUE != 0n, true, "-Number.MIN_VALUE != 0n");
assert.sameValue(-10n != Number.MIN_VALUE, true, "-10n != Number.MIN_VALUE");
assert.sameValue(Number.MIN_VALUE != -10n, true, "Number.MIN_VALUE != -10n");
56 changes: 56 additions & 0 deletions test/language/expressions/does-not-equals/bigint-and-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Non-strict inequality comparison of BigInt values and non-primitive objects
esid: sec-abstract-equality-comparison
info: |
10. If Type(x) is either String, Number, BigInt, or Symbol and Type(y) is Object, return the result of the comparison x == ? ToPrimitive(y).
11. If Type(x) is Object and Type(y) is either String, Number, BigInt, or Symbol, return the result of the comparison ? ToPrimitive(x) == y.
then after the recursion:
1. If Type(x) is the same as Type(y), then
a. Return the result of performing Strict Equality Comparison x === y.
...
6. If Type(x) is BigInt and Type(y) is String,
a. Let n be StringToBigInt(y).
b. If n is NaN, return false.
c. Return the result of x == n.
7. If Type(x) is String and Type(y) is BigInt, return the result of y == x.
features: [BigInt]
---*/

assert.sameValue(0n != Object(0n), false, "0n != Object(0n)");
assert.sameValue(Object(0n) != 0n, false, "Object(0n) != 0n");
assert.sameValue(0n != Object(1n), true, "0n != Object(1n)");
assert.sameValue(Object(1n) != 0n, true, "Object(1n) != 0n");
assert.sameValue(1n != Object(0n), true, "1n != Object(0n)");
assert.sameValue(Object(0n) != 1n, true, "Object(0n) != 1n");
assert.sameValue(1n != Object(1n), false, "1n != Object(1n)");
assert.sameValue(Object(1n) != 1n, false, "Object(1n) != 1n");
assert.sameValue(2n != Object(0n), true, "2n != Object(0n)");
assert.sameValue(Object(0n) != 2n, true, "Object(0n) != 2n");
assert.sameValue(2n != Object(1n), true, "2n != Object(1n)");
assert.sameValue(Object(1n) != 2n, true, "Object(1n) != 2n");
assert.sameValue(2n != Object(2n), false, "2n != Object(2n)");
assert.sameValue(Object(2n) != 2n, false, "Object(2n) != 2n");
assert.sameValue(0n != {}, true, "0n != {}");
assert.sameValue({} != 0n, true, "{} != 0n");
assert.sameValue(0n != {valueOf: function() { return 0n; }}, false, "0n != {valueOf: function() { return 0n; }}");
assert.sameValue({valueOf: function() { return 0n; }} != 0n, false, "{valueOf: function() { return 0n; }} != 0n");
assert.sameValue(0n != {valueOf: function() { return 1n; }}, true, "0n != {valueOf: function() { return 1n; }}");
assert.sameValue({valueOf: function() { return 1n; }} != 0n, true, "{valueOf: function() { return 1n; }} != 0n");
assert.sameValue(0n != {toString: function() { return "0"; }}, false, "0n != {toString: function() { return \"0\"; }}");
assert.sameValue({toString: function() { return "0"; }} != 0n, false, "{toString: function() { return \"0\"; }} != 0n");
assert.sameValue(0n != {toString: function() { return "1"; }}, true, "0n != {toString: function() { return \"1\"; }}");
assert.sameValue({toString: function() { return "1"; }} != 0n, true, "{toString: function() { return \"1\"; }} != 0n");
assert.sameValue(900719925474099101n != {valueOf: function() { return 900719925474099101n; }}, false, "900719925474099101n != {valueOf: function() { return 900719925474099101n; }}");
assert.sameValue({valueOf: function() { return 900719925474099101n; }} != 900719925474099101n, false, "{valueOf: function() { return 900719925474099101n; }} != 900719925474099101n");
assert.sameValue(900719925474099101n != {valueOf: function() { return 900719925474099102n; }}, true, "900719925474099101n != {valueOf: function() { return 900719925474099102n; }}");
assert.sameValue({valueOf: function() { return 900719925474099102n; }} != 900719925474099101n, true, "{valueOf: function() { return 900719925474099102n; }} != 900719925474099101n");
assert.sameValue(900719925474099101n != {toString: function() { return "900719925474099101"; }}, false, "900719925474099101n != {toString: function() { return \"900719925474099101\"; }}");
assert.sameValue({toString: function() { return "900719925474099101"; }} != 900719925474099101n, false, "{toString: function() { return \"900719925474099101\"; }} != 900719925474099101n");
assert.sameValue(900719925474099101n != {toString: function() { return "900719925474099102"; }}, true, "900719925474099101n != {toString: function() { return \"900719925474099102\"; }}");
assert.sameValue({toString: function() { return "900719925474099102"; }} != 900719925474099101n, true, "{toString: function() { return \"900719925474099102\"; }} != 900719925474099101n");
Loading

0 comments on commit 6443289

Please sign in to comment.