Skip to content

[Intro to property based tests] Configure Values property of quick.Config to ensure property test coverage #884

@evanash16

Description

@evanash16

Even with MaxCount configured at 1000, it is technically possible that quick.Check passes values to our assertion function which fall outside of the range of [0, 3999]. In this case, due to the arabic > 3999 check in the assertion function, all of the tests would automatically pass and not catch any issues, making the test suite somewhat unreliable. This is even more apparent if you use a uint64 instead of a uint16.

To ensure that our property test is respecting the implicit restrictions of the ConvertToRoman and ConvertToArabic functions (which cannot accept or return a value greater than 3999, as called out in the book), it might be useful to inform readers about the Values property of quick.Config, as well, which can hardcode known "properties" (no pun intended) of a given implementation which cannot necessarily be represented with Go types and reflected automatically by the property testing library. For example, with the following config, we can guarantee that every test iteration in TestPropertiesOfConversion actually validates the implementation:

...
Values: func(args []reflect.Value, r *rand.Rand) {
    args[0] = reflect.ValueOf(uint16(r.Intn(4000)))
},
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions