# HG changeset patch
# User marek_ka
# Date 1663705569 14400
#      Tue Sep 20 16:26:09 2022 -0400
# Node ID c72f293685b105844df9a49970e0d227a4b9efd5
# Parent  009e2be83f658a9104e6a41a030fc9efbfc3b317
Update tests for bug #63063 fix. Update bug fix for OutputSel in
scripts/ode/private/integrate_adaptive.m.

diff -r 009e2be83f65 -r c72f293685b1 scripts/ode/ode23.m
--- a/scripts/ode/ode23.m	Mon Sep 19 21:27:22 2022 -0400
+++ b/scripts/ode/ode23.m	Tue Sep 20 16:26:09 2022 -0400
@@ -350,7 +350,8 @@
 %!      error ('fout: step "init"');
 %!    endif
 %!  elseif (isempty (flag))
-%!    if (! isequal (size (t), [1, 1]))
+%!  # Multiple steps can be sent in one function call
+%!    if (! isequal ( size (t), size (y)))
 %!      error ('fout: step "calc"');
 %!    endif
 %!  elseif (strcmp (flag, "done"))
@@ -365,6 +366,12 @@
 %!test  # two output arguments
 %! [t, y] = ode23 (@fpol, [0 2], [2 0]);
 %! assert ([t(end), y(end,:)], [2, fref], 1e-3);
+%!test  # correct number of steps with Refine
+%! [t1, y1] = ode23 (@fpol, [0 2], [2 0], odeset("Refine",1));
+%! [t2, y2] = ode23 (@fpol, [0 2], [2 0], odeset("Refine",4));
+%! [t3, y3] = ode23 (@fpol, [0 2], [2 0]); #default Refine=1
+%! assert ( (length (t1) == length (t3)) && ...
+%!          (length (t2) == 4*length (t1) - 3) );
 %!test  # anonymous function instead of real function
 %! fvdp = @(t,y) [y(2); (1 - y(1)^2) * y(2) - y(1)];
 %! [t, y] = ode23 (fvdp, [0 2], [2 0]);
@@ -430,9 +437,9 @@
 %! opt = odeset ("NonNegative", 2);
 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
 %! assert ([sol.x(end); sol.y(:,end)], [2; 2; 0], 1e-1);
-%!test  # Details of OutputSel and Refine can't be tested
-%! opt = odeset ("OutputFcn", @fout, "OutputSel", 1, "Refine", 5);
-%! sol = ode23 (@fpol, [0 2], [2 0], opt);
+%!test  # Details of OutputSel can't be tested
+%! opt = odeset ("OutputFcn", @fout, "OutputSel", 1);
+%! sol = ode45 (@fpol, [0 2], [2 0], opt);
 %!test  # Stats must add further elements in sol
 %! opt = odeset ("Stats", "on");
 %! stat_str = evalc ("sol = ode23 (@fpol, [0 2], [2 0], opt);");
@@ -447,10 +454,9 @@
 %! assert (isfield (sol, "xe"));
 %! assert (isfield (sol, "ye"));
 %!test  # Events option, now stop integration
-%! warning ("off", "integrate_adaptive:unexpected_termination", "local");
 %! opt = odeset ("Events", @fevn, "NormControl", "on");
 %! sol = ode23 (@fpol, [0 10], [2 0], opt);
