When writing unit tests for a bidirectional converter, I was wondering if it was enough to cover only one direction with the unit test. Suppose a converter that converts both from a -> band from b -> a:
class Converter<A, B> {
B convertToB(A a) { }
A convertToA(B b) { }
}
Or more formally:
f(a) = b
f(b) = a
Standard unit tests would have to check both directions of conversion. However, it is very easy to write type tests f(f(a)) == a. Suppose that it is f(a) == bcovered by the unit test symbol. Which of these tests will be necessary and sufficient to cover f(b) == a?
(1) f(f(a)) == a
(2) f(f(b)) == b
(3) f(f(a)) == a && f(f(b)) == b
or we need to check
(4) f(b) == a
source
share