function find_distances_test ( ) 

%*****************************************************************************80
%
%% FIND_DISTANCES_TEST tests FIND_DISTANCES.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license. 
%
%  Modified:
%
%    10 January 2018
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'FIND_DISTANCES_TEST:\n' );
  fprintf ( 1, '  FIND_DISTANCES takes a candidate location Y\n' );
  fprintf ( 1, '  and determines whether its distance to each point\n' );
  fprintf ( 1, '  in the X array is listed in the L array.\n' );

  n = 5;
  l_length = n * ( n - 1 ) / 2;
  l = [  13, 15, 38, 90, 2, 25, 77, 23, 75, 52 ];
  i4vec_print ( l_length, l, '  Initial L array:' );

  [ l, l_max ] = i4vec_max_last ( l_length, l );
  l_length = l_length - 1;

  x = zeros ( n, 1 );
  x(1) = 0;
  x(2) = l_max;
  x_length = 2;
%
%  Solution is X = (/ 0, 13, 15, 38, 90 /) or (/ 0, 52, 75, 77, 90 /)
%  So Y = 13, 15, 38, 52, 75 or 77 will be acceptable.
%
  [ l, y ] = i4vec_max_last ( l_length, l );
  [ success, l ] = find_distances ( l_length, l, x_length, x, y );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Consider Y = %d\n', y );
  fprintf ( 1, '\n' );
  if ( success )
    fprintf ( 1, '  This Y is acceptable.\n' );
    l_length = l_length - x_length;
    x_length = x_length + 1;
    x(x_length) = y;
    i4vec_print ( x_length, x, '  New X array:' );
    i4vec_print ( l_length, l, '  New L array:' );
  else
    fprintf ( 1, '  This Y is not acceptable.\n' );
  end

  y = 35;
  [ success, l ] = find_distances ( l_length, l, x_length, x, y );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Consider Y = %d\n', y );
  fprintf ( 1, '\n' );
  if ( success )
    fprintf ( 1, '  This Y is acceptable.\n' );
    l_length = l_length - x_length;
    x_length = x_length + 1;
    x(x_length) = y;
    i4vec_print ( x_length, x, '  New X array:' );
    i4vec_print ( l_length, l, '  New L array:' );
  else
    fprintf ( 1, '  This Y is not acceptable.\n' );
  end

  return
end