Skip to content

[BigInt tests] ❌ Binary + and -#246

Open
LiarPrincess wants to merge 2 commits intoapple:bigintegerfrom
LiarPrincess:5-Binary-ADD-SUB
Open

[BigInt tests] ❌ Binary + and -#246
LiarPrincess wants to merge 2 commits intoapple:bigintegerfrom
LiarPrincess:5-Binary-ADD-SUB

Conversation

@LiarPrincess
Copy link
Copy Markdown

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


❌ Failures

func test_binarySub() {
  // https://www.wolframalpha.com/input?i=-922337203685477587+-+%28-9223372036854775808%29
  let lhs = BigInt("-922337203685477587")!
  let rhs = BigInt("-9223372036854775808")!
  let expected = BigInt("8301034833169298221")!
  XCTAssertEqual(lhs - rhs, expected)
  // The same on Swift.Int:
  XCTAssertEqual(-922337203685477587 - (-9223372036854775808), 8301034833169298221)
}

func test_binarySub_2() {
  typealias Word = BigIntPrototype.Word

  let intMax = Int.max
  let intMaxAsWord = Word(intMax.magnitude)

  // intMax - (-(Word.max - intMaxAsWord)) =
  // intMax - (-Word.max + intMaxAsWord) =
  // intMax + Word.max - intMaxAsWord =
  // Word.max
  let max = BigInt(intMax)
  let value = BigInt(.negative, magnitude: Word.max - intMaxAsWord)
  let expected = BigInt(.positive, magnitude: Word.max)
  XCTAssertEqual(max - value, expected)
}

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