function monty_hall_simulation_test ( )

%*****************************************************************************80
%
%% monty_hall_simulation_test() tests monty_hall_simulation().
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    26 August 2022
%
%  Author:
%
%    Original Python code by Christian Hill.
%    This version by John Burkardt
%
%  Reference:
%
%    Christian Hill,
%    Learning Scientific Programming With Python,
%    Second Edition,
%    Cambridge University Press, 2020
%    ISBN: 978-1-108-74591-8
%
  addpath ( '../monty_hall_simulation' );

  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'monty_hall_simulation_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  monty_hall_simulation() simulates the Monty Hall\n' );
  fprintf ( 1, '  prize winning game, in which a prize is hidden behind\n' );
  fprintf ( 1, '  one of several doors.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'Doors  No-switch winning      Switch winning\n' );
  fprintf ( 1, '       Observed  Predicted  Observed  Predicted\n' );
  fprintf ( 1, '' );

  for ndoors = 3 : 10

    ntrials = 100000;

    switch_doors = false;
    wins_noswitch = 0;
    for i = 1 : ntrials
      win = monty_hall_simulation ( switch_doors, ndoors );
      if ( win ) 
        wins_noswitch = wins_noswitch + 1;
      end
    end
    ratio_noswitch = wins_noswitch / ntrials;

    switch_doors = true;
    wins_switch = 0;
    for i = 1 : ntrials
      win = monty_hall_simulation ( switch_doors, ndoors );
      if ( win )
        wins_switch = wins_switch + 1;
      end
    end
    ratio_switch = wins_switch / ntrials;

    [ prob_noswitch, prob_switch ] = monty_hall_probabilities ( ndoors );

    fprintf ( 1, '  %2d  %8.4g  %8.4g  %8.4g  %8.4g\n', ...
      ndoors, ratio_noswitch, prob_noswitch, ratio_switch, prob_switch );

  end
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'monty_hall_simulation_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  timestamp ( );
  rmpath ( '../monty_hall_simulation' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

