swift-numerics
swift-numerics copied to clipboard
[BigInt tests] đź’€ Binary `*`, `/` and `%`
trafficstars
Please read the #242 Using tests from “Violet - Python VM written in Swift” before.
đź’€ Crash
func test_div_crash() {
let lhs = BigInt("-9223372036854775808")!
let rhs = BigInt("-1")!
_ = lhs / rhs // Overflow
}
❌ Failures
func test_div_sign() {
// 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)
}
I added the test for rounding toward 0: |quotient * rhs| <= |lhs|, but the current implementation of BigInt.magnitude does not work, so this test will fail though not because of div.