function components_2d_test ( )

%*****************************************************************************80
%
%% components_2d_test() tests components_2d().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 July 2022
%
%  Author:
%
%    John Burkardt
%
  m = 17;
  n = 9;

  A = [ ...
    0, 0, 0, 0, 0, 0, 0, 0, 0; ...
    0, 0, 1, 0, 0, 1, 0, 0, 0; ...
    0, 1, 1, 0, 1, 1, 1, 0, 0; ...
    0, 1, 1, 1, 1, 1, 1, 0, 0; ...
    0, 0, 1, 1, 1, 0, 0, 0, 0; ...
    0, 0, 1, 1, 1, 0, 0, 0, 0; ...
    0, 1, 1, 1, 0, 1, 0, 1, 0; ...
    0, 1, 1, 0, 0, 1, 0, 1, 0; ...
    0, 0, 1, 0, 0, 0, 0, 1, 0; ...
    0, 0, 0, 0, 1, 0, 1, 1, 0; ...
    0, 1, 0, 1, 1, 0, 1, 0, 0; ...
    0, 1, 1, 1, 1, 1, 0, 0, 0; ...
    0, 0, 1, 1, 0, 1, 0, 1, 0; ...
    0, 0, 1, 1, 0, 1, 0, 1, 0; ...
    0, 1, 1, 0, 1, 0, 1, 1, 0; ...
    0, 1, 0, 0, 1, 0, 1, 1, 0; ...
    0, 0, 0, 0, 0, 0, 0, 0, 0 ];

  fprintf ( 1, '\n' );
  fprintf ( 1, 'components_2d_test():\n' );
  fprintf ( 1, '  components_2d() finds and labels connected\n' );
  fprintf ( 1, '  components in a 2D integer array.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  A:\n' );
  fprintf ( 1, '\n' );
  for i = 1 : m
    fprintf ( 1, '    ' );
    for j = 1 : n
      fprintf ( 1, '%d', A(i,j) );
    end
    fprintf ( 1, '\n' );
  end

  C = components_2d ( A );
  component_num = max ( max ( C ) );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of components = %d\n', component_num );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  C:\n' );
  fprintf ( 1, '\n' );
  for i = 1 : m
    fprintf ( 1, '    ' );
    for j = 1 : n
      fprintf ( 1, '%d', C(i,j) );
    end
    fprintf ( 1, '\n' );
  end

  return
end
