I'm trying to make a generic test function in Swift that tests a function that mutates its argument. However, I get an error message that I can't find a way to solve:
public func testMutating<T: Comparable>(id: Int, input: T, output: T, testObj: (T) -> Any) {
var inputMutating = input // Make a mutable copy of input
_ = testObj(&inputMutating) // Compiler error: Argument type 'inout T' does not conform to expected type 'Comparable'
if (inputMutating == output) {
print("Test \(id) PASSED :D")
} else {
print("Test \(id) FAILED :(")
print(" Expected: \(output)")
print(" Actual : \(inputMutating)")
}
}
Aucun commentaire:
Enregistrer un commentaire