swift-numerics
swift-numerics copied to clipboard
[BigInt tests] đź’€ Init from int
trafficstars
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)
}