-%! assert ([sol.ie, sol.xe, sol.ye],
+%! assert ([sol.ie, sol.xe, sol.ye.'],
 %!         [2.0, 2.496110, -0.830550, -2.677589], .5e-1);
 %!test  # Events option, five output arguments
 %! warning ("off", "integrate_adaptive:unexpected_termination", "local");
diff -r 009e2be83f65 -r c72f293685b1 scripts/ode/ode23s.m
--- a/scripts/ode/ode23s.m	Mon Sep 19 21:27:22 2022 -0400
+++ b/scripts/ode/ode23s.m	Tue Sep 20 16:26:09 2022 -0400
@@ -384,7 +384,8 @@
 %!      error ('fout: step "init"');
 %!    endif
 %!  elseif (isempty (flag))
-%!    if (! isequal (size (t), [1, 1]))
+%!  # Multiple steps can be sent in one function call
+%!    if (! isequal ( size (t), size (y)))
 %!      error ('fout: step "calc"');
 %!    endif
 %!  elseif (strcmp (flag, "done"))
@@ -399,6 +400,12 @@
 %!test  # two output arguments
 %! [t, y] = ode23s (@fpol, [0 2], [2 0]);
 %! assert ([t(end), y(end,:)], [2, fref], 1e-3);
+%!test  # correct number of steps with Refine
+%! [t1, y1] = ode23s (@fpol, [0 2], [2 0], odeset("Refine",1));
+%! [t2, y2] = ode23s (@fpol, [0 2], [2 0], odeset("Refine",4));
+%! [t3, y3] = ode23s (@fpol, [0 2], [2 0]); #default Refine=1
+%! assert ( (length (t1) == length (t3)) && ...
+%!          (length (t2) == 4*length (t1) - 3) );
 %!test  # anonymous function instead of real function
 %! fvdp = @(t,y) [y(2); 10 * (1 - y(1)^2) * y(2) - y(1)];
 %! [t, y] = ode23s (fvdp, [0 2], [2 0]);
@@ -430,9 +437,9 @@
 %! opt = odeset ("RelTol", 1e-8, "NormControl", "on");
 %! sol = ode23s (@fpol, [0 2], [2 0], opt);
 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-4);
-%!test  # Details of OutputSel and Refine can't be tested
-%! opt = odeset ("OutputFcn", @fout, "OutputSel", 1, "Refine", 5);
-%! sol = ode23s (@fpol, [0 2], [2 0], opt);
+%!test  # Details of OutputSel can't be tested
+%! opt = odeset ("OutputFcn", @fout, "OutputSel", 1);
+%! sol = ode45 (@fpol, [0 2], [2 0], opt);
 %!test  # Stats must add further elements in sol
 %! opt = odeset ("Stats", "on");
 %! stat_str = evalc ("sol = ode23s (@fpol, [0 2], [2 0], opt);");
diff -r 009e2be83f65 -r c72f293685b1 scripts/ode/ode45.m
--- a/scripts/ode/ode45.m	Mon Sep 19 21:27:22 2022 -0400
+++ b/scripts/ode/ode45.m	Tue Sep 20 16:26:09 2022 -0400
@@ -349,7 +349,8 @@
 %!      error ('fout: step "init"');
 %!    endif
 %!  elseif (isempty (flag))
-%!    if (! isequal (size (t), [1, 1]))
+%!  # Multiple steps can be sent in one function call
+%!    if (! isequal ( size (t), size (y)))
 %!      error ('fout: step "calc"');
 %!    endif
 %!  elseif (strcmp (flag, "done"))
@@ -365,8 +366,14 @@
 %! [t, y] = ode45 (@fpol, [0 2], [2 0]);
 %! assert ([t(end), y(end,:)], [2, fref], 1e-2);
 %!test  # not too many steps
-%! [t, y] = ode45 (@fpol, [0 2], [2 0]);
+%! [t, y] = ode45 (@fpol, [0 2], [2 0], odeset("Refine",1));
 %! assert (size (t) < 20);
+%!test  # correct number of steps with Refine
+%! [t1, y1] = ode45 (@fpol, [0 2], [2 0], odeset("Refine",1));
+%! [t2, y2] = ode45 (@fpol, [0 2], [2 0], odeset("Refine",4));
+%! [t3, y3] = ode45 (@fpol, [0 2], [2 0]); #default Refine=4
+%! assert ( (length (t2) == length (t3)) && ...
+%!          (length (t2) == 4*length (t1) - 3) );
 %!test  # anonymous function instead of real function
 %! fvdp = @(t,y) [y(2); (1 - y(1)^2) * y(2) - y(1)];
 %! [t, y] = ode45 (fvdp, [0 2], [2 0]);
@@ -386,7 +393,7 @@
 %! [t, y] = ode45 (@(t,y) y, [-2 0], 2);
 %! assert ([t(end), y(end,:)], vref, 1e-1);
 %!test  # InitialStep option
-%! opt = odeset ("InitialStep", 1e-8);
+%! opt = odeset ("InitialStep", 1e-8, "Refine", 1);
 %! [t, y] = ode45 (@fpol, [0 0.2], [2 0], opt);
 %! assert ([t(2)-t(1)], [1e-8], 1e-9);
 %!test  # MaxStep option
@@ -441,8 +448,8 @@
 %! opt = odeset ("NonNegative", 2);
 %! sol = ode45 (@fpol, [0 2], [2 0], opt);
 %! assert ([sol.x(end); sol.y(:,end)], [2; 2; 0], 0.5);
-%!test  # Details of OutputSel and Refine can't be tested
-%! opt = odeset ("OutputFcn", @fout, "OutputSel", 1, "Refine", 5);
+%!test  # Details of OutputSel can't be tested
+%! opt = odeset ("OutputFcn", @fout, "OutputSel", 1);
 %! sol = ode45 (@fpol, [0 2], [2 0], opt);
 %!test  # Stats must add further elements in sol
 %! opt = odeset ("Stats", "on");
@@ -458,10 +465,9 @@
 %! assert (isfield (sol, "xe"));
 %! assert (isfield (sol, "ye"));
 %!test  # Events option, now stop integration
-%! warning ("off", "integrate_adaptive:unexpected_termination", "local");
 %! opt = odeset ("Events", @fevn, "NormControl", "on");
 %! sol = ode45 (@fpol, [0 10], [2 0], opt);
-%! assert ([sol.ie, sol.xe, sol.ye],
+%! assert ([sol.ie, sol.xe, sol.ye.'],
 %!         [2.0, 2.496110, -0.830550, -2.677589], 6e-1);
 %!test  # Events option, five output arguments
 %! warning ("off", "integrate_adaptive:unexpected_termination", "local");
@@ -505,7 +511,7 @@
 %!test # Check that imaginary part of solution does not get inverted
 %! sol = ode45 (@(x,y) 1, [0 1], 1i);
 %! assert (imag (sol.y), ones (size (sol.y)));
-%! [x, y] = ode45 (@(x,y) 1, [0 1], 1i);
+%! [x, y] = ode45 (@(x,y) 1, [0 1], 1i, odeset ("Refine",1) );
 %! assert (imag (y), ones (size (y)));
 
 %!error <Invalid call> ode45 ()
diff -r 009e2be83f65 -r c72f293685b1 scripts/ode/private/integrate_adaptive.m
--- a/scripts/ode/private/integrate_adaptive.m	Mon Sep 19 21:27:22 2022 -0400
+++ b/scripts/ode/private/integrate_adaptive.m	Tue Sep 20 16:26:09 2022 -0400
@@ -226,7 +226,7 @@
         xadd = output_x(:, (iout-iadd+1):end);
         tadd = output_t((iout-iadd+1):end);
         if (! isempty (options.OutputSel))
-          xadd = xadd(options.OutputSel, 1);
+          xadd = xadd(options.OutputSel, :);
         endif
         stop_solve = feval (options.OutputFcn, tadd, xadd, 
                             [], options.funarguments{:});
