-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More thorough bigint relational comparison tests #1251
Merged
+556
−32
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
test/language/expressions/greater-than-or-equal/bigint-and-bigint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Comparisons of BigInt and BigInt values | ||
esid: sec-abstract-relational-comparison | ||
info: | | ||
... | ||
3. If both px and py are Strings, then | ||
... | ||
4. Else, | ||
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important. | ||
b. Let ny be ? ToNumeric(py). | ||
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny). | ||
|
||
sec-numeric-types-bigint-lessThan | ||
BigInt::lessThan (x, y) | ||
|
||
The abstract operation BigInt::lessThan with two arguments x and y of BigInt type returns true if x is less than y and false otherwise. | ||
|
||
features: [BigInt] | ||
---*/ | ||
|
||
assert.sameValue(0n >= 0n, true); | ||
assert.sameValue(1n >= 1n, true); | ||
assert.sameValue(-1n >= -1n, true); | ||
assert.sameValue(0n >= -0n, true); | ||
assert.sameValue(-0n >= 0n, true); | ||
assert.sameValue(0n >= 1n, false); | ||
assert.sameValue(1n >= 0n, true); | ||
assert.sameValue(0n >= -1n, true); | ||
assert.sameValue(-1n >= 0n, false); | ||
assert.sameValue(1n >= -1n, true); | ||
assert.sameValue(-1n >= 1n, false); | ||
assert.sameValue(0x1fffffffffffff01n >= 0x1fffffffffffff02n, false); | ||
assert.sameValue(0x1fffffffffffff02n >= 0x1fffffffffffff01n, true); | ||
assert.sameValue(-0x1fffffffffffff01n >= -0x1fffffffffffff02n, true); | ||
assert.sameValue(-0x1fffffffffffff02n >= -0x1fffffffffffff01n, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe test some more values, e.g., a combination of long and short BigInt values. |
||
assert.sameValue(0x10000000000000000n >= 0n, true); | ||
assert.sameValue(0n >= 0x10000000000000000n, false); | ||
assert.sameValue(0x10000000000000000n >= 1n, true); | ||
assert.sameValue(1n >= 0x10000000000000000n, false); | ||
assert.sameValue(0x10000000000000000n >= -1n, true); | ||
assert.sameValue(-1n >= 0x10000000000000000n, false); | ||
assert.sameValue(0x10000000000000001n >= 0n, true); | ||
assert.sameValue(0n >= 0x10000000000000001n, false); | ||
assert.sameValue(-0x10000000000000000n >= 0n, false); | ||
assert.sameValue(0n >= -0x10000000000000000n, true); | ||
assert.sameValue(-0x10000000000000000n >= 1n, false); | ||
assert.sameValue(1n >= -0x10000000000000000n, true); | ||
assert.sameValue(-0x10000000000000000n >= -1n, false); | ||
assert.sameValue(-1n >= -0x10000000000000000n, true); | ||
assert.sameValue(-0x10000000000000001n >= 0n, false); | ||
assert.sameValue(0n >= -0x10000000000000001n, true); | ||
assert.sameValue(0x10000000000000000n >= 0x100000000n, true); | ||
assert.sameValue(0x100000000n >= 0x10000000000000000n, false); |
31 changes: 31 additions & 0 deletions
31
test/language/expressions/greater-than-or-equal/bigint-and-non-finite.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Comparisons of BigInt and non-finite Number values | ||
esid: sec-abstract-relational-comparison | ||
info: | | ||
... | ||
3. If both px and py are Strings, then | ||
... | ||
4. Else, | ||
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important. | ||
b. Let ny be ? ToNumeric(py). | ||
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny). | ||
d. Assert: Type(nx) is BigInt and Type(ny) is Number, or if Type(nx) is Number and Type(ny) is BigInt. | ||
e. If x or y are any of NaN, return undefined. | ||
f. If x is -∞, or y is +∞, return true. | ||
g. If x is +∞, or y is -∞, return false. | ||
features: [BigInt] | ||
---*/ | ||
|
||
assert.sameValue(1n >= Infinity, false); | ||
assert.sameValue(Infinity >= 1n, true); | ||
assert.sameValue(-1n >= Infinity, false); | ||
assert.sameValue(Infinity >= -1n, true); | ||
assert.sameValue(1n >= -Infinity, true); | ||
assert.sameValue(-Infinity >= 1n, false); | ||
assert.sameValue(-1n >= -Infinity, true); | ||
assert.sameValue(-Infinity >= -1n, false); | ||
assert.sameValue(0n >= NaN, false); | ||
assert.sameValue(NaN >= 0n, false); |
38 changes: 38 additions & 0 deletions
38
test/language/expressions/greater-than-or-equal/bigint-and-number-extremes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (C) 2017 Josh Wolfe. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Comparisons of large BigInt and Number values | ||
esid: sec-abstract-relational-comparison | ||
info: | | ||
... | ||
3. If both px and py are Strings, then | ||
... | ||
4. Else, | ||
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important. | ||
b. Let ny be ? ToNumeric(py). | ||
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny). | ||
d. Assert: Type(nx) is BigInt and Type(ny) is Number, or if Type(nx) is Number and Type(ny) is BigInt. | ||
e. If x or y are any of NaN, return undefined. | ||
f. If x is -∞, or y is +∞, return true. | ||
g. If x is +∞, or y is -∞, return false. | ||
h. If the mathematical value of nx is less than the mathematical value of ny, return true, otherwise return false. | ||
features: [BigInt] | ||
---*/ | ||
|
||
assert.sameValue(1n >= Number.MAX_VALUE, false); | ||
assert.sameValue(Number.MAX_VALUE >= 1n, true); | ||
assert.sameValue(1n >= -Number.MAX_VALUE, true); | ||
assert.sameValue(-Number.MAX_VALUE >= 1n, false); | ||
assert.sameValue( | ||
0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn >= Number.MAX_VALUE, | ||
false); | ||
assert.sameValue( | ||
Number.MAX_VALUE >= 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn, | ||
true); | ||
assert.sameValue( | ||
0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n >= Number.MAX_VALUE, | ||
true); | ||
assert.sameValue( | ||
Number.MAX_VALUE >= 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n, | ||
false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
test/language/expressions/greater-than/bigint-and-bigint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Comparisons of BigInt and BigInt values | ||
esid: sec-abstract-relational-comparison | ||
info: | | ||
... | ||
3. If both px and py are Strings, then | ||
... | ||
4. Else, | ||
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important. | ||
b. Let ny be ? ToNumeric(py). | ||
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny). | ||
|
||
sec-numeric-types-bigint-lessThan | ||
BigInt::lessThan (x, y) | ||
|
||
The abstract operation BigInt::lessThan with two arguments x and y of BigInt type returns true if x is less than y and false otherwise. | ||
|
||
features: [BigInt] | ||
---*/ | ||
|
||
assert.sameValue(0n > 0n, false); | ||
assert.sameValue(1n > 1n, false); | ||
assert.sameValue(-1n > -1n, false); | ||
assert.sameValue(0n > -0n, false); | ||
assert.sameValue(-0n > 0n, false); | ||
assert.sameValue(0n > 1n, false); | ||
assert.sameValue(1n > 0n, true); | ||
assert.sameValue(0n > -1n, true); | ||
assert.sameValue(-1n > 0n, false); | ||
assert.sameValue(1n > -1n, true); | ||
assert.sameValue(-1n > 1n, false); | ||
assert.sameValue(0x1fffffffffffff01n > 0x1fffffffffffff02n, false); | ||
assert.sameValue(0x1fffffffffffff02n > 0x1fffffffffffff01n, true); | ||
assert.sameValue(-0x1fffffffffffff01n > -0x1fffffffffffff02n, true); | ||
assert.sameValue(-0x1fffffffffffff02n > -0x1fffffffffffff01n, false); | ||
assert.sameValue(0x10000000000000000n > 0n, true); | ||
assert.sameValue(0n > 0x10000000000000000n, false); | ||
assert.sameValue(0x10000000000000000n > 1n, true); | ||
assert.sameValue(1n > 0x10000000000000000n, false); | ||
assert.sameValue(0x10000000000000000n > -1n, true); | ||
assert.sameValue(-1n > 0x10000000000000000n, false); | ||
assert.sameValue(0x10000000000000001n > 0n, true); | ||
assert.sameValue(0n > 0x10000000000000001n, false); | ||
assert.sameValue(-0x10000000000000000n > 0n, false); | ||
assert.sameValue(0n > -0x10000000000000000n, true); | ||
assert.sameValue(-0x10000000000000000n > 1n, false); | ||
assert.sameValue(1n > -0x10000000000000000n, true); | ||
assert.sameValue(-0x10000000000000000n > -1n, false); | ||
assert.sameValue(-1n > -0x10000000000000000n, true); | ||
assert.sameValue(-0x10000000000000001n > 0n, false); | ||
assert.sameValue(0n > -0x10000000000000001n, true); | ||
assert.sameValue(0x10000000000000000n > 0x100000000n, true); | ||
assert.sameValue(0x100000000n > 0x10000000000000000n, false); |
31 changes: 31 additions & 0 deletions
31
test/language/expressions/greater-than/bigint-and-non-finite.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Comparisons of BigInt and non-finite Number values | ||
esid: sec-abstract-relational-comparison | ||
info: | | ||
... | ||
3. If both px and py are Strings, then | ||
... | ||
4. Else, | ||
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important. | ||
b. Let ny be ? ToNumeric(py). | ||
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny). | ||
d. Assert: Type(nx) is BigInt and Type(ny) is Number, or if Type(nx) is Number and Type(ny) is BigInt. | ||
e. If x or y are any of NaN, return undefined. | ||
f. If x is -∞, or y is +∞, return true. | ||
g. If x is +∞, or y is -∞, return false. | ||
features: [BigInt] | ||
---*/ | ||
|
||
assert.sameValue(1n > Infinity, false); | ||
assert.sameValue(Infinity > 1n, true); | ||
assert.sameValue(-1n > Infinity, false); | ||
assert.sameValue(Infinity > -1n, true); | ||
assert.sameValue(1n > -Infinity, true); | ||
assert.sameValue(-Infinity > 1n, false); | ||
assert.sameValue(-1n > -Infinity, true); | ||
assert.sameValue(-Infinity > -1n, false); | ||
assert.sameValue(0n > NaN, false); | ||
assert.sameValue(NaN > 0n, false); |
38 changes: 38 additions & 0 deletions
38
test/language/expressions/greater-than/bigint-and-number-extremes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (C) 2017 Josh Wolfe. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Comparisons of BigInt and Number values | ||
esid: sec-abstract-relational-comparison | ||
info: | | ||
... | ||
3. If both px and py are Strings, then | ||
... | ||
4. Else, | ||
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important. | ||
b. Let ny be ? ToNumeric(py). | ||
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny). | ||
d. Assert: Type(nx) is BigInt and Type(ny) is Number, or if Type(nx) is Number and Type(ny) is BigInt. | ||
e. If x or y are any of NaN, return undefined. | ||
f. If x is -∞, or y is +∞, return true. | ||
g. If x is +∞, or y is -∞, return false. | ||
h. If the mathematical value of nx is less than the mathematical value of ny, return true, otherwise return false. | ||
features: [BigInt] | ||
---*/ | ||
|
||
assert.sameValue(1n > Number.MAX_VALUE, false); | ||
assert.sameValue(Number.MAX_VALUE > 1n, true); | ||
assert.sameValue(1n > -Number.MAX_VALUE, true); | ||
assert.sameValue(-Number.MAX_VALUE > 1n, false); | ||
assert.sameValue( | ||
0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn > Number.MAX_VALUE, | ||
false); | ||
assert.sameValue( | ||
Number.MAX_VALUE > 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn, | ||
true); | ||
assert.sameValue( | ||
0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n > Number.MAX_VALUE, | ||
true); | ||
assert.sameValue( | ||
Number.MAX_VALUE > 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n, | ||
false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
test/language/expressions/less-than-or-equal/bigint-and-bigint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Comparisons of BigInt and BigInt values | ||
esid: sec-abstract-relational-comparison | ||
info: | | ||
... | ||
3. If both px and py are Strings, then | ||
... | ||
4. Else, | ||
a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important. | ||
b. Let ny be ? ToNumeric(py). | ||
c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny). | ||
|
||
sec-numeric-types-bigint-lessThan | ||
BigInt::lessThan (x, y) | ||
|
||
The abstract operation BigInt::lessThan with two arguments x and y of BigInt type returns true if x is less than y and false otherwise. | ||
|
||
features: [BigInt] | ||
---*/ | ||
|
||
assert.sameValue(0n <= 0n, true); | ||
assert.sameValue(1n <= 1n, true); | ||
assert.sameValue(-1n <= -1n, true); | ||
assert.sameValue(0n <= -0n, true); | ||
assert.sameValue(-0n <= 0n, true); | ||
assert.sameValue(0n <= 1n, true); | ||
assert.sameValue(1n <= 0n, false); | ||
assert.sameValue(0n <= -1n, false); | ||
assert.sameValue(-1n <= 0n, true); | ||
assert.sameValue(1n <= -1n, false); | ||
assert.sameValue(-1n <= 1n, true); | ||
assert.sameValue(0x1fffffffffffff01n <= 0x1fffffffffffff02n, true); | ||
assert.sameValue(0x1fffffffffffff02n <= 0x1fffffffffffff01n, false); | ||
assert.sameValue(-0x1fffffffffffff01n <= -0x1fffffffffffff02n, false); | ||
assert.sameValue(-0x1fffffffffffff02n <= -0x1fffffffffffff01n, true); | ||
assert.sameValue(0x10000000000000000n <= 0n, false); | ||
assert.sameValue(0n <= 0x10000000000000000n, true); | ||
assert.sameValue(0x10000000000000000n <= 1n, false); | ||
assert.sameValue(1n <= 0x10000000000000000n, true); | ||
assert.sameValue(0x10000000000000000n <= -1n, false); | ||
assert.sameValue(-1n <= 0x10000000000000000n, true); | ||
assert.sameValue(0x10000000000000001n <= 0n, false); | ||
assert.sameValue(0n <= 0x10000000000000001n, true); | ||
assert.sameValue(-0x10000000000000000n <= 0n, true); | ||
assert.sameValue(0n <= -0x10000000000000000n, false); | ||
assert.sameValue(-0x10000000000000000n <= 1n, true); | ||
assert.sameValue(1n <= -0x10000000000000000n, false); | ||
assert.sameValue(-0x10000000000000000n <= -1n, true); | ||
assert.sameValue(-1n <= -0x10000000000000000n, false); | ||
assert.sameValue(-0x10000000000000001n <= 0n, true); | ||
assert.sameValue(0n <= -0x10000000000000001n, false); | ||
assert.sameValue(0x10000000000000000n <= 0x100000000n, false); | ||
assert.sameValue(0x100000000n <= 0x10000000000000000n, true); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're hitting this case, right? If so, maybe the below spec text doesn't need to be quoted. Also, you could quote BigInt::lessThan, which is always hit here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. The frontmatter needs to be specialized for the different files even more than this. I'll make that update.