Skip to content

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