https://kotlinlang.org logo
#kotest
Title
# kotest
s

Srki Rakic

07/08/2021, 1:55 AM
Given a
listOf(localDate: LocalDate)
if one date is in the past, the function should return false. I see that
Arb.localDate
takes a min and max date, but what I’d like is to have a mix of valid and invalid dates, or empty list. How would I setup that property test? Shouldn’t this pass?
Copy code
test("debug") {
        Arb.list(
            Arb.localDate(maxDate = LocalDate.now().minusDays(30)),
            1..6
        ).merge(
            Arb.list(
                Arb.localDate(minDate = LocalDate.now().plusDays(30)),
                0..6
            )
        ).forAll {
            it.any { date -> date.isBefore(LocalDate.now()) }
        }
    }
This should have at least one date in the past?
e

Emil Kantis

07/08/2021, 6:00 AM
Easier way, I think?
Copy code
Arb.localDate().withEdgecases(LocalDate.now(), LocalDate.now().minusDays(1))
s

Srki Rakic

07/08/2021, 12:32 PM
Hey @Emil Kantis, thanks for the reply. I’m not sure I follow. Can you please explain how this would work for my use case? Basically I want a list of dates as an input with at least one date in the past.
Also I believe the test I posted should pass, but it doesn’t. For some reason, it still generates a list that has all dates in the future.
e

Emil Kantis

07/08/2021, 1:21 PM
forAll
means that every arbitrarily generated list must pass the condition. You have 2 list generators, one which will always generate 1-6 dates before today, and one which will generate 0-6 dates after today. The last generator will generate failing inputs
s

Srki Rakic

07/08/2021, 1:57 PM
Got it. So Maybe I’m misunderstanding how merge works. I though that there will be only one list generated from both generators (list1 + list2).