Sources:
def test_mysort():
l = [5, 3, 2, 1, 6]
l_sorted = my_sort(l)
assert l_sorted == [1, 2, 3, 5, 6]
from hypothesis import given
import hypothesis.strategies as some
@given(l=some.lists(some.integers()))
def test_my_sort(l):
l_sorted = my_sort(l)
assert len(l_sorted) == len(l)
assert set(l_sorted) == set(l)
for i in range(len(l) - 1):
assert l_sorted[i] <= l_sorted[i+1]
property "finds biggest element" do
forall x <- non_empty(list(integer())) do
MyModule.biggest(x) == model_biggest(x)
end
end
def model_biggest(x) do
List.last(Enum.sort(list))
end
property "symmetric encoding/decoding" do
forall data <- list({atom(), any()}) do
encoded = encode(data)
is_binary(encoded) and data == decode(encoded)
end
end
property "a sorted list keeps its size" do
forall l <- list(number()) do
length(l) == length(MyModule.sort(l))
end
end
Given a callback module implementing the :proper_statem behaviour (i.e. defining an abstract state machine of the system under test), PropEr can generate random symbolic sequences of calls to that system
- Events:
* 63.37%, input list length in range 0-5
* 27.72%, input list length in range 5-10
* 3.96%, input list length in range 10-15
* 2.97%, input list length in range 15-20
* 0.99%, input list length in range 35-40