Skip to content

Instantly share code, notes, and snippets.

@grufino
Last active August 20, 2019 19:53
Show Gist options
  • Save grufino/aa8a97d29f61bda9e2a501c7dad83f5e to your computer and use it in GitHub Desktop.
Save grufino/aa8a97d29f61bda9e2a501c7dad83f5e to your computer and use it in GitHub Desktop.
property "index number is always it's average in all indexes" do
check all size <- integer(1..100),
number_lists <- list_of(number_list(size), min_length: 1, max_length: 100) do
# since this test is based on index it also tests that ordering is maintained
Enum.map(1..(size - 1), fn index ->
index_avg =
Enum.map(number_lists, fn number_list -> Enum.at(number_list, index) end)
|> Enum.filter(fn value -> value != 0 && value != nil end)
|> Math.Enum.mean()
assert MissingData.average_list(number_lists) |> Enum.at(index) == index_avg
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment