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] đź’€ Init from int #254

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

Conversation

LiarPrincess
Copy link

@LiarPrincess LiarPrincess commented Jan 18, 2023

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


Tests for all of the let n = BigInt(some_integer) variants.

đź’€ Crash

func test_initFromInt_crash() {
  // 18446744073709551615 = UInt64.max
  let int: UInt64 = 18446744073709551615
  let big = BigInt(int)
  let revert = UInt64(big)
}

❌ Failures

func test_initFromInt_exactly() {
  let int: UInt64 = 18446744073709551614
  let big = BigInt(exactly: int)!
  let revert = UInt64(exactly: big)
  XCTAssertEqual(int, revert)
}

func test_initFromInt_clamping() {
  let int: UInt64 = 18446744073709551614
  let big = BigInt(clamping: int)
  let revert = UInt64(clamping: big)
  XCTAssertEqual(int, revert)
}

func test_initFromInt_truncatingIfNeeded() {
  let int: UInt64 = 18446744073709551615
  let big = BigInt(truncatingIfNeeded: int)
  let intString = String(int, radix: 10, uppercase: false)
  let bigString = String(big, radix: 10, uppercase: false)
  XCTAssertEqual(bigString, intString)
}

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.

1 participant