Skip to content

Commit

Permalink
Replace deprecated is_approx with is-approx
Browse files Browse the repository at this point in the history
is_approx will reach the end of its deprecation cycle on Dec. 17. Replace it
with the new version, the is-approx. The new is-approx without explicit
tolerance provided behaves exactly as old is_approx as of today[^1], so this
commit makes no functional changes and all tests function the same.

Method used:
1) find . -iname '*' -exec perl -pi -e \
    's/(^|\s)is_approx(\(|\s)/${1}is-approx${2}/g' {} \;
2) Check manually to ensure all substitutions are done on is_approx
    without custom tolerances.
3) ???
4) Profit!

[1] rakudo/rakudo@82432a4
  • Loading branch information
zoffixznet committed Oct 19, 2016
1 parent afd32c2 commit 40f6f5b
Show file tree
Hide file tree
Showing 45 changed files with 929 additions and 929 deletions.
12 changes: 6 additions & 6 deletions S02-literals/numeric.t
Expand Up @@ -13,7 +13,7 @@ does-ok 1.Num, Real, '1.Num does Real';

# L<S02/Rational literals/Rational literals are indicated>

is_approx <1/2>, 0.5, '<1/2> Rat literal';
is-approx <1/2>, 0.5, '<1/2> Rat literal';
isa-ok <1/2>, Rat, '<1/2> produces a Rat';
does-ok <1/2>, Numeric, '<1/2> does Numeric';
does-ok <1/2>, Real, '<1/2> does Real';
Expand Down Expand Up @@ -60,16 +60,16 @@ is <-3.5-2.5i>, -3.5 - 2.5i, '-<3.5-2.5i> produces correct value';
is <+3.1e10+2.9e10i>, 3.1e10 + 2.9e10i, '<3.1e10+2.9e10i> produces correct value';
is <+3.1e+11+2.9e+11i>, 3.1e11 + 2.9e11i, '<+3.1e+11+2.9e+11i> produces correct value';
is <-3.1e+12-2.9e+12i>, -3.1e+12 + -2.9e+12i, '<-3.1e+12-2.9e+12i> produces correct value';
is_approx <-3.1e-23-2.9e-23i>.re, -3.1e-23, '<-3.1e-23-2.9e-23i> produces correct real value';
is_approx <-3.1e-23-2.9e-23i>.im, -2.9e-23, '<-3.1e-23-2.9e-23i> produces correct imaginary value';
is_approx <3.1e-99+2.9e-99i>.re, 3.1e-99, '<3.1e-99+2.9e-99i> produces correct real value';
is_approx <3.1e-99+2.9e-99i>.im, 2.9e-99, '<3.1e-99+2.9e-99i> produces correct imaginary value';
is-approx <-3.1e-23-2.9e-23i>.re, -3.1e-23, '<-3.1e-23-2.9e-23i> produces correct real value';
is-approx <-3.1e-23-2.9e-23i>.im, -2.9e-23, '<-3.1e-23-2.9e-23i> produces correct imaginary value';
is-approx <3.1e-99+2.9e-99i>.re, 3.1e-99, '<3.1e-99+2.9e-99i> produces correct real value';
is-approx <3.1e-99+2.9e-99i>.im, 2.9e-99, '<3.1e-99+2.9e-99i> produces correct imaginary value';

is <NaN+Inf\i>, NaN + Inf\i, '<NaN+Inf\i> produces correct value';
is <NaN-Inf\i>, NaN - Inf\i, '<NaN-Inf\i> produces correct value';

# RT #74640
is_approx 3.14159265358979323846264338327950288419716939937510e0,
is-approx 3.14159265358979323846264338327950288419716939937510e0,
3.141592, 'very long Num literals';

