Skip to content

Commit 29a2f30

Browse files
committed
More property based properties
1 parent 20e720d commit 29a2f30

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/statistex_test.exs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ defmodule Statistex.StatistexTest do
164164

165165
assert_basic_statistics(stats)
166166
assert_mode_in_samples(stats, samples)
167-
frequency_assertions(stats, samples)
167+
assert_frequencies(stats, samples)
168+
assert_bounds(stats, samples)
168169

169170
# shuffling values around shouldn't change the results
170171
shuffled_stats = samples |> Enum.shuffle() |> statistics()
@@ -183,6 +184,9 @@ defmodule Statistex.StatistexTest do
183184

184185
assert stats.median == stats.percentiles[50]
185186

187+
assert stats.median >= stats.percentiles[25]
188+
assert stats.percentiles[75] >= stats.median
189+
186190
assert stats.variance >= 0
187191
assert stats.standard_deviation >= 0
188192
assert stats.standard_deviation_ratio >= 0
@@ -204,7 +208,7 @@ defmodule Statistex.StatistexTest do
204208
end
205209
end
206210

207-
defp frequency_assertions(stats, samples) do
211+
defp assert_frequencies(stats, samples) do
208212
frequency_distribution = stats.frequency_distribution
209213
frequency_entry_count = map_size(frequency_distribution)
210214

@@ -230,6 +234,16 @@ defmodule Statistex.StatistexTest do
230234
assert count_sum == stats.sample_size
231235
end
232236

237+
defp assert_bounds(stats, samples) do
238+
Enum.each(stats.outliers, fn outlier ->
239+
assert outlier in samples
240+
assert outlier < stats.lower_outlier_bound || outlier > stats.upper_outlier_bound
241+
end)
242+
243+
assert stats.lower_outlier_bound <= stats.percentiles[25]
244+
assert stats.upper_outlier_bound >= stats.percentiles[75]
245+
end
246+
233247
defp big_list_big_floats do
234248
sized(fn size ->
235249
resize(

0 commit comments

Comments
 (0)