Skip to content

Commit

Permalink
Respond to comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ploeh committed May 24, 2022
1 parent 1c267a6 commit fda4c2b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions _posts/2015-05-07-functional-design-is-intrinsically-testable.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,26 @@ <h2 id="comments-header">
</div>
<div class="comment-date">2022-05-23 2:12 UTC</div>
</div>

<div class="comment" id="9e0edebafc604154b4472d0a3d978894">
<div class="comment-author"><a href="{{ HOME_PATH }}">Mark Seemann</a></div>
<div class="comment-content">
<p>
Spencer, thank you for writing. While I know that Clojure.spec exists, I don't know more about it than what you've described. It's not quite the same, but it sounds not too dissimilar from <a href="http://hackage.haskell.org/package/QuickCheck">QuickCheck</a> <code>Arbitrary</code> instances. They don't describe predicates, but they do implement (pseudo-random) generators of values. Those generators then drive data generation for property-based tests.
</p>
<p>
Parametrised tests (including properties) are essentially predicates. They take input and return a binary result. Granted, the result isn't <em>true</em> or <em>false</em>, but rather <em>pass</em> or <em>fail</em>, but I hope it's evident that these are isomorphic.
</p>
<p>
How does that relate to testing totality? It's better than nothing, but in practice we must suffer the reality of combinatorics. You can easily use brute force to prove total a function that takes a single Boolean value as input. A byte input requires 256 test cases, so that's also within the realm of the possible. Many input types, however, <a href="/2021/11/15/types-as-sets">represent conceptually infinite sets</a>. A string, for example, represents a conceptually infinite set.
</p>
<p>
Imagine an adversarial function that loops forever if the input string is a very particular value. This value might be a one-million-character string generated randomly at compile time. The odds that any random test case generator ever hits that particular value are effectively nil.
</p>
<p>
While I like property-based testing a lot, I don't consider it a measure of totality. If the domain of a function is infinite, it makes little difference if you exercise a hundred or a million test cases - you've still covered practically zero percent of the domain.
</p>
</div>
<div class="comment-date">2022-05-24 6:27 UTC</div>
</div>
</div>

0 comments on commit fda4c2b

Please sign in to comment.