function perm_lex_successor_test ( )

%*****************************************************************************80
%
%% perm_lex_successor_test() tests perm_lex_successor().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 December 2015
%
%  Author:
%
%    John Burkardt
%
  n = 4;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'perm_lex_successor_test():\n' );
  fprintf ( 1, '  perm_lex_successor() lists\n' );
  fprintf ( 1, '  permutations using the lexicographic ordering:\n' );

  p = [];
  rank = -1;

  while ( true )

    rank_old = rank;

    [ p, rank ] = perm_lex_successor ( n, p, rank );

    if ( rank <= rank_old )
      break
    end

    fprintf ( 1, '%4d:', rank );
    for i = 1 : n
      fprintf ( 1, '%5d', p(i) );
    end
    fprintf ( 1, '\n' );

  end

  return
end
