This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test "lists of different size as input result in error" do | |
stats = [[0, 10, 20], [20, 10, 0], [10, 10]] | |
assert MissingData.average_list(stats) == :error | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test "generate list of numbers given same size input list" do | |
stats = [[0, 10, 20], [20, 10, 0], [10, 10, 10]] | |
assert MissingData.average_list(stats) == [15, 10, 15] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"ac_ratio": | |
{"accelerations": | |
[100.0,166.0,0,119.0,147.0,92.0,0,0,118.0,0,127.0,133.0, | |
192.0,0,103.0,133.0,0,142.0,149.0,181.0,0,140.0,0,0,0,0,0,0], | |
"sprint_distances": | |
[153.002649391,231.992722498,0,272.078987806,167.660927286,198.818410826,0,0,376.611274507, | |
0,320.307097832,255.344880942,743.19938242,0,603.015597359,40.2846969563,0,789.82629535, | |
130.172380645,807.139266604,0,653.654959634,0,0,0,0,0,0] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property "always returns list of the same size" do | |
check all size <- integer(0..100), | |
number_lists <- list_of(number_list(size), min_length: 1, max_length: 100) do | |
assert length(MissingData.average_list(number_lists)) == length(Enum.random(number_lists)) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defp number_list(size) do | |
gen all number_list <- list_of(integer(0..99999), length: size) do | |
number_list | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MissingData do | |
@doc """ | |
Example input: | |
> MissingData.average_list([[0, 10, 20], [20, 10, 0], [10, 10, 10]]) | |
Example output: | |
> [15, 10, 15] | |
""" | |
def average_list(list_of_lists) do | |
if have_same_sizes?(list_of_lists) do |