Permalink
Browse files

Add tests to make sure the rounding functions are not cheating.

  • Loading branch information...
1 parent 2652a39 commit e993f8dc304b97f7012fd2718a486efb7484e2d9 @colomon colomon committed Dec 7, 2011
Showing with 28 additions and 1 deletion.
  1. +28 −1 S32-num/rounders.t
View
@@ -1,6 +1,6 @@
use v6;
use Test;
-plan 108;
+plan 120;
# L<S32::Numeric/Real/"=item round">
# L<S32::Numeric/Real/"=item floor">
@@ -103,6 +103,33 @@ for %tests.keys.sort -> $t {
}
+{
+ my $big-int = 1234567890123456789012345678903;
+ is $big-int.floor, $big-int, "floor passes bigints unchanged";
+ is $big-int.ceiling, $big-int, "ceiling passes bigints unchanged";
+ is $big-int.round, $big-int, "round passes bigints unchanged";
+ is $big-int.truncate, $big-int, "truncate passes bigints unchanged";
+}
+
+{
+ my $big-rat = 1234567890123456789012345678903 / 2;
+ my $big-int = 1234567890123456789012345678903 div 2;
+ is $big-rat.floor, $big-int, "floor handles Rats properly";
+ is $big-rat.ceiling, $big-int + 1, "ceiling handles Rats properly";
+ is $big-rat.round, $big-int + 1, "round handles Rats properly";
+ is $big-rat.truncate, $big-int, "truncate handles Rats properly";
+}
+
+#?rakudo skip "FatRat NYI"
+{
+ my $big-rat = FatRat.new(1234567890123456789012345678903, 2);
+ my $big-int = 1234567890123456789012345678903 div 2;
+ is $big-rat.floor, $big-int, "floor handles FatRats properly";
+ is $big-rat.ceiling, $big-int + 1, "ceiling handles FatRats properly";
+ is $big-rat.round, $big-int + 1, "round handles FatRats properly";
+ is $big-rat.truncate, $big-int, "truncate handles FatRats properly";
+}
+
done;
# vim: ft=perl6

0 comments on commit e993f8d

Please sign in to comment.