Permalink
Browse files

[t/spec] Add some basic tests for complex addition and subtraction.

git-svn-id: http://svn.pugscode.org/pugs@28517 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 5e87c2a commit 06c877b81ab305e94a3f4134534ce0d84f843323 colomon committed Sep 30, 2009
Showing with 40 additions and 1 deletion.
  1. +40 −1 S32-num/complex.t
View
@@ -2,10 +2,48 @@ use v6;
use Test;
-plan 140;
+plan *;
# Basic tests functions specific to complex numbers.
+isa_ok(1 + 2i, Complex, 'postfix:<i> creates a Complex number');
+
+# MUST: test .perl, .Str
+
+my @examples = (0i, 1 + 0i, -1 + 0i, 1i, -1i, 2 + 0i, -2 + 0i, 2i, -2i,
+ 2 + 3i, 2 - 3i, -2 + 3i, -2 - 3i,
+ cis(1.1), cis(3.1), cis(5.1), 35.unpolar(0.8), 40.unpolar(3.7));
+
+for @examples -> $z {
+ is_approx($z + 0, $z, "$z + 0 = $z");
+ is_approx(0 + $z, $z, "0 + $z = $z");
+ is_approx($z + 0.0, $z, "$z + 0.0 = $z");
+ is_approx(0.0 + $z, $z, "0.0 + $z = $z");
+ is_approx($z + 0 / 1, $z, "$z + 0/1 = $z");
+ is_approx(0 / 1 + $z, $z, "0/1 + $z = $z");
+
+ is_approx($z - 0, $z, "$z - 0 = $z");
+ is_approx(0 - $z, -$z, "0 - $z = -$z");
+ is_approx($z - 0.0, $z, "$z - 0.0 = $z");
+ is_approx(0.0 - $z, -$z, "0.0 - $z = -$z");
+ is_approx($z - 0 / 1, $z, "$z - 0/1 = $z");
+ is_approx(0 / 1 - $z, -$z, "0/1 - $z = -$z");
+
+ is_approx($z + 2, $z.re + 2 + ($z.im)i, "$z + 2");
+ is_approx(2 + $z, $z.re + 2 + ($z.im)i, "2 + $z");
+ is_approx($z + 2.5, $z.re + 2.5 + ($z.im)i, "$z + 2.5 = $z");
+ is_approx(2.5 + $z, $z.re + 2.5 + ($z.im)i, "2.5 + $z = $z");
+ is_approx($z + 3 / 2, $z.re + 3/2 + ($z.im)i, "$z + 3/2");
+ is_approx(3 / 2 + $z, $z.re + 3/2 + ($z.im)i, "3/2 + $z");
+
+ is_approx($z - 2, $z.re - 2 + ($z.im)i, "$z - 2");
+ is_approx(2 - $z, -$z.re + 2 - ($z.im)i, "2 - $z");
+ is_approx($z - 2.5, $z.re - 2.5 + ($z.im)i, "$z - 2.5 = $z");
+ is_approx(2.5 - $z, -$z.re + 2.5 - ($z.im)i, "2.5 - $z = $z");
+ is_approx($z - 3 / 2, $z.re - 3/2 + ($z.im)i, "$z - 3/2");
+ is_approx(3 / 2 - $z, -$z.re + 3/2 - ($z.im)i, "3/2 - $z");
+}
+
# L<S32::Numeric/Complex/=item re>
# L<S32::Numeric/Complex/=item im>
@@ -84,5 +122,6 @@ my $pi = 3.141592653589793238;
is_approx(4.unpolar($pi), -4, "4.unpolar(pi) == -4");
}
+done_testing;
# vim: ft=perl6

0 comments on commit 06c877b

Please sign in to comment.