# HG changeset patch # User Rik # Date 1508180314 25200 # Node ID 1a3229a2f1abf3678c22f91353b377974fa5da66 # Parent 2e64bed0bb3a420e56330dc39bc2a222b347bc3e integral2.m, integral3.m: Clean up BIST tests. * integral2.m, integral3.m: Clean up BIST tests. diff -r 2e64bed0bb3a -r 1a3229a2f1ab scripts/general/integral2.m --- 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 () diff -r 2e64bed0bb3a -r 1a3229a2f1ab scripts/general/integral3.m --- 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