Skip to content
Newer
Older
100644 158 lines (128 sloc) 5.11 KB
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored May 8, 2008
1 use v6;
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
2 use Test;
fa26638 @labster testing fix for RT #118545, round with scale argument
labster authored Jul 2, 2013
3 plan 128;
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
4
b8d99dd [t/spec] fix more smartlinks
moritz authored Mar 15, 2010
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 Jan 24, 2008
9
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored Jan 27, 2008
10 =begin pod
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
11
76f901d Tests for rounding NaN and Inf
leto authored Feb 24, 2009
12 Basic tests for the round(), floor(), truncate() and ceiling() built-ins
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
13
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored Jan 27, 2008
14 =end pod
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
15
76f901d Tests for rounding NaN and Inf
leto authored Feb 24, 2009
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 May 14, 2010
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 Jan 24, 2008
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 May 15, 2010
49 [ -0.5, 0 ], [ "-0.499.Num", 0 ], [ "-5.499.Num", -5 ],
50 [ "2.Num", 2 ] ],
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
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 May 15, 2010
53 [ -0.5, -1 ], [ "-0.499.Num", -1 ], [ "-5.499.Num", -6 ],
54 [ "2.Num", 2 ] ],
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
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 May 15, 2010
57 [ -0.5, 0 ], [ "-0.499.Num", 0 ], [ "-5.499.Num", -5 ],
58 [ "2.Num", 2 ] ],
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
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 May 15, 2010
61 [ -0.5, 0 ], [ "-0.499.Num", 0 ], [ "-5.499.Num", -5 ],
62 [ "2.Num", 2 ] ],
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
63 );
64
7922e91 @KrisShannon Revert my last commit.
KrisShannon authored Jan 8, 2012
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 Jan 24, 2008
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 Nov 12, 2008
73 my $code = "{$type}({$test[0]})";
ee7b7eb [t/spec] corrected rounders.t; fudged for rakudo (ugly mess)
moritz authored Sep 2, 2008
74 my $res = eval($code);
75
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
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 Nov 12, 2008
80 ok($res == $test[1], "$code == {$test[1]}");
ad1b86b [t] Test suite refactoring.
cosimo authored Jan 24, 2008
81 }
82 }
83 }
84
f4a4f4f [t/spec] Add tests for method forms.
colomon authored May 14, 2010
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 Jan 31, 2009
98 }
99 }
100
6e20293 [t/spec] check that the rounder functions return Int values (RT #61526)
moritz authored Dec 19, 2008
101 for %tests.keys.sort -> $t {
d413b87 @moritz rakudo fudges
moritz authored Dec 6, 2011
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 Dec 19, 2008
103
104 }
105
fa26638 @labster testing fix for RT #118545, round with scale argument
labster authored Jul 2, 2013
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"
123 is $num.round(1e-5), 123.45679, "($num).round(1e-5) == 123.45679";
124 }
125
126
127
128
e993f8d @colomon Add tests to make sure the rounding functions are not cheating.
colomon authored Dec 7, 2011
129 {
130 my $big-int = 1234567890123456789012345678903;
131 is $big-int.floor, $big-int, "floor passes bigints unchanged";
132 is $big-int.ceiling, $big-int, "ceiling passes bigints unchanged";
133 is $big-int.round, $big-int, "round passes bigints unchanged";
134 is $big-int.truncate, $big-int, "truncate passes bigints unchanged";
135 }
136
137 {
138 my $big-rat = 1234567890123456789012345678903 / 2;
139 my $big-int = 1234567890123456789012345678903 div 2;
140 is $big-rat.floor, $big-int, "floor handles Rats properly";
141 is $big-rat.ceiling, $big-int + 1, "ceiling handles Rats properly";
142 is $big-rat.round, $big-int + 1, "round handles Rats properly";
143 is $big-rat.truncate, $big-int, "truncate handles Rats properly";
144 }
145
146 {
147 my $big-rat = FatRat.new(1234567890123456789012345678903, 2);
148 my $big-int = 1234567890123456789012345678903 div 2;
149 is $big-rat.floor, $big-int, "floor handles FatRats properly";
150 is $big-rat.ceiling, $big-int + 1, "ceiling handles FatRats properly";
151 is $big-rat.round, $big-int + 1, "round handles FatRats properly";
152 is $big-rat.truncate, $big-int, "truncate handles FatRats properly";
153 }
154
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored Dec 31, 2010
155 done;
752d480 [t/spec] Unfudge a tad.
colomon authored May 14, 2010
156
6e20293 [t/spec] check that the rounder functions return Int values (RT #61526)
moritz authored Dec 19, 2008
157 # vim: ft=perl6
Something went wrong with that request. Please try again.