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

WITHIN() has exclusionary edges: is(1,within(0,1)) fails #937

Open
hbmaclean opened this issue Mar 23, 2023 · 0 comments
Open

WITHIN() has exclusionary edges: is(1,within(0,1)) fails #937

hbmaclean opened this issue Mar 23, 2023 · 0 comments

Comments

@hbmaclean
Copy link

within() considers the range boundaries to be NOT within. Under the covers, Test2::Tools::Compare->within() indirectly calls Test2::Compare::Float->verify(), which compares with < and >, rather than <= and >=.

Is this intended? In any case, please document the behavior.

Demonstration:

use Test2::V0;
is(55, within(54,1),      'on upper edge');
is(53, within(54,1),      'on lower edge');
is(55, within(54,2),      'wholly within range');
is(53, within(54,2),      'wholly within range');
is(55, within(54,1.0001), 'barely within range (workaround)');
is(53, within(54,1.0001), 'barely within range (workaround)');
done_testing();

# prove -v within.t

not ok 1 - on upper edge

# Failed test 'on upper edge'
# at within.t line 2.
# +-----+----+----------+-----+
# | GOT | OP | CHECK    | LNs |
# +-----+----+----------+-----+
# | 55  | == | 54 +/- 1 | 2   |
# +-----+----+----------+-----+
not ok 2 - on lower edge
ok 3 - wholly within range
ok 4 - wholly within range
ok 5 - barely within range (workaround)

# Failed test 'on lower edge'
# at within.t line 3.
# +-----+----+----------+-----+
# | GOT | OP | CHECK    | LNs |
# +-----+----+----------+-----+
# | 53  | == | 54 +/- 1 | 3   |
# +-----+----+----------+-----+
ok 6 - barely within range (workaround)
@exodist exodist transferred this issue from Test-More/Test2-Suite Aug 4, 2024
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

1 participant