Given the following Swift class:
class TestObject: NSObject { let a: Int init(a: Int) { self.a = a super.init() } } func ==(lhs: TestObject, rhs: TestObject) -> Bool { return lhs.a == rhs.a }
and test case:
func testExample() { let a = TestObject(a: 4) let b = TestObject(a: 4) XCTAssertEqual(a, b)
both statements return different values, but both must pass.
I tried writing a custom assert function:
func BAAssertEquatable<A: Equatable>(x1: A, _ x2: A, _ message: String, file: String = __FILE__, line: UInt = __LINE__) { let operandsEqual = (x1 == x2) XCTAssert(operandsEqual, message, file: file, line: line) }
but it also fails:
BAAssertEquatable(a, b, "custom assert")
What's going on here?
swift xctest
Bill
source share