diff --git a/test/mv_web/live/member_live/date_filter_property_test.exs b/test/mv_web/live/member_live/date_filter_property_test.exs index fcce2a3..8844f91 100644 --- a/test/mv_web/live/member_live/date_filter_property_test.exs +++ b/test/mv_web/live/member_live/date_filter_property_test.exs @@ -20,11 +20,12 @@ defmodule MvWeb.MemberLive.Index.DateFilterPropertyTest do # Generators ----------------------------------------------------------- + defp date_gen do + map(integer(-3650..3650), &Date.add(~D[2000-01-01], &1)) + end + defp optional_date_gen do - one_of([ - constant(nil), - map(integer(-3650..3650), &Date.add(~D[2000-01-01], &1)) - ]) + one_of([constant(nil), date_gen()]) end defp exit_date_mode_gen do @@ -57,19 +58,25 @@ defmodule MvWeb.MemberLive.Index.DateFilterPropertyTest do # 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 gen all( - from <- optional_date_gen(), - to <- optional_date_gen(), - from != nil or to != nil + which <- member_of([:from_only, :to_only, :both]), + date_a <- date_gen(), + date_b <- date_gen() ) do - {from, to} + case which do + :from_only -> {date_a, nil} + :to_only -> {nil, date_a} + :both -> {date_a, date_b} + end end end - defp value_date_gen do - map(integer(-3650..3650), &Date.add(~D[2000-01-01], &1)) - end + defp value_date_gen, do: date_gen() # Property -------------------------------------------------------------