<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="189908" data-post-id="189908">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Aetherus" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Aetherus/120/17203_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Aetherus
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thank you so much! I bought it on PragProg.</p>
<p>I’m still struggling to see the counter-examples with Elixir, though. I tried</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">File.read!("_build/propcheck.ctex")
|&gt; :erlang.binary_to_term()
</code></pre>
<p>and got an <code>ArgumentError</code>.</p>
<p><strong>UPDATE</strong></p>
<p>I found that the couter-examples file <code>_build/propcheck.ctex</code> is a DETS table, whose keys are <code>mfargs</code>, but I’m confusing about the values. They seem to always be <code>[[]]</code>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="189908" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/property-based-testing-with-proper-erlang-and-elixir-pragprog/15339/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-189908" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="189908"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #23"></div>
  </section>
</div>
    <div class="postbit" id="189923" data-post-id="189923">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ferd" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ferd/120/12731_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ferd
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Property-Based Testing with PropEr, LYSE, &amp; Erlang in Anger</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m not 100% sure of it but looking at <a href="https://github.com/alfert/propcheck/blob/bcdb467546c5853ef7d529bd987f2638bb23ddbc/lib/counterstrike.ex" class="inline-onebox" rel="noopener nofollow ugc">propcheck/lib/counterstrike.ex at bcdb467546c5853ef7d529bd987f2638bb23ddbc · alfert/propcheck · GitHub</a>, it appears that the format is <code>{mfa, counterexamples}</code>. I would expect <code>mfa</code> to be the code behind the failing property, and <code>counterexamples</code> a list of the specific inputs that can make it fail.</p>
<p>So the <code>counterexamples</code> being <code>[[]]</code> means that there is a single counterexample when the input is <code>[]</code>. These are passed directly to PropEr when re-running the property: <a href="https://github.com/alfert/propcheck/blob/3e81043dd090085f1bfd5bb9f70d44acc5294e1c/lib/properties.ex#L177" class="inline-onebox" rel="noopener nofollow ugc">propcheck/lib/properties.ex at 3e81043dd090085f1bfd5bb9f70d44acc5294e1c · alfert/propcheck · GitHub</a> – the library then does the rest.</p>
<p>The way I handled them in the rebar3 plugin is a bit different, but I rely on the same sort of functionality. The PropEr library hands the counterexample back to you upon failure, and if you send the same arguments back you should get the same failure out if nothing changed.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="189923" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/property-based-testing-with-proper-erlang-and-elixir-pragprog/15339/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-189923" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="189923"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #24"></div>
  </section>
</div>
    <div class="postbit" id="189974" data-post-id="189974">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Aetherus" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Aetherus/120/17203_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Aetherus
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks. It seems my toy property fails when the input is an empty list, and Elixir treats <code>[[]]</code> as an empty iodata so prints an empty line.</p>
<p>Now I’m facing another problem: PropCheck seems not doing shrinking. I’m following the book and implemented the <code>biggest(list)</code> function as</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def biggest([head|tail]), do: biggest(tail, head)

defp biggest([], max), do: max
defp biggest([head|tail], max) when head &gt; max, do: biggest(tail, head)
defp biggest([head|tail], max) when head &lt; max, do: biggest(tail, max)
</code></pre>
<p>The minimal input that can cause a failure is a list with 2 identical elements, but when I run</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">PROPCHECK_VERBOSE=1 mix test
</code></pre>
<p>PropCheck outputs</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Failed: After 24 test(s).
An exception was raised:
** (FunctionClauseError) no function clause matching in Pbt.BiggestTest.biggest/2
Stacktrace:


[6, 6, 1, -3, -5, -3, -3]

Shrinking (0 time(s))
[6, 6, 1, -3, -5, -3, -3]
.................................................................

  1) property finds biggest element (Pbt.BiggestTest)
     test/biggest_test.exs:5
     Property Elixir.Pbt.BiggestTest.property finds biggest element() failed. Counter-Example is:
     [[6, 6, 1, -3, -5, -3, -3]]
     
     Counter example stored.
     
     code: nil
     stacktrace:
       (propcheck 1.2.2) lib/properties.ex:227: PropCheck.Properties.handle_check_results/2
       test/biggest_test.exs:5: (test)
</code></pre>
<p>Interestingly, when I code the property in Erlang, PropEr is doing shrinking correctly.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="189974" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/property-based-testing-with-proper-erlang-and-elixir-pragprog/15339/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-189974" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="189974"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>