Skip to content

Instantly share code, notes, and snippets.

@timo
Created June 19, 2013 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timo/173b1696cbecf4c28500 to your computer and use it in GitHub Desktop.
Save timo/173b1696cbecf4c28500 to your computer and use it in GitHub Desktop.
From dea51d09b2580e8d8fafa5ca1724d21de5e0164e Mon Sep 17 00:00:00 2001
From: Timo Paulssen <timonator@perpetuum-immobile.de>
Date: Wed, 19 Jun 2013 17:22:13 +0200
Subject: [PATCH] div by 0 soft-failure tests for Rat, Num.
---
S02-magicals/dollar_bang.t | 5 +----
S03-operators/div.t | 10 ++++++++++
S32-num/rat.t | 4 +++-
3 files changed, 14 insertions(+), 5 deletions(-)
create mode 100644 S03-operators/div.t
diff --git a/S02-magicals/dollar_bang.t b/S02-magicals/dollar_bang.t
index a7b48e6..805d6c9 100644
--- a/S02-magicals/dollar_bang.t
+++ b/S02-magicals/dollar_bang.t
@@ -2,7 +2,7 @@ use v6;
use Test;
-plan 16;
+plan 15;
=begin desc
@@ -28,9 +28,6 @@ try { eval 'foo(@a,@a)' };
ok $!.defined, 'Calling a subroutine with a nonmatching signature sets $!';
ok !$called, 'The subroutine also was not called';
-try { 1 div 0 };
-ok $!.defined, 'Dividing one by zero sets $!';
-
sub incr ( $a is rw ) { $a++ };
try { incr(19) };
ok $!.defined, 'Modifying a constant sets $!';
diff --git a/S03-operators/div.t b/S03-operators/div.t
new file mode 100644
index 0000000..a2952e3
--- /dev/null
+++ b/S03-operators/div.t
@@ -0,0 +1,10 @@
+use Test;
+
+plan 6;
+
+isa_ok 10 div 0 , Failure, "10 div 0 softfails";
+isa_ok 10 / 0 , Rat, "10 / 0 is a Rat.";
+isa_ok 10 / 0.0 , Rat, "10 / 0.0 is a rat";
+isa_ok 10 / 0e0 , Failure, "10 / 0e0 softfails";
+isa_ok (1/1) / 0e0, Failure, "(1/1) / 0e0 softfails";
+isa_ok 1e0 / (0/1), Failure, "1e0 / (0/1) softfails";
diff --git a/S32-num/rat.t b/S32-num/rat.t
index 0ba2b83..358f9db 100644
--- a/S32-num/rat.t
+++ b/S32-num/rat.t
@@ -153,11 +153,13 @@ is((2 / (2 / 3)).nude, (3, 1), "2 / 2/3 = 3 is simplified internally");
is_approx sin(5.0e0), sin(10/2), 'sin(Rat) works';
-# SHOULD: Add divide by zero / zero denominator tests
+# SHOULD: Add zero denominator tests
# Added three constructor tests above. Unsure about the
# wisdom of allowing math with zero denominator Rats,
# so I'm holding off on writing tests for it.
+# there are a few division by zero tests in S03-operator/div.t
+
#?niecza todo
#?pugs todo 'NaN.Rat'
is NaN.Rat, NaN, "NaN.Rat == NaN";
--
1.7.10.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment