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

[BigInt tests] ❌ Nodejs tests #243

Open
wants to merge 2 commits into
base: biginteger
Choose a base branch
from

Conversation

LiarPrincess
Copy link

Please read the #242 Using tests from “Violet - Python VM written in Swift” before.


Tests generated by Node.js.

It does require Node.js installed (obviously), but we could solve it with Docker. So, if you want I cann add appropriate Dockerfile.

❌ Failures

There are about 6700 failures, I will not go into details of all of them.

func test_node_div_incorrectSign() {
  // positive / negative = negative
  var lhs = BigInt("18446744073709551615")!
  var rhs = BigInt("-1")!
  var expected = BigInt("-18446744073709551615")!
  XCTAssertEqual(lhs / rhs, expected)

  // negative / positive = negative
  lhs = BigInt("-340282366920938463481821351505477763074")!
  rhs = BigInt("18446744073709551629")!
  expected = BigInt("-18446744073709551604")!
  XCTAssertEqual(lhs / rhs, expected)
}

func test_node_mod_incorrectSign() {
  // SMALL % BIG = SMALL
  // We need to satisfy: BIG * 0 + result = SMALL -> result = SMALL
  // The same, but on the standard Swift.Int to prove the point:
  XCTAssertEqual(-1 % 123, -1)
  XCTAssertEqual(-1 % -123, -1)
  // In general the 'reminder' follows the 'lhs' sign (round toward 0).
  // Except for the case where 'lhs' is negative and 'reminder' is 0.

  var lhs = BigInt("-1")!
  var rhs = BigInt("18446744073709551615")!
  XCTAssertEqual(lhs % rhs, lhs)

  // Also fails if 'rhs' is negative
  lhs = BigInt("-7730941133")!
  rhs = BigInt("-18446744073709551615")!
  XCTAssertEqual(lhs % rhs, lhs)
}

// From my observations all of the `xor` tests are failing.
func test_node_xor() {
  var lhs = BigInt("0")!
  var rhs = BigInt("1")!
  var expected = BigInt("1")!
  XCTAssertEqual(lhs ^ rhs, expected)
  XCTAssertEqual(0 ^ 1, 1) // Proof

  lhs = BigInt("0")!
  rhs = BigInt("-1")!
  expected = BigInt("-1")!
  XCTAssertEqual(lhs ^ rhs, expected)
  XCTAssertEqual(0 ^ -1, -1) // Proof
}

@mgriebling
Copy link

These tests now all pass with #261 pull request.

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.

2 participants