function coin_simulation_test ( )

%*****************************************************************************80
%
%% coin_simulation_test() tests coin_simulation().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 December 2018
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../coin_simulation' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'coin_simulation_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s.\n', version ( ) );
  fprintf ( 1, '  coin_simulation() simulates and visualizes the repeated\n' );
  fprintf ( 1, '  tossing of a coin.\n' );
%
%  Generate lists of values.
%
  coin_biased_test ( );
  coin_streak_test ( );
  coin_uniform_test ( );
%
%  Generate one set of biased data for all the plots.
%
  n = 100;
  heads = 0.70;
  v = coin_biased ( n, heads );
%
%  Generate various plots based on the biased data.
%
  label = sprintf ( ...
    'Tails(left) versus Heads(right), %d tosses with head bias %g', n, heads );
  filename = 'coin_biased_barchart.png';
  coin_barchart ( n, v, label, filename );

  label = sprintf ( 'Tossing a coin with %g bias %d times', heads, n );
  filename = 'coin_biased_plot.png';
  coin_plot ( n, v, label, filename );

  label = sprintf ( 'Tossing a coin with %g bias %d times', heads, n );
  filename = 'coin_biased_average.png';
  coin_average_plot ( n, v, label, filename );

  label = sprintf ( 'Tossing a coin with %g bias %d times', heads, n );
  filename = 'coin_biased_sign.png';
  coin_sign_plot ( n, v, label, filename );

  label = sprintf ( 'Tossing a coin with %g bias %d times', heads, n );
  filename = 'coin_biased_streak.png';
  coin_streak_plot ( n, v, label, filename );

  label = sprintf ( 'Tossing a coin with %g bias %d times', heads, n );
  filename = 'coin_biased_sum.png';
  coin_sum_plot ( n, v, label, filename );
%
%  1024 experiments, toss 10 times and count the heads on a biased coin.
%
  m = 1024;
  n = 10;
  heads = 0.70;

  v = coins_biased ( m, n, heads );

  label = sprintf ( ...
    '%d cases, number of heads tossing a coin with %g bias %d times', ...
    m, heads, n );
  filename = 'coins_biased_sum_barchart.png';
  coins_sum_barchart ( m, n, v, label, filename );
%
%  Generate one set of uniform data for all the plots.
%
  n = 100;
  v = coin_uniform ( n );
%
%  Generate various plots based on the uniform data.
%
  label = sprintf ( 'Tails(left) versus Heads(right), %d tosses with fair coin', n );
  filename = 'coin_uniform_barchart.png';
  coin_barchart ( n, v, label, filename );

  label = sprintf ( 'Tossing a fair coin %d times', n );
  filename = 'coin_uniform_plot.png';
  coin_plot ( n, v, label, filename );

  label = sprintf ( 'Tossing a fair coin %d times', n );
  filename = 'coin_uniform_average.png';
  coin_average_plot ( n, v, label, filename );

  label = sprintf ( 'Tossing a fair coin %d times', n );
  filename = 'coin_uniform_sign.png';
  coin_sign_plot ( n, v, label, filename );

  label = sprintf ( 'Tossing a fair coin %d times', n );
  filename = 'coin_uniform_streak.png';
  coin_streak_plot ( n, v, label, filename );

  label = sprintf ( 'Tossing a fair coin %d times', n );
  filename = 'coin_uniform_sum.png';
  coin_sum_plot ( n, v, label, filename );
%
%  Generate M sets of uniform data for all the plots.
%
  m = 20;
  n = 100;
  v = coins_uniform ( m, n );

  label = sprintf ( '%d cases, tossing a fair coin %d times', m, n );
  filename = 'coins_uniform_plot.png';
  coins_plot ( m, n, v, label, filename );

  label = sprintf ( '%d cases, tossing a fair coin %d times', m, n );
  filename = 'coins_uniform_average.png';
  coins_average_plot ( m, n, v, label, filename );

  label = sprintf ( '%d cases, tossing a fair coin %d times', m, n );
  filename = 'coins_uniform_sum.png';
  coins_sum_plot ( m, n, v, label, filename );
%
%  1024 experiments, toss 10 times and count the heads on a fair coin.
%
  m = 1024;
  n = 10;
  v = coins_uniform ( m, n );

  label = sprintf ( ...
    '%d cases, number of heads tossing a fair coin %d times', m, n );
  filename = 'coins_uniform_sum_barchart.png';
  coins_sum_barchart ( m, n, v, label, filename );
%
%  Test some utilities.
%
  r8row_print_test ( );
  r8row_print_some_test ( );
  r8row_running_average_test ( );
  r8row_running_sum_test ( );
  r8row_uniform_ab_test ( );

  r8vec_print_test ( );
  r8vec_running_average_test ( );
  r8vec_running_sign3_test ( );
  r8vec_running_sum_test ( );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'coin_simulation_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../coin_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

