function perm1_distance_test ( )

%*****************************************************************************80
%
%% PERM1_DISTANCE_TEST tests PERM1_DISTANCE
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 May 2015
%
%  Author:
%
%    John Burkardt
%
  n = 10;

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

  seed = 123456789;

  [ p1, seed ] = perm1_random2 ( n, seed );
  perm1_print ( n, p1, '  Permutation P1' );
  [ p2, seed ] = perm1_random2 ( n, seed );
  perm1_print ( n, p2, '  Permutation P2' );
  [ p3, seed ] = perm1_random2 ( n, seed );
  perm1_print ( n, p3, '  Permutation P3' );

  k11 = perm1_distance ( n, p1, p1 );
  k12 = perm1_distance ( n, p1, p2 );
  k21 = perm1_distance ( n, p2, p1 );
  k13 = perm1_distance ( n, p1, p3 );
  k23 = perm1_distance ( n, 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