# RT #73236
Expand Down
8 changes: 4 additions & 4 deletions S02-literals/radix.t
Expand Up @@ -125,20 +125,20 @@ is(:16('0d37'), 0x0D37, ":16('0d37') uses d as hex digit" );
# It seems odd that the numbers on the inside on the <> would be a mix of
# bases. Maybe I've misread the paragraph -- brian
{
is_approx(:16<dead_beef> * 16**8, :16<dead_beef*16**8>,
is-approx(:16<dead_beef> * 16**8, :16<dead_beef*16**8>,
'Powers outside same as powers inside');

is_approx(:16<dead_beef> * 16**0, :16<dead_beef*16**0>,
is-approx(:16<dead_beef> * 16**0, :16<dead_beef*16**0>,
'Zero powers inside');

#?rakudo skip "RT #123862 - negative radix"
is_approx(:16<dead_beef> * 16**-1, :16<dead_beef*16**-1>,
is-approx(:16<dead_beef> * 16**-1, :16<dead_beef*16**-1>,
'Negative powers inside');
}

# L<S02/General radices/"Any radix may include a fractional part">

is_approx(:16<dead_beef.face>, 0xDEAD_BEEF + 0xFACE / 65536.0, 'Fractional base 16 works' );
is-approx(:16<dead_beef.face>, 0xDEAD_BEEF + 0xFACE / 65536.0, 'Fractional base 16 works' );


# L<S02/General radices/":8<177777>">
Expand Down
2 changes: 1 addition & 1 deletion S02-types/instants-and-durations.t
Expand Up @@ -11,7 +11,7 @@ plan 33;
isa-ok 5 + $i, Instant, 'Int + Instant ~~ Instant';
isa-ok $i - 1/3, Instant, 'Instant - Rat ~~ Instant';
my $later = now;
is_approx $i, $later, 'now and just now are close';
is-approx $i, $later, 'now and just now are close';
ok $later >= $i, 'time does not move backwards';
}

Expand Down
12 changes: 6 additions & 6 deletions S02-types/num.t
Expand Up @@ -7,17 +7,17 @@ use Test;
plan 86;

isa-ok( EVAL(1.Num.perl), Num, 'EVAL 1.Num.perl is Num' );
is_approx( EVAL(1.Num.perl), 1, 'EVAL 1.Num.perl is 1' );
is-approx( EVAL(1.Num.perl), 1, 'EVAL 1.Num.perl is 1' );
isa-ok( EVAL(0.Num.perl), Num, 'EVAL 0.Num.perl is Num' );
is_approx( EVAL(0.Num.perl), 0, 'EVAL 0.Num.perl is 0' );
is-approx( EVAL(0.Num.perl), 0, 'EVAL 0.Num.perl is 0' );
isa-ok( EVAL((-1).Num.perl), Num, 'EVAL -1.Num.perl is Num' );
is_approx( EVAL((-1).Num.perl), -1, 'EVAL -1.Num.perl is -1' );
is-approx( EVAL((-1).Num.perl), -1, 'EVAL -1.Num.perl is -1' );
isa-ok( EVAL(1.1.Num.perl), Num, 'EVAL 1.1.Num.perl is Num' );
is_approx( EVAL(1.1.perl), 1.1, 'EVAL 1.1.Num.perl is 1.1' );
is-approx( EVAL(1.1.perl), 1.1, 'EVAL 1.1.Num.perl is 1.1' );
isa-ok( EVAL((-1.1).Num.perl), Num, 'EVAL -1.1.Num.perl is Num' );
is_approx( EVAL((-1.1).perl), -1.1, 'EVAL -1.1.Num.perl is -1.1' );
is-approx( EVAL((-1.1).perl), -1.1, 'EVAL -1.1.Num.perl is -1.1' );
isa-ok( EVAL(1e100.Num.perl), Num, 'EVAL 1e100.Num.perl is Num' );
is_approx( EVAL(1e100.Num.perl), 1e100, 'EVAL 1e100.Num.perl is 1' );
is-approx( EVAL(1e100.Num.perl), 1e100, 'EVAL 1e100.Num.perl is 1' );

{
my $a = 1; "$a";
Expand Down
10 changes: 5 additions & 5 deletions S03-operators/arith.t
Expand Up @@ -191,8 +191,8 @@ tryeq -5.5 / -2, 2.75;

is 2**2, 4;
is 2.2**2, 4.84;
is_approx 2**2.2, 4.59479341;
is_approx 2.2**2.2, 5.66669577;
is-approx 2**2.2, 4.59479341;
is-approx 2.2**2.2, 5.66669577;
is 1**0, 1;
is 1**1, 1;
isnt 2**3**4, 4096, "** is right associative";
Expand All @@ -211,10 +211,10 @@ isnt 2**3**4, 4096, "** is right associative";
is 2 ** 2 ** 3, 256, 'infix:<**> is right associative';

{
is_approx(-1, (0 + 1i)**2, "i^2 == -1");
is-approx(-1, (0 + 1i)**2, "i^2 == -1");

is_approx(-1, (0.7071067811865476 + -0.7071067811865475i)**4, "sqrt(-i)**4 ==-1" );
is_approx(1i, (-1+0i)**0.5, '(-1+0i)**0.5 == i ');
is-approx(-1, (0.7071067811865476 + -0.7071067811865475i)**4, "sqrt(-i)**4 ==-1" );
is-approx(1i, (-1+0i)**0.5, '(-1+0i)**0.5 == i ');
}

{
Expand Down
6 changes: 3 additions & 3 deletions S03-operators/autovivification.t
Expand Up @@ -83,13 +83,13 @@ plan 23;
{
my $x;
$x = $x + 1i;
is_approx($x, 0 + 1i, 'my $x; $x = $x + 1i; works');
is-approx($x, 0 + 1i, 'my $x; $x = $x + 1i; works');
}

{
my $x;
$x += 1i;
is_approx($x, 0 + 1i, 'my $x; $x += 1i; works');
is-approx($x, 0 + 1i, 'my $x; $x += 1i; works');
}

{
Expand All @@ -101,7 +101,7 @@ plan 23;
{
my $x;
$x *= 1i;
is_approx($x, 1i, 'my $x; $x *= 1i works');
is-approx($x, 1i, 'my $x; $x *= 1i works');
}

# L<S03/Assignment operators/"If you apply an assignment operator to a
Expand Down
2 changes: 1 addition & 1 deletion S03-operators/overflow.t
Expand Up @@ -156,7 +156,7 @@ sub tryeq_sloppy ($lhs, $rhs, $todo1 = '') {
# Believe it or not, this one overflows on 32-bit Rakduo as of 3/8/2010.
{
# RT #73262
is_approx 7**(-1), 0.14285714285714, '7**(-1) works';
is-approx 7**(-1), 0.14285714285714, '7**(-1) works';
}

{
Expand Down
2 changes: 1 addition & 1 deletion S04-declarations/implicit-parameter.t
Expand Up @@ -14,7 +14,7 @@ plan 20;
{
# test with implicit $_
my $f2 = { .sqrt };
is_approx $f2(4), 2, 'Block with implicit $_ has one formal parameter';
is-approx $f2(4), 2, 'Block with implicit $_ has one formal parameter';
}

{
Expand Down
6 changes: 3 additions & 3 deletions S06-operator-overloading/workout.t
Expand Up @@ -37,7 +37,7 @@ multi sub infix:<T**>(Vector $a, $b) { Vector.new($a.coords >>**>> $b); }
multi sub infix:<>(Vector $a, Vector $b) { [+]($a.coords »*« $b.coords); }
multi sub infix:<dot>(Vector $a, Vector $b) { [+]($a.coords >>*<< $b.coords); }

### note the is_approx from Test.pm doesn't lift infix:<-> and abs,
### note the is-approx from Test.pm doesn't lift infix:<-> and abs,
# so we can't expect it work with class Vector. Thus we re-make one that does
# the custom ops

Expand All @@ -52,8 +52,8 @@ sub ia($got, $expected, $descr = "$got is approximately $expected") {
?$test;
}

# a few Vector sanity tests, verifying we can use is_approx for Vectors
# Note that this assumes that is_approx (1) lifts its operators (See S04)
# a few Vector sanity tests, verifying we can use is-approx for Vectors
# Note that this assumes that is-approx (1) lifts its operators (See S04)
# and (2) uses the method form of abs(), or lifts abs() too.
# Needs more discussion and spec coverage.
{
Expand Down

0 comments on commit 40f6f5b

Please sign in to comment.