function permutation_distance_stats_test ( )

%*****************************************************************************80
%
%% permutation_distance_stats_test() tests permutation_distance_stats().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 September 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'permutation_distance_stats_test():\n' );
  fprintf ( 1, '  Test permutation_distance_stats().\n' );

  n = 10000;
  fprintf ( 1, '  Using N = %d sample permutations.\n', n );
  fprintf ( 1, '  Permutation order is M\n' );
  fprintf ( 1, '  Compute mean and variance of Ulam permutation distance.\n' );
  fprintf ( 1, '\n' );

  fprintf ( 1, '   M   Mean   Predicted Variance\n' );
  fprintf ( 1, '\n' );
  bob = 1:40;
  mu = zeros ( 40, 1 );
  for m = 1 : 40
    [ mu(m), variance ] = permutation_distance_stats ( m, n );
    fprintf ( 1, '  %2d  %g  %g  %g\n', m, mu(m), mu(m) - m + 2.0 *sqrt ( mu ( m ) ), variance );
  end

  clf ( );
  hold ( 'on' );
  plot ( 1:40, mu, 'bo', 'linewidth', 3 );
  plot ( 1:40, bob-2*sqrt(bob),'r-', 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  filename = 'permutation_distance_stats.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

