Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 159 lines (129 sloc) 5.258 kb
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
ad1b86b [t] Test suite refactoring.
cosimo authored
2 use Test;
fa26638 @labster testing fix for RT #118545, round with scale argument
labster authored
3 plan 128;
ad1b86b [t] Test suite refactoring.
cosimo authored
4
b8d99dd [t/spec] fix more smartlinks
moritz authored
5 # L<S32::Numeric/Real/"=item round">
6 # L<S32::Numeric/Real/"=item floor">
7 # L<S32::Numeric/Real/"=item truncate">
8 # L<S32::Numeric/Real/"=item ceiling">
ad1b86b [t] Test suite refactoring.
cosimo authored
9
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
10 =begin pod
ad1b86b [t] Test suite refactoring.
cosimo authored
11
76f901d Tests for rounding NaN and Inf
leto authored
12 Basic tests for the round(), floor(), truncate() and ceiling() built-ins
ad1b86b [t] Test suite refactoring.
cosimo authored
13
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
14 =end pod
ad1b86b [t] Test suite refactoring.
cosimo authored
15
76f901d Tests for rounding NaN and Inf
leto authored
16 is( floor(NaN), NaN, 'floor(NaN) is NaN');
17 is( round(NaN), NaN, 'round(NaN) is NaN');
18 is( ceiling(NaN), NaN, 'ceiling(NaN) is NaN');
19 is( truncate(NaN), NaN, 'truncate(NaN) is NaN');
20
21 is( floor(Inf), Inf, 'floor(Inf) is Inf');
22 is( round(Inf), Inf, 'round(Inf) is Inf');
23 is( ceiling(Inf), Inf, 'ceiling(Inf) is Inf');
24 is( truncate(Inf), Inf, 'truncate(Inf) is Inf');
25
f4a4f4f [t/spec] Add tests for method forms.
colomon authored
26 is( floor(-Inf), -Inf, 'floor(-Inf) is -Inf');
27 is( round(-Inf), -Inf, 'round(-Inf) is -Inf');
28 is( ceiling(-Inf), -Inf, 'ceiling(-Inf) is -Inf');
29 is( truncate(-Inf), -Inf, 'truncate(-Inf) is -Inf');
30
31 is( NaN.floor, NaN, 'NaN.floor is NaN');
32 is( NaN.round, NaN, 'NaN.round is NaN');
33 is( NaN.ceiling, NaN, 'NaN.ceiling is NaN');
34 is( NaN.truncate, NaN, 'NaN.truncate is NaN');
35
36 is( Inf.floor, Inf, 'Inf.floor is Inf');
37 is( Inf.round, Inf, 'Inf.round is Inf');
38 is( Inf.ceiling, Inf, 'Inf.ceiling is Inf');
39 is( Inf.truncate, Inf, 'Inf.truncate is Inf');
40
41 is( (-Inf).floor, -Inf, '(-Inf).floor is -Inf');
42 is( (-Inf).round, -Inf, '(-Inf).round is -Inf');
43 is( (-Inf).ceiling, -Inf, '(-Inf).ceiling is -Inf');
44 is( (-Inf).truncate, -Inf, '(-Inf).truncate is -Inf');
45
ad1b86b [t] Test suite refactoring.
cosimo authored
46 my %tests =
47 ( ceiling => [ [ 1.5, 2 ], [ 2, 2 ], [ 1.4999, 2 ],
48 [ -0.1, 0 ], [ -1, -1 ], [ -5.9, -5 ],
61ad9ad [t/spec] Cut back on a few more or less duplicate tests.
colomon authored
49 [ -0.5, 0 ], [ "-0.499.Num", 0 ], [ "-5.499.Num", -5 ],
50 [ "2.Num", 2 ] ],
ad1b86b [t] Test suite refactoring.
cosimo authored
51 floor => [ [ 1.5, 1 ], [ 2, 2 ], [ 1.4999, 1 ],
52 [ -0.1, -1 ], [ -1, -1 ], [ -5.9, -6 ],
61ad9ad [t/spec] Cut back on a few more or less duplicate tests.
colomon authored
53 [ -0.5, -1 ], [ "-0.499.Num", -1 ], [ "-5.499.Num", -6 ],
54 [ "2.Num", 2 ] ],
ad1b86b [t] Test suite refactoring.
cosimo authored
55 round => [ [ 1.5, 2 ], [ 2, 2 ], [ 1.4999, 1 ],
56 [ -0.1, 0 ], [ -1, -1 ], [ -5.9, -6 ],
61ad9ad [t/spec] Cut back on a few more or less duplicate tests.
colomon authored
57 [ -0.5, 0 ], [ "-0.499.Num", 0 ], [ "-5.499.Num", -5 ],
58 [ "2.Num", 2 ] ],
ad1b86b [t] Test suite refactoring.
cosimo authored
59 truncate => [ [ 1.5, 1 ], [ 2, 2 ], [ 1.4999, 1 ],
60 [ -0.1, 0 ], [ -1, -1 ], [ -5.9, -5 ],
61ad9ad [t/spec] Cut back on a few more or less duplicate tests.
colomon authored
61 [ -0.5, 0 ], [ "-0.499.Num", 0 ], [ "-5.499.Num", -5 ],
62 [ "2.Num", 2 ] ],
ad1b86b [t] Test suite refactoring.
cosimo authored
63 );
64
7922e91 @KrisShannon Revert my last commit.
KrisShannon authored
65 #?pugs emit if $?PUGS_BACKEND ne "BACKEND_PUGS" {
66 #?pugs emit skip_rest "PIL2JS and PIL-Run do not support eval() yet.";
67 #?pugs emit exit;
68 #?pugs emit }
ad1b86b [t] Test suite refactoring.
cosimo authored
69
70 for %tests.keys.sort -> $type {
71 my @subtests = @(%tests{$type}); # XXX .[] doesn't work yet!
72 for @subtests -> $test {
62910e6 [t/spec] clean up of S29-num/rounders.t
moritz authored
73 my $code = "{$type}({$test[0]})";
ee7b7eb [t/spec] corrected rounders.t; fudged for rakudo (ugly mess)
moritz authored
74 my $res = eval($code);
75
ad1b86b [t] Test suite refactoring.
cosimo authored
76 if ($!) {
77 #?pugs todo 'feature'
78 flunk("failed to parse $code ($!)");
79 } else {
62910e6 [t/spec] clean up of S29-num/rounders.t
moritz authored
80 ok($res == $test[1], "$code == {$test[1]}");
ad1b86b [t] Test suite refactoring.
cosimo authored
81 }
82 }
83 }
84
f4a4f4f [t/spec] Add tests for method forms.
colomon authored
85
86 for %tests.keys.sort -> $type {
87 my @subtests = @(%tests{$type}); # XXX .[] doesn't work yet!
88 for @subtests -> $test {
89 my $code = "({$test[0]}).{$type}";
90 my $res = eval($code);
91
92 if ($!) {
93 #?pugs todo 'feature'
94 flunk("failed to parse $code ($!)");
95 } else {
96 ok($res == $test[1], "$code == {$test[1]}");
97 }
576906b [t] added named arg tests to trig and num functions
frew authored
98 }
99 }
100
6e20293 [t/spec] check that the rounder functions return Int values (RT #61526)
moritz authored
101 for %tests.keys.sort -> $t {
d413b87 @moritz rakudo fudges
moritz authored
102 isa_ok eval("{$t}(1.1)"), Int, "rounder $t returns an Int";
6e20293 [t/spec] check that the rounder functions return Int values (RT #61526)
moritz authored
103
104 }
105
fa26638 @labster testing fix for RT #118545, round with scale argument
labster authored
106 # RT #118545 Round with arguments
107 #?pugs 4 skip "round with arguments"
108 {
109 my $integer = 987654321;
110 is $integer.round(1), 987654321, "round integer with argument";
111 is $integer.round(5), 987654320, "($integer).round(5) == 987654320";
112 is $integer.round(1e5), 987700000, "($integer).round(1e5) == 987700000";
113 is 2.round(3/20), 1.95, "2.round(3/20) == 1.95";
114 }
115
116 #?pugs 4 skip "round with arguments"
117 {
118 my $num = 123.456789;
119 is $num.round(1), 123, "round with argument";
120 is $num.round(5), 125, "($num).round(5) == 125";
121 is $num.round(1/100), 123.46, "($num).round(1/100) == 123.46";
122 #?niecza todo "rounding with Num makes more rounding errors"
a3be3ac @coke Rakudo (jvm/parrot) un/fudge
coke authored
123 #?rakudo.jvm todo "nigh"
fa26638 @labster testing fix for RT #118545, round with scale argument
labster authored
124 is $num.round(1e-5), 123.45679, "($num).round(1e-5) == 123.45679";
125 }
126
127
128
129
e993f8d @colomon Add tests to make sure the rounding functions are not cheating.
colomon authored
130 {
131 my $big-int = 1234567890123456789012345678903;
132 is $big-int.floor, $big-int, "floor passes bigints unchanged";
133 is $big-int.ceiling, $big-int, "ceiling passes bigints unchanged";
134 is $big-int.round, $big-int, "round passes bigints unchanged";
135 is $big-int.truncate, $big-int, "truncate passes bigints unchanged";
136 }
137
138 {
139 my $big-rat = 1234567890123456789012345678903 / 2;
140 my $big-int = 1234567890123456789012345678903 div 2;
141 is $big-rat.floor, $big-int, "floor handles Rats properly";
142 is $big-rat.ceiling, $big-int + 1, "ceiling handles Rats properly";
143 is $big-rat.round, $big-int + 1, "round handles Rats properly";
144 is $big-rat.truncate, $big-int, "truncate handles Rats properly";
145 }
146
147 {
148 my $big-rat = FatRat.new(1234567890123456789012345678903, 2);
149 my $big-int = 1234567890123456789012345678903 div 2;
150 is $big-rat.floor, $big-int, "floor handles FatRats properly";
151 is $big-rat.ceiling, $big-int + 1, "ceiling handles FatRats properly";
152 is $big-rat.round, $big-int + 1, "round handles FatRats properly";
153 is $big-rat.truncate, $big-int, "truncate handles FatRats properly";
154 }
155
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
156 done;
752d480 [t/spec] Unfudge a tad.
colomon authored
157
6e20293 [t/spec] check that the rounder functions return Int values (RT #61526)
moritz authored
158 # vim: ft=perl6
Something went wrong with that request. Please try again.