function tree_to_pruefer_test ( )

%*****************************************************************************80
%
%% tree_to_pruefer_test() tests tree_to_pruefer().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 December 2015
%
%  Author:
%
%    John Burkardt
%
  n = 5;
  test_num = 5;

  fprintf ( 1, ' \n' );
  fprintf ( 1, 'tree_to_pruefer_test():\n' );
  fprintf ( 1, '  tree_to_pruefer() converts a tree to a Pruefer code.\n' );

  pruefer_num = pruefer_enum ( n );

  i4_lo = 0;
  i4_hi = pruefer_num - 1;

  for test = 1 : test_num
%
%  Pick a "random" Pruefer code.
%
    rank = randi ( [ i4_lo, i4_hi ], 1 );

    p = pruefer_unrank ( rank, n );

    fprintf ( 1, ' \n' );
    fprintf ( 1, '  Random Pruefer code of rank %d\n', rank );
    fprintf ( 1, '\n' );
    for i = 1 : n - 2
      fprintf ( 1, '%5d', p(i) );
    end
    fprintf ( 1, '\n' );
%
%  Convert the Pruefer code to a tree.
%
    t = pruefer_to_tree ( n, p );

    fprintf ( 1, ' \n' );
    fprintf ( 1, '  Edge list for the corresponding tree:\n' );
    fprintf ( 1, ' \n' );
    for j = 1 : n - 1
      fprintf ( 1, '  %3d  %3d  %3d', j, t(1:2,j) );
    end
    fprintf ( 1, '\n' );
%
%  Convert the tree to a Pruefer code.
%
    p = tree_to_pruefer ( n, t );

    fprintf ( 1, ' \n' );
    fprintf ( 1, '  Corresponding Pruefer code:\n' );
    fprintf ( 1, '\n' );
    for i = 1 : n - 2
      fprintf ( 1, '%5d', p(i) );
    end
    fprintf ( 1, '\n' );

  end

  return
end
