apple / swift-numerics

Advanced mathematical types and functions for Swift
Apache License 2.0
1.66k stars 140 forks source link

[BigInt tests] ❌ Property based tests #251

Open LiarPrincess opened 1 year ago

LiarPrincess commented 1 year ago

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


Tests where we want to express things like:

❌ Failures

// ApplyA_ApplyB_Equals_ApplyAB.swift
func test_a_b_ab() {
  // (a/-3) / -5 = a/15
  let lhs = BigInt(.negative, magnitude: 18446744073709551615)
  let a = BigInt(-3)
  let b = BigInt(-5)
  let ab = BigInt(15)

  let r0 = (lhs / a) / b
  let r1 = lhs / ab
  XCTAssertEqual(r0, r1)
}

// ApplyA_UndoA.swift
func test_a_undoA() {
  let n = BigInt(-1)
  let x = BigInt(-9223372036854775808)
  XCTAssertEqual(n, (n + x) - x)
  XCTAssertEqual(n, (n * x) / x)
}