Skip to content

Commit 190ed77

Browse files
committed
test scaled tolerance on =~= and <=>
1 parent 16b3b97 commit 190ed77

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

β€ŽS03-operators/comparison.tβ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 49;
4+
plan 53;
55

66
# N.B.: relational ops are in relational.t
77

@@ -37,9 +37,13 @@ is NaN cmp 1, More, "NaN generic comparison sorts NaN in with alphabetics";
3737
is NaN cmp NaN, Same, "NaN generic comparison sorts NaN in with alphabetics";
3838

3939
is exp(i * pi) <=> -1, Same, "<=> ignores tiny imaginary values";
40+
is exp(i * pi) * 1e10 <=> -1 * 1e10, Same, "<=> ignores tiny imaginary values, scaled up";
41+
is exp(i * pi) * 1e-10 <=> -1 * 1e-10, Same, "<=> ignores tiny imaginary values, scaled down";
4042
{
41-
my $*SIGNIFICANCE = 1e-20;
43+
my $*TOLERANCE = 1e-18;
4244
throws-like 'exp(i * pi) <=> -1', Exception, "(unless they exceed the signficance)";
45+
throws-like 'exp(i * pi) * 1e10 <=> -1 * 1e10', Exception, "(still fails scaled up)";
46+
throws-like 'exp(i * pi) * 1e-10 <=> -1 * 1e-10', Exception, "(still fails scaled down)";
4347
}
4448

4549
# leg comparison (Str)

β€ŽS03-operators/relational.tβ€Ž

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 132;
4+
plan 144;
55

66
## N.B.: Tests for infix:Β«<=>Β» (spaceship) and infix:<cmp> belong
77
## in F<t/S03-operators/comparison.t>.
@@ -183,13 +183,30 @@ ok exp(i * pi) =~= -1, "=~= does approximate equality";
183183
ok exp(i * pi) β‰… -1, "β‰… does approximate equality";
184184
185185
{
186-
my $*SIGNIFICANCE = 0.1;
187-
ok 1.01 =~= 1, '=~= pays attention to $*SIGNIFICANCE (More)';
188-
ok 0.99 =~= 1, '=~= pays attention to $*SIGNIFICANCE (Less)';
189-
ok 1.01 β‰… 1, 'β‰… pays attention to $*SIGNIFICANCE (More)';
190-
ok 0.99 β‰… 1, 'β‰… pays attention to $*SIGNIFICANCE (Less)';
191-
nok 1.2 β‰… 1, 'β‰… pays attention to $*SIGNIFICANCE (more More)';
192-
nok 0.8 β‰… 1, 'β‰… pays attention to $*SIGNIFICANCE (more Less)';
186+
my $*TOLERANCE = 0.1;
187+
ok 1.01 =~= 1, '=~= pays attention to $*TOLERANCE (More)';
188+
ok 0.99 =~= 1, '=~= pays attention to $*TOLERANCE (Less)';
189+
ok 1.01 β‰… 1, 'β‰… pays attention to $*TOLERANCE (More)';
190+
ok 0.99 β‰… 1, 'β‰… pays attention to $*TOLERANCE (Less)';
191+
nok 1.2 β‰… 1, 'β‰… pays attention to $*TOLERANCE (more More)';
192+
nok 0.8 β‰… 1, 'β‰… pays attention to $*TOLERANCE (more Less)';
193+
194+
# β‰… is scaled up to larger arg
195+
ok 101 =~= 100, '=~= pays attention to scaled-up $*TOLERANCE (More)';
196+
ok 99 =~= 100, '=~= pays attention to scaled-up $*TOLERANCE (Less)';
197+
ok 101 β‰… 100, 'β‰… pays attention to scaled-up $*TOLERANCE (More)';
198+
ok 99 β‰… 100, 'β‰… pays attention to scaled-up $*TOLERANCE (Less)';
199+
nok 120 β‰… 100, 'β‰… pays attention to scaled-up $*TOLERANCE (more More)';
200+
nok 80 β‰… 100, 'β‰… pays attention to scaled-up $*TOLERANCE (more Less)';
201+
202+
# β‰… is scaled down to larger arg
203+
ok 0.00101 =~= .001, '=~= pays attention to scaled-down $*TOLERANCE (More)';
204+
ok 0.00099 =~= .001, '=~= pays attention to scaled-down $*TOLERANCE (Less)';
205+
ok 0.00101 β‰… .001, 'β‰… pays attention to scaled-down $*TOLERANCE (More)';
206+
ok 0.00099 β‰… .001, 'β‰… pays attention to scaled-down $*TOLERANCE (Less)';
207+
nok 0.00120 β‰… .001, 'β‰… pays attention to scaled-down $*TOLERANCE (more More)';
208+
nok 0.00080 β‰… .001, 'β‰… pays attention to scaled-down $*TOLERANCE (more Less)';
209+
193210
}
194211
195212
# vim: ft=perl6

β€ŽS32-num/complex.tβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ is_approx e.log(1i), -2i / pi, "log e base i == -2i / pi";
167167
is <0+NaNi> cmp <0+0i>, More, "<0+NaNi> cmp <0+0i>";
168168
}
169169

170-
ok Num(i ** 2) == -1, 'Num(Complex) pays attention to $*SIGNIFICANCE';
170+
ok Num(exp i * Ο€) == -1, 'Num(Complex) pays attention to $*TOLERANCE';
171171
{
172-
my $*SIGNIFICANCE = 1e-20;
173-
throws-like 'Num(i ** 2)', Exception, 'Num(Complex) pays attention to $*SIGNIFICANCE';
172+
my $*TOLERANCE = 1e-20;
173+
throws-like 'Num(exp i * Ο€)', Exception, 'Num(Complex) pays attention to $*TOLERANCE';
174174
}
175175

176176
# vim: ft=perl6

0 commit comments

Comments
Β (0)