Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix S02-literals/numeric.t
Some of the tests for different forms of Rat literals did so in a way
that calls will call .Numeric on Str (as well as any other non-Numeric
argument). Since a Rat literal that's not parsed correctly will be
interpreted as a Str, then as long as Str.Numeric can handle the given
Rat form any issues with Rat literals for those forms were hidden. These
tests were changed to ensure we don't numify any strings.

Also updated some of the tests to use the new 'does-ok' to check roles,
and replaced a smartmatch against Str with an 'isa-ok' check.
  • Loading branch information
ShimmerFairy committed Aug 28, 2015
1 parent edea297 commit cf775d3
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions S02-literals/numeric.t
Expand Up @@ -4,19 +4,19 @@ use Test;
plan 52;

isa-ok 1, Int, '1 produces a Int';
ok 1 ~~ Numeric, '1 is Numeric';
ok 1 ~~ Real, '1 is Real';
does-ok 1, Numeric, '1 does Numeric';
does-ok 1, Real, '1 does Real';

isa-ok 1.Num, Num, '1.Num produces a Int';
ok 1.Num ~~ Numeric, '1.Num is Numeric';
ok 1.Num ~~ Real, '1.Num is Real';
does-ok 1.Num, Numeric, '1.Num does Numeric';
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';
isa-ok <1/2>, Rat, '<1/2> produces a Rat';
ok <1/2> ~~ Numeric, '<1/2> is Numeric';
ok <1/2> ~~ Real, '<1/2> is Real';
does-ok <1/2>, Numeric, '<1/2> does Numeric';
does-ok <1/2>, Real, '<1/2> does Real';
isa-ok <0x01/0x02>, Rat, 'same with hexadecimal numbers';

ok <1/-3>.WHAT === Str, 'negative allowed only on numerator';
Expand All @@ -26,9 +26,9 @@ isa-ok <-1/3>, Rat, 'negative Rat literal';
ok <-1/3> * -3 == 1, 'negative Rat literal';

#?rakudo.jvm todo 'fails with "Attempt to divide by zero using div" on JVM RT #124559'
ok <0x01/0x03> / (0x01/0x03) == 1, 'Rat works with hexadecimal numbers';
ok <:13<01>/:13<07>> / (1/7) == 1, 'Rat works with colon radix numbers';
ok <:12<1a>/:12<7b>> / (:12<1a> / :12<7b>) == 1, 'Rat works with colon radix numbers';
is <0x01/0x03>, (0x01/0x03), 'Rat works with hexadecimal numbers';
is <:13<01>/:13<07>>, (1/7), 'Rat works with colon radix numbers';
is <:12<1a>/:12<7b>>, (:12<1a> / :12<7b>), 'Rat works with colon radix numbers';

# L<S02/Complex literals/Complex literals are similarly indicated>

Expand All @@ -38,9 +38,9 @@ isa-ok <-3+3i>, Complex, '<-3+3i> is a Complex literal';
isa-ok <+4-4i>, Complex, '<+4-4i> is a Complex literal';
isa-ok <-5-5i>, Complex, '<-5-5i> is a Complex literal';

ok <1+1i> ~~ Numeric, '1+1i is Numeric';
nok <1+1i> ~~ Real, '1+1i is not Real';
ok <1*1i> ~~ Str, '1*1i is a Str';
does-ok <1+1i>, Numeric, '1+1i does Numeric';
nok <1+1i>.does(Real), '1+1i doesn\'t do Real';
isa-ok <1*1i>, Str, '1*1i is a Str';

is <3+2i>, 3 + 2i, '<3+2i> produces correct value';
is <+3+2i>, +3 + 2i, '<+3+2i> produces correct value';
Expand All @@ -62,8 +62,8 @@ is_approx <-3.1e-23-2.9e-23i>.im, -2.9e-23, '<-3.1e-23-2.9e-23i> produces corre
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';
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,
Expand Down

0 comments on commit cf775d3

Please sign in to comment.