Skip to content

[BigInt tests] 💀 Init from int#254

Open
LiarPrincess wants to merge 2 commits into
apple:bigintegerfrom
LiarPrincess:1-Init-from-int
Open

[BigInt tests] 💀 Init from int#254
LiarPrincess wants to merge 2 commits into
apple:bigintegerfrom
LiarPrincess:1-Init-from-int

Conversation

@LiarPrincess

@LiarPrincess LiarPrincess commented Jan 18, 2023

Copy link
Copy Markdown

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