Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int/2 generator is broken #40

Closed
essen opened this issue Dec 16, 2014 · 4 comments
Closed

int/2 generator is broken #40

essen opened this issue Dec 16, 2014 · 4 comments

Comments

@essen
Copy link
Contributor

essen commented Dec 16, 2014

Hello,

The following property:

prop_int2() ->
    ?FORALL(I, int(1, 12), begin io:format("~p~n", [I]), true end).

gives the following output:

3
.8
.10
.9
.5
.2
.10
.10
.3
.2
.17
.22
.24
.22
[...]
.59
.182
.2
.158
.185
.134
.10
.109
.113

As you can see the max limit is not enforced as one would expect. This makes generating integers between 1 and 12 difficult.

Changing "max" into "min" in the int/2 function seems to solve the problem:

3
.4
.7
.7
.8
.11
.5
.12
[...]
.3
.7
.8
.8
.9
.10
.5
.9
.6
.6
.3

If this seems correct I would like to submit a patch for this, but I am not sure how to write a test for it. Would using triq_dom:sample in a loop (run 100 times for example) be good enough? The only test seemingly similar I can see tests for boolean only.

@krestenkrab
Copy link
Owner

This test fails with the current code base:

prop_intrange() ->
    ?FORALL({X,Y},
            ?SUCHTHAT({XX,YY},
                      {int(), int()},
                      XX < YY),

            true = triq:counterexample( prop_intrange(X,Y))).

prop_intrange(X,Y) when X < Y ->
    ?FORALL(I, int(X,Y),
            ?WHENFAIL(io:format("Min=~p, Max=~p, I=~p~n", [X,Y,I]),
                      (I >= X) andalso (I =< Y))).

Basically, it just invokes trip recursively for each set of {X,Y} values.

The failure looks like this:

Ran 100 tests
Testing triq_tests:prop_intrange/0
.Failed!
Min=0, Max=1, I=2

Failed after 2 tests with false
Simplified:
    I = 2
Failed with: [2]

Failed after 1 tests with [2]
Simplified:
    { X , Y } = {0,0}
triq_tests: run_property_testing_test_...*failed*

Now try fixing that :-)

@essen
Copy link
Contributor Author

essen commented Dec 17, 2014

Wow that's much better yes. I will do that now.

@essen
Copy link
Contributor Author

essen commented Dec 17, 2014

See #41.

@krestenkrab
Copy link
Owner

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants