3 ms·
A lot of the time it's easier to confirm that an answer is correct than compute that answer. Imagine a test like: val result = factorize(367) assertEqu
by lmm 6y ago
A lot of the time it's easier to confirm that an answer is correct than compute that answer. Imagine a test like:
val result = factorize(367)
assertEquals(367, result.reduce(_ * _))
This isn't really a "human validation" - as a human I don't actually know what the prime factorisation of 367 is - and the sense in which it's a "compiler rule" is a deep and subtle one. But I'd argue that it's a valid test and quite a lot of software tests are of this type.
Another type of test not considered here is a "redundant" check for a simple case. If we write a test like:
assertEquals(multiply(83, 83), pow(83, 2))
then to a certain extent that's redundant, but I'd argue it's a useful sanity check of our pow implementation. Again it doesn't seem right to call this a "human validation" since I don't actually know 83^2 as a human.
It also bears considering that even an entirely redundant test may be useful in providing (and explaining) a use case for an API. If we've just implemented the map() function for lists, then a test like:
def f(x: Int) = x * 2
val input = List(1, 2, 3)
var result = List.empty()
for { element <- input }
result :+= f(element)
assertEquals(result, input map f)
is "redundant" in this taxonomy, but a perfectly legitimate test of map; often "be equivalent to this more complicated sequence of functions" is exactly the specification of a particular function.
- xtajv 6y ago> A lot of the time it's easier to confirm that an answer is correct than compute that answer. Is this a "human validation" that P!=NP ? ;)
- sfink 6y agoMore like "most software is in NP", since "easy to confirm an answer" is the set's defining characteristic.
- sbergot 6y agowhat you are describing is testing invariant properties. It is telling that your two examples are math functions because those often have lots of useful invariants. A lot of time you only have weaker properties to test so you have to look for other methodologies such as using vectors of inputs/expected results or building a simpler reference implementation to test the optimized version.