function gray_next_test ( )

%*****************************************************************************80
%
%% GRAY_NEXT_TEST tests GRAY_NEXT.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    12 June 2015
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'GRAY_NEXT_TEST\n' );
  fprintf ( 1, '  GRAY_NEXT returns the index of the single item\n' );
  fprintf ( 1, '  to be changed in order to get the next Gray code.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '   K  Change  Gray Code\n' );
  fprintf ( 1, '\n' );

  n = 4;
  change = -n;
  k = 0;
  a = zeros ( n, 1 );

  g = zeros ( n, 1 );

  while ( true )

    [ change, k, a ] = gray_next ( n, change, k, a );

    if ( change == -n )
      break
    elseif ( change == 0 )
      g(1:n) = 0;
    else
      g(abs(change)) = 1 - g(abs(change));
    end

    fprintf ( 1, '  %2d  %6d  ', k, change );
    for i = 1 : n
      fprintf ( 1, '%d', g(i) );
    end
    fprintf ( 1, '\n' );
    
  end

  return
end
