3 ms·
> Tests can almost by definition give stronger guarantees than a type system, False. > This means that, for any type, it’s possible to replicate the check don
by dragonwriter 5y ago
> Tests can almost by definition give stronger guarantees than a type system,
False.
> This means that, for any type, it’s possible to replicate the check done by the compiler at compile-time in a unit test but not vice versa.
False. I mean, Turing completeness does mean you could replicate any type guarantee in code, but that code would generally not be a unit test; guarantees provided by type systems are universally quantified, to confirm that with testing would require testing every combination of values in the function’s domain (as determined by its parameter types.)
The code would instead be a static typechecker that consumed the untyped source code plus a representation of the type assertions to be checked and where they attach to the untyped source code, and then did exactly the same things that any other static typechecker would do.
That is... standard optional static typecheckers for dynamic languages. (Though those usually also support inline type assertions, perhaps via comments in languages without specific syntactic support, e.g., Python 2.x)
You can approximate universally quantified guarantees in a testing regime with property-based testing, but that's at best probabilistic rather than actual universal quantification.