function permutation_distance_ulam_test ( )

%*****************************************************************************80
%
%% permutation_distance_ulam_test() tests permutation_distance_ulam().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 September 2022
%
%  Author:
%
%    John Burkardt
%
  n = 10;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'permutation_distance_ulam():\n' );
  fprintf ( 1, '  permutation_distance_ulam() computes the Ulam metric distance\n' );
  fprintf ( 1, '  between two permutations of (1,...,N).\n' );

  p1 = randperm ( n );
  permutation_print ( p1, '  Permutation P1' );
  p2 = randperm ( n );
  permutation_print ( p2, '  Permutation P2' );
  p3 = randperm ( n );
  permutation_print ( p3, '  Permutation P3' );

  k11 = permutation_distance_ulam ( p1, p1 );
  k12 = permutation_distance_ulam ( p1, p2 );
  k21 = permutation_distance_ulam ( p2, p1 );
  k13 = permutation_distance_ulam ( p1, p3 );
  k23 = permutation_distance_ulam ( p2, p3 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  K(P1,P1) should be 0.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  K(P1,P1) = %d\n', k11 );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  K(P1,P2) should equal K(P2,P1).\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  K(P1,P2) = %d\n', k12 );
  fprintf ( 1, '  K(P2,P1) = %d\n', k21 );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  K(P1,P3) <= K(P1,P2) + K(P2,P3).\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  K(P1,P3) = %d\n', k13 );
  fprintf ( 1, '  K(P1,P2) = %d\n', k12 );
  fprintf ( 1, '  K(P2,P3) = %d\n', k23 );
  fprintf ( 1, '  K(P1,P2) + K(P2,P3) = %d\n', k12 + k23 );

  return
end
