function perm1_cycle_stats_test ( )

%*****************************************************************************80
%
%% perm1_cycle_stats_test() tests perm1_cycle_stats().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 November 2022
%
%  Author:
%
%    John Burkardt
%
  n = 9;
  p1 = [ 2, 3, 9, 6, 7, 8, 5, 4, 1 ];

  fprintf ( 1, '\n' );
  fprintf ( 1, 'perm1_cycle_stats_test():\n' );
  fprintf ( 1, '  perm1_cycle_stats() counts cycles of each length\n' );
  fprintf ( 1, '  in a permutation of 1 through N.\n' );

  perm1_print ( n, p1, '  The standard index form permutation:' );
 
  cycle_stats = perm1_cycle_stats ( p1 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Cycle lengths:\n' );
  for i = 1 : n
    fprintf ( 1, '  %2d  %2d\n', i, cycle_stats(i) );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Now average over 1000 permutations of length 100:\n' );
  n = 100;
  trials = 1000;
  cycle_stats = zeros ( n, 1 );
  for i = 1 : trials
    p = randperm ( n );
    cycle_stats = cycle_stats + perm1_cycle_stats ( p );
  end
  cycle_stats = cycle_stats / trials;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Cycle length averages:\n' );
  for i = 1 : n
    p = 1.0 / i;
    fprintf ( 1, '  %2d  %g  %g\n', i, cycle_stats(i), p );
  end

  return
end
