question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Poor numeric domain coverage when using default arbitraries

See original GitHub issue

Testing Problem

Poor numeric domain coverage when using default arbitraries. The property evenNumbersAreEvenAndSmall is not falsified by Jqwik 0.8.4 using the default jqwik.poperties in the tests below:

public class JqwikTests {

    public static final Condition<Long> EVEN = new Condition<>(x -> x % 2 == 0, "even");
    public static final Condition<Long> SMALL = new Condition<>(x -> x < 2000, "< 2000");

    @Provide
    Arbitrary<Long> evenNumbers() {
        return Arbitraries.longs().filter(l -> l % 2 == 0);
    }

    @Property
    void evenNumbersAreEven(@ForAll("evenNumbers") long evenNumber) {
        assertThat(evenNumber)
                .is(EVEN);
    }

    @Property
    void evenNumbersAreEvenAndSmall(@ForAll("evenNumbers") long evenNumber) {
        System.out.println(evenNumber);
        assertThat(evenNumber)
                .is(EVEN)
                .is(SMALL);
    }
}
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running JqwikTests
0
-9223372036854775808
8
-468
-214
284
186
... many more (993? :-)) numbers, but all roughly in the region (-500, 500)

The other tested frameworks (JunitQuickCheck, QuickTheories, VavrTest) are able to falsify this using default settings but have unusable or no shrinking.

Manually setting the range to (Long.MIN_VALUE + 1, Long.MAX_VALUE - 1) solves this as does increasing the number of tries.

Suggested Solution

The very small test domain (defaultMaxFromTries = Math.max(tries / 2 - 3, 3))) should either be documented quite prominently or increased (at least for int/long).

Discussion

Documenting does not need any further discussion I guess 😃

Increasing the test domain while keeping the number of tries obviously spreads out the sample data which might be wanted–or not.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jlinkcommented, Mar 1, 2018

I chose a different path. Random number generation now uses the whole domain between allowed min and max values. However, the full domain is divided into several partitions so that lower numbers are generated with a higher probability. The cut off point is determined by Math.max(tries / 2, 10).

@rkraneis I tried with your original example and evenNumbersAreEvenAndSmall is now successfully falsified.

0reactions
jlinkcommented, Mar 1, 2018

Change available in version 0.8.5-SNAPSHOT

Read more comments on GitHub >

github_iconTop Results From Across the Web

jqwik User Guide - 1.7.1
Here, the list is created using the default list arbitrary, but the String elements are generated using the arbitrary from the method shortStrings...
Read more >
NCBI Conserved Domain Database (CDD) Help - NIH
A superfamily cluster is a set of conserved domain models that generate overlapping annotation on the same protein sequences. These models are assumed...
Read more >
Microsoft Defender for Identity domain dominance security ...
This article explains the Microsoft Defender for Identity alerts issued when attacks, typically part of domain dominance phase efforts, ...
Read more >
Is it bad to have numbers in your start up name or domain ...
It is not necessarily bad to use a number in your startup name or domain name. But you will have to use with...
Read more >
What is a reasonable code coverage % for unit tests (and ...
In the real world of project teams with competing priorities, code coverage races to 0%. We need a required number in order to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found