test(member-live): build date-filter property bounds without a reject-filter
The bound-pair generator filtered out ~1/4 of generated values, so unlucky seeds hit StreamData's FilterTooNarrowError under full property runs. Construct an at-least-one-bound-set pair directly instead, preserving the exact domain with no rejection.
This commit is contained in:
parent
655fd80524
commit
cb54c2c46e
1 changed files with 18 additions and 11 deletions
|
|
@ -20,11 +20,12 @@ defmodule MvWeb.MemberLive.Index.DateFilterPropertyTest do
|
||||||
|
|
||||||
# Generators -----------------------------------------------------------
|
# Generators -----------------------------------------------------------
|
||||||
|
|
||||||
defp optional_date_gen do
|
defp date_gen do
|
||||||
one_of([
|
|
||||||
constant(nil),
|
|
||||||
map(integer(-3650..3650), &Date.add(~D[2000-01-01], &1))
|
map(integer(-3650..3650), &Date.add(~D[2000-01-01], &1))
|
||||||
])
|
end
|
||||||
|
|
||||||
|
defp optional_date_gen do
|
||||||
|
one_of([constant(nil), date_gen()])
|
||||||
end
|
end
|
||||||
|
|
||||||
defp exit_date_mode_gen do
|
defp exit_date_mode_gen do
|
||||||
|
|
@ -57,19 +58,25 @@ defmodule MvWeb.MemberLive.Index.DateFilterPropertyTest do
|
||||||
|
|
||||||
# Property -------------------------------------------------------------
|
# Property -------------------------------------------------------------
|
||||||
|
|
||||||
|
# Generates a {from, to} pair with at least one bound set. Built by construction
|
||||||
|
# (pick which bounds are set, then generate the required dates) rather than by
|
||||||
|
# filtering out the both-nil case, so StreamData never rejects values and cannot
|
||||||
|
# raise FilterTooNarrowError on unlucky seeds.
|
||||||
defp bound_pair_with_at_least_one_set_gen do
|
defp bound_pair_with_at_least_one_set_gen do
|
||||||
gen all(
|
gen all(
|
||||||
from <- optional_date_gen(),
|
which <- member_of([:from_only, :to_only, :both]),
|
||||||
to <- optional_date_gen(),
|
date_a <- date_gen(),
|
||||||
from != nil or to != nil
|
date_b <- date_gen()
|
||||||
) do
|
) do
|
||||||
{from, to}
|
case which do
|
||||||
|
:from_only -> {date_a, nil}
|
||||||
|
:to_only -> {nil, date_a}
|
||||||
|
:both -> {date_a, date_b}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp value_date_gen do
|
defp value_date_gen, do: date_gen()
|
||||||
map(integer(-3650..3650), &Date.add(~D[2000-01-01], &1))
|
|
||||||
end
|
|
||||||
|
|
||||||
# Property -------------------------------------------------------------
|
# Property -------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue