function gamblers_ruin_test ( )

%*****************************************************************************80
%
%% gamblers_ruin_test() tests gamblers_ruin().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 January 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'gamblers_ruin_test():\n' );
  fprintf ( 1, '  gamblers_ruin() considers the gambler''s ruin problem.\n' );
  fprintf ( 1, '  Players A and B repeatedly play a game against each other.\n' );
  fprintf ( 1, '  On each game, player A has a probability P of winning.\n' );
  fprintf ( 1, '  After each game, the winner gets 1 dollar from the loser.\n' );
  fprintf ( 1, '  The players begin with A and B dollars, respectively.\n' );
  fprintf ( 1, '  They play until one is bankrupt.\n' );
  fprintf ( 1, '  How long will it take for one player to go bankrupt?\n' );
  fprintf ( 1, '  What is the probability that A is ruined?\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  A  B  P  Prob(ruin)  AverageGames\n' );
  fprintf ( 1, '\n' );

  a_test = [ 9, 90, 9, 99 ];
  b_test = [ 1, 10, 1,  1 ];
  p_test = [ 0.50, 0.50, 0.45, 0.40 ];

  for i = 1 : 4
    a = a_test(i);
    b = b_test(i);
    p = p_test(i);
    [ AR, LS ] = gamblers_ruin ( a, b, p );
    fprintf ( 1, '  %2d  %2d  %g  %g  %g\n', a, b, p, AR, LS );
  end
 
  return
end

