# Elm-minithesis: shrinking without compromises

**URL:** <https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071>\
**Category:** Show and Tell\
**Created:** [July 23, 2020, 2:07pm UTC](https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071 "2020-07-23T14:07:44Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![mattpiz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mattpiz/32/860_2.png) [@mattpiz](https://discourse.elm-lang.org/u/mattpiz)\
**Post date:** [July 29, 2020, 2:03pm UTC](https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071/21 "2020-07-29T14:03:45Z")

</div>

> [@Janiczek](#):
>
> Combine this with `elm-test` default `--fuzz 100` and **you potentially get up to 100k generation attempts for a single test.**

Ah that’s good to know and probably the reason indeed. I’ll wait for your “call for testing and feedback” before continuing but I was curious enough that I wanted to try now 😉

---

<div class="post-metadata">

**Author:** ![Janiczek](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/janiczek/32/4516_2.png) [@Janiczek](https://discourse.elm-lang.org/u/Janiczek)\
**Post date:** [July 30, 2020, 10:27am UTC](https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071/22 "2020-07-30T10:27:08Z")

</div>

@mattpiz Just FYI: I’ve started benchmarking elm-minithesis and one of the first benchmarks were various implementations of your “less empty string” fuzzer. See the code here: [https://github.com/Janiczek/elm-minithesis/blob/master/benchmarks/fuzzer-implementations/less-empty-string/src/Main.elm](https://github.com/Janiczek/elm-minithesis/blob/master/benchmarks/fuzzer-implementations/less-empty-string/src/Main.elm)

 ![bench](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/2X/c/cce3cf1cdb0147a26754631f1ff96f966b0aa787.png)

---

<div class="post-metadata">

**Author:** ![mattpiz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mattpiz/32/860_2.png) [@mattpiz](https://discourse.elm-lang.org/u/mattpiz)\
**Post date:** [July 30, 2020, 10:56am UTC](https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071/23 "2020-07-30T10:56:58Z")

</div>

I had not looked for the `stringWith` function, that’s really cool! One remark regarding its interface, an average length does not say much without knowing the associated distribution (or simply standard deviation if Gaussian distribution is assumed)

---

<div class="post-metadata">

**Author:** ![Janiczek](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/janiczek/32/4516_2.png) [@Janiczek](https://discourse.elm-lang.org/u/Janiczek)\
**Post date:** [July 30, 2020, 11:02am UTC](https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071/24 "2020-07-30T11:02:15Z")

</div>

Thanks @mattpiz. Yeah it internally converts to a `continue generating probability` according to geometric distribution. Perhaps I should do

```elm
stringWith
  { minLength : Maybe Int
  , maxLength : Maybe Int
  , continueProbability : Maybe Float
  }

```

instead?  
Or do you think a doc comment explaining the distribution would be enough?

---

<div class="post-metadata">

**Author:** ![Janiczek](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/janiczek/32/4516_2.png) [@Janiczek](https://discourse.elm-lang.org/u/Janiczek)\
**Post date:** [July 30, 2020, 12:08pm UTC](https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071/25 "2020-07-30T12:08:46Z")

</div>

Another benchmark done: this time comparing minithesis vs elm-test:

Fuzzer:

```elm
-- elm-minithesis:
Minithesis.Fuzz.int 0 10000
-- elm-test:
Fuzz.intRange 0 10000

```

Test function:

```elm
-- elm-minithesis:
(\i -> i < 5000)
-- elm-test:
(\i -> Expect.lessThan 5000 i)

```

And here are the results:

 ![bench2](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/2X/5/543d6c5fd545c4586cce65c23927dd7e638fec2e.png)  
Looks like:

- minithesis is taking ~3x longer when generating the value (we have additional overhead because we have to remember the PRNG choices; elm-test can just use the `Random.Generator` as is)
- elm-test is taking ~10x longer when shrinking the values

All in all, that’s encouraging 🎉

Benchmark code: [https://github.com/Janiczek/elm-minithesis/blob/master/benchmarks/vs-elm-test/int/src/Main.elm](https://github.com/Janiczek/elm-minithesis/blob/master/benchmarks/vs-elm-test/int/src/Main.elm)

---

<div class="post-metadata">

**Author:** ![mattpiz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mattpiz/32/860_2.png) [@mattpiz](https://discourse.elm-lang.org/u/mattpiz)\
**Post date:** [July 30, 2020, 12:15pm UTC](https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071/26 "2020-07-30T12:15:05Z")

</div>

[This distribution](https://en.wikipedia.org/wiki/Geometric_distribution) where the mean value is related to the probability of success with `mean = (1-p) / p` right? I don’t know what would be better, but simply looking at it now gives a better idea of what kind of values may appear. Contrary to what most people might think, the average value is not where the probability density function is max (which is always 0). And increasing the average value tends to a uniform distribution. That may be counter-intuitive and probably best to illustrate in the doc.

---

<div class="post-metadata">

**Author:** ![Janiczek](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/janiczek/32/4516_2.png) [@Janiczek](https://discourse.elm-lang.org/u/Janiczek)\
**Post date:** [July 30, 2020, 1:52pm UTC](https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071/27 "2020-07-30T13:52:17Z")

</div>

For anybody who’s interested: I posted a **call for testing and feedback** : [Elm-minithesis: gathering feedback and benchmarks](https://discourse.elm-lang.org/t/elm-minithesis-gathering-feedback-and-benchmarks/6106)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [August 9, 2020, 1:52pm UTC](https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071/28 "2020-08-09T13:52:19Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.elm-lang.org/t/elm-minithesis-shrinking-without-compromises/6071.md?page=1)
