changeset 24149:1a3229a2f1ab

integral2.m, integral3.m: Clean up BIST tests. * integral2.m, integral3.m: Clean up BIST tests.
author Rik <rik@octave.org>
date Mon, 16 Oct 2017 11:58:34 -0700
parents 2e64bed0bb3a
children a386810e8693
files scripts/general/integral2.m scripts/general/integral3.m
diffstat 2 files changed, 22 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/integral2.m	Sat Oct 14 18:30:51 2017 -0400
+++ b/scripts/general/integral2.m	Mon Oct 16 11:58:34 2017 -0700
@@ -257,49 +257,43 @@
 ## vectorized = false test
 %!test
 %! f = @(x, y) x * y;
-%! assert (integral2 (f, 0, 1, 0, 1, "vectorized", false), 0.25, 1e-10);
+%!assert (integral2 (f, 0, 1, 0, 1, "vectorized", false), 0.25, 1e-10)
 
 ## tolerance tests
-%!shared f
+%!test
 %! f = @(x, y) 9 * x.^2 + 15 * y.^2;
-
 %!assert (integral2 (f, 0, 5, -5, 0, "AbsTol", 1e-9), 5000, 1e-9)
 %!assert (integral2 (f, 0, 5, -5, 0, "RelTol", 1e-5), 5000, -1e-5)
-%!assert (integral2 (f, 0, 5, -5, 0, "RelTol", 1e-6, "AbsTol", 1e-9),
-%!        5000, 1e-9)
+%!assert (integral2 (f, 0, 5, -5, 0, "RelTol", 1e-6, "AbsTol", 1e-9), 5000, 1e-9)
 
 ## tests from dblquad
-%!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1, "AbsTol", 1e-7),
-%!        2*log (2), 1e-7)
-%!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1, "RelTol", 1e-5),
-%!        2*log (2), -1e-5)
-%!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1, "AbsTol", 1e-8,
-%!                                                   "RelTol", 1e-6),
+%!test
+%! f = @(x, y) 1 ./ (x+y);
+%!assert (integral2 (f, 0, 1, 0, 1, "AbsTol", 1e-7), 2*log (2), 1e-7)
+%!assert (integral2 (f, 0, 1, 0, 1, "RelTol", 1e-5), 2*log (2), -1e-5)
+%!assert (integral2 (f, 0, 1, 0, 1, "AbsTol", 1e-8, "RelTol", 1e-6),
 %!        2*log (2), -1e-6)
+%!assert (integral2 (f, 0, 1, 0, @(x) 1 - x), 1, -1e-6)
+
 %!assert (integral2 (@(x, y) exp (-x.^2 - y.^2) , -1, 1, -1, 1),
 %!        pi * erf (1).^2, 1e-10)
 
 %!assert (integral2 (@plus, 1, 2, 3, 4), 5, 1e-10)
-%!assert (integral2 (@(x,y) 1 ./ (x + y), 0, 1, 0, @(x) 1 - x), 1, -1e-6)
 
 ## tests from dblquad w/method specified
-%!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1,
-%!                   "AbsTol", 1e-7, "method", "iterated"),
+%!assert (integral2 (f, 0, 1, 0, 1, "AbsTol", 1e-7, "method", "iterated"),
 %!        2*log (2), 1e-7)
-%!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1,
-%!                   "RelTol", 1e-5, "method", "iterated"),
+%!assert (integral2 (f, 0, 1, 0, 1, "RelTol", 1e-5, "method", "iterated"),
 %!        2*log (2), -1e-5)
-%!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1,
-%!                   "AbsTol", 1e-8, "RelTol", 1e-6, "method", "iterated"),
+%!assert (integral2 (f, 0, 1, 0, 1, "AbsTol", 1e-8, "RelTol", 1e-6,
+%!                                  "Method", "iterated"),
 %!        2*log (2), -1e-6)
+%!assert (integral2 (f, 0, 1, 0, @(x) 1 - x, "Method", "iterated"), 1, -1e-6)
 %!assert (integral2 (@(x, y) exp (-x.^2 - y.^2) , -1, 1, -1, 1,
-%!                   "method", "iterated"),
+%!                                                "Method", "iterated"),
 %!        pi * erf (1).^2, 1e-10)
 
 %!assert (integral2 (@plus, 1, 2, 3, 4, "method", "iterated"), 5, 1e-10)
-%!assert (integral2 (@(x,y) 1 ./ (x + y), 0, 1, 0, @(x) 1 - x,
-%!                   "method", "iterated"),
-%!        1, -1e-6)
 
 ## Test input validation
 %!error integral2 ()
--- a/scripts/general/integral3.m	Sat Oct 14 18:30:51 2017 -0400
+++ b/scripts/general/integral3.m	Mon Oct 16 11:58:34 2017 -0700
@@ -283,9 +283,8 @@
 %! assert (integral3 (f, 0, 1, 0, 1, 0, 1, "vectorized", false), 0.125, 1e-10);
 
 ## tolerance tests
-%!shared f
+%!test
 %! f = @(x, y, z) 2 * x.^2 + 3 * y.^2 + 4 * z.^2;
-
 %!assert (integral3 (f, 0, 5, -5, 0, 0, 5, "AbsTol", 1e-9), 9375, 1e-9)
 %!assert (integral3 (f, 0, 5, -5, 0, 0, 5, "RelTol", 1e-5), 9375, -1e-5)
 %!assert (integral3 (f, 0, 5, -5, 0, 0, 5, "RelTol", 1e-6, "AbsTol", 1e-9),
@@ -293,8 +292,11 @@
 
 ## non-rectangular region
 ## This test is too slow with "iterated" method
-%!assert (integral3 (@(x,y,z) 1 ./ (x + y + z), 0, 1, 0, @(x) 1 - x, 0,
-%!        @(x, y) 1 - x - y, "method", "tiled"), 0.25, 1e-6)
+%!test
+%! f = @(x,y,z) 1 ./ (x + y + z);
+%! ymax = @(x) 1 - x;
+%! zmax = @(x, y) 1 - x - y;
+%! assert (integral3 (f, 0, 1, 0, ymax, 0, zmax, "method", "tiled"), 0.25, 1e-6);
 
 ## Test input validation
 %!error integral3