swift-numerics icon indicating copy to clipboard operation
swift-numerics copied to clipboard

[BigInt tests] ❌ Property based tests

Open LiarPrincess opened this issue 2 years ago • 0 comments
trafficstars

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


Tests where we want to express things like:

  • ∀xab, (x+a)+b = x+(a+b)
  • ∀xn, (n+x)-x = n

❌ 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)
}

LiarPrincess avatar Jan 18 '23 15:01 LiarPrincess