January 2019
Intermediate to advanced
376 pages
8h 49m
English
Here’s the code for this whole chapter put together:
| | Elixir code/ThinkingInProperties/elixir/pbt/test/pbt_test.exs |
| | defmodule PbtTest do |
| | use ExUnit.Case |
| | use PropCheck |
| | |
| | property "finds biggest element" do |
| | forall x <- non_empty(list(integer())) do |
| | Pbt.biggest(x) == model_biggest(x) |
| | end |
| | end |
| | |
| | def model_biggest(list) do |
| | List.last(Enum.sort(list)) |
| | end |
| | |
| | |
| | property "picks the last number" do |
| | forall {list, known_last} <- {list(number()), number()} do |
| | known_list = list ++ [known_last] |
| | known_last == List.last(known_list) |
| | end |
| | end |
| | |
| | |
| | property "a sorted list has ordered pairs" do |
| | forall list <- list(term()) do |
| | is_ordered(Enum.sort(list)) ... |
Read now
Unlock full access