Skip to content
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
merged 3 commits into from
Oct 2, 2017

Conversation

thejoshwolfe
Copy link
Contributor

Notably this introduces coverage for:

  • bigint against Infinity and NaN, which are special cases in the new algorithm.
  • Number.MAX_VALUE vs bigint values that are a little above and a little below it by a factor of 16.
  • bigint against bigint, including values greater than Number.MAX_SAFE_INTEGER that only differ by 1n.

Regarding Number.MAX_VALUE, my reading of the spec is that we should not test differing from that value by only 1, since Number.MAX_VALUE is an approximate value. However, a factor of 16 above and below seems far enough way that any reasonable approximation should recognize the difference.

I'm trying a new approach to writing tests, where instead of using runtime abstraction to get thorough and consistent coverage, I'm using a python script to generate this code. I didn't include the generator script in this PR, because it seemed like a one-off thing that wouldn't be generally useful. If there is interest in including this generator in test262, here's what I've got so far, and I already know the style would need cleaning up to fit test262's style (e.g. indentation width).

The generator approach made it very easy to separate tests into 16 separate files. I could separate these tests into even more files pretty easily if that'd be desired. For example, I could put Infinity and NaN into separate test files instead of the one file called -non-finite.

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).
Copy link
Member

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.

Copy link
Contributor Author

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.

assert.sameValue(0x1fffffffffffff01n >= 0x1fffffffffffff02n, false);
assert.sameValue(0x1fffffffffffff02n >= 0x1fffffffffffff01n, true);
assert.sameValue(-0x1fffffffffffff01n >= -0x1fffffffffffff02n, true);
assert.sameValue(-0x1fffffffffffff02n >= -0x1fffffffffffff01n, false);
Copy link
Member

Choose a reason for hiding this comment

The 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(1n >= -Number.MAX_VALUE, true);
assert.sameValue(-Number.MAX_VALUE >= 1n, false);
assert.sameValue(
0xfffffffffffff80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n >= Number.MAX_VALUE,
Copy link
Member

@littledan littledan Sep 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have a test for the edge cases, namely the BigInt which represents one less than Number.MAX_VALUE, the BigInt which is Number.MAX_VALUE, and one greater than it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed this in the OP of this PR, but it might be good to throw a comment in the file as well. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed the explanation there. I disagree with your reading of the spec--I think Number.MAX_VALUE is well-defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'll tighten up the test.

@leobalter
Copy link
Member

instead of using runtime abstraction to get thorough and consistent coverage, I'm using a python script to generate this code

Are you saying you can't achieve a thorough and consistent coverage this way?

@thejoshwolfe
Copy link
Contributor Author

Are you saying you can't achieve a thorough and consistent coverage this way?

Sorry. I'm saying that I am achieving the same level of runtime coverage. Instead of runtime logic, I'm using analogous logic in the code generator.

An example of this coverage is that the case of comparing 1n against 0 is specified once in the generator, and 8 cases are output in the code: 4 different operators, and 2 different ways to order the operands.

@rwaldron
Copy link
Contributor

rwaldron commented Oct 2, 2017

I'm using a python script to generate this code. I didn't include the generator script in this PR, because it seemed like a one-off thing that wouldn't be generally useful.

Why not use the existing test generator tool?

@rwaldron
Copy link
Contributor

rwaldron commented Oct 2, 2017

Please review the CI failures. The frontmatter is invalid.

Linting 16 files.
Linting complete. 4 errors found.
test/language/expressions/greater-than-or-equal/bigint-and-bigint.js: FRONTMATTER - No valid YAML-formatted frontmatter
test/language/expressions/greater-than/bigint-and-bigint.js: FRONTMATTER - No valid YAML-formatted frontmatter
test/language/expressions/less-than-or-equal/bigint-and-bigint.js: FRONTMATTER - No valid YAML-formatted frontmatter
test/language/expressions/less-than/bigint-and-bigint.js: FRONTMATTER - No valid YAML-formatted frontmatter

c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny).

sec-numeric-types-bigint-lessThan
BigInt::lessThan (x, y)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing spaces, this is causing the yaml parsing to fail.

@thejoshwolfe
Copy link
Contributor Author

Please review the CI failures. The frontmatter is invalid.

Oops. Should have known that was invalid yaml.

@thejoshwolfe
Copy link
Contributor Author

Why not use the existing test generator tool?

If you're talking about tools/generator/generator.py, then I don't think it's the right fit for this usecase. I don't think the template and case design can generate what I'm doing with switching the order of the operands and inverting the condition for the non-or-equal operators. I can look into trying to use the existing generator, but writing something quick from scratch seemed much easier.

Copy link
Member

@leobalter leobalter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this point, we can take care of nitpicks in follow up PRs.

LGTM.

@leobalter leobalter merged commit aca48e4 into tc39:master Oct 2, 2017
@thejoshwolfe thejoshwolfe deleted the relational branch October 3, 2017 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants