3 ms·
> Turns out... we don't really do that so much. With a suitably enlarged definition of (static) type, a lot of tests become type-assertions. Eg red black tree
by eru 11y ago
> Turns out... we don't really do that so much.
With a suitably enlarged definition of (static) type, a lot of tests become type-assertions.
Eg red black trees have interesting balancing requirements: no t
See eg Red Black Trees are another interesting example. A red black tree is a binary search tree, and all its nodes are coloured either red or black. You can not have two red nodes in a row on any path, but all paths from root to any leave have to have the same number of black nodes.
Testing that these two properties hold after an arbitrary number of inserts sounds like a good candidate for a unit tests, and doesn't sound like a type assertion, does it?
See https://www.reddit.com/r/haskell/comments/ti5il/redblack_trees_in_haskell_using_gadts_existential/ https://www.reddit.com/r/haskell/comments/ti5il/redblack_tre... for how to encode those properties into the types.
In any case, Haskell has great support for unit tests, too. (Because in general you can't and at any rate don't want to encode everything you care about in the type system.)
Have a look at QuickCheck. There are ports for various other languages, too. QuickCheck is a generalization of the table-driven approach to unit-testing: it's about generating those tables automatically, and automatically simplifying any inputs found that lead to buggy behaviour.