Skip to content

Commit

Permalink
Test Str.Num/&val/num literal give same results
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Apr 13, 2018
1 parent db0c58b commit 4da5909
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
17 changes: 16 additions & 1 deletion S02-types/num.t
Expand Up @@ -4,7 +4,7 @@ use Test;

#L<S02/The C<Num> and C<Rat> Types/Perl 6 intrinsically supports big integers>

plan 104;
plan 105;

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' );
Expand Down Expand Up @@ -826,4 +826,19 @@ cmp-ok "9.9989999999999991e0".EVAL, &[!<], "9.998999999999999e0".EVAL,
cmp-ok Num(0.777777777777777777777), '==', Num(0.7777777777777777777771),
'Rat->Num conversion is monotonic';

subtest 'parsed nums are the same as those produced from Str.Num' => {
plan 6;
is '9.998999999999999e0'.EVAL, '9.998999999999999e0',
'parsed number stringification';
is '9.998999999999999e0'.Num, '9.998999999999999e0',
'Str.Num stringification';
is val('9.998999999999999e0').Numeric.Str, '9.998999999999999e0',
'val().Numeric.Str stringification';

cmp-ok '9.998999999999999e0'.EVAL, '==', '9.998999999999999e0'.Num,
'parsed matches Str.Num';
cmp-ok '9.998999999999999e0'.EVAL, '==', val('9.998999999999999e0'),
'parsed matches val()';
}

# vim: ft=perl6
17 changes: 16 additions & 1 deletion S32-num/stress.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 1;
plan 2;

# https://github.com/rakudo/rakudo/issues/1651
subtest 'No drift when roundtripping Num -> Str -> Num -> Str' => {
Expand All @@ -28,4 +28,19 @@ subtest 'No drift when roundtripping Num -> Str -> Num -> Str' => {
}
}

# RT#128914
subtest 'parsed literals match &val and Str.Num' => {
plan 2*my $rounds = 100;
sub gen-num {
('.', ^9 .roll: 20).flat.List.rotate(-19.rand.Int).join
~ 'e' ~ (-324..308).pick
}

for ^$rounds {
my $n := gen-num;
cmp-ok $n.EVAL, '==', $n.Num, "parsed literal == Str.Num [$n]";
cmp-ok $n.EVAL, '==', val($n), "parsed literal == val() [$n]";
}
}

# vim: ft=perl6

0 comments on commit 4da5909

Please sign in to comment.