function trinity_hexity_test ( )

%*****************************************************************************80
%
%% trinity_hexity_test() tests the hexity of the trinity problem.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 February 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'trinity_hexity_test():\n' );
  fprintf ( 1, '  Analyze hexity of the trinity tiling problem.\n' );
  fprintf ( 1, '  The hexity of the grid should equal the sum of\n' );
  fprintf ( 1, '  the hexities of the 4 tiles, after proper rotation\n' );
  fprintf ( 1, '  and reflection.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  We can first configure each tile, then compute its hexity.\n' );
  fprintf ( 1, '  Or, we can compute the hexity of each tile in its default\n' );
  fprintf ( 1, '  configuration, and then apply the transformations to the\n' );
  fprintf ( 1, '  hexity vector directly.\n' );
%
%  Get trinity word and compute grid hexity.
%
  [ g_w, g_p ] = trinity_grid_word ( );

  g_h = object_hexity ( g_w, g_p );
%
%  Get number of tiles.
%
  tile_num = trinity_tile_num ( );
%
%  Print hexity of each tile in default configuration.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Hexity of Trinity tiles in default configuration:\n' );
  fprintf ( 1, '\n' );

  for tile_index = 1 : tile_num
    [ t_w, t_p ] = trinity_tile_word ( tile_index );
    t_h = object_hexity ( t_w, t_p );
    fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d\n', t_h, sum ( t_h ) );
  end
%
%  Transform each tile to its configuration in the solution, then compute hexity.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Compute configuration, then hexity:\n' );
  fprintf ( 1, '\n' );

  h2 = zeros ( 1, 12 );

  tile_index = 1;
  [ t_w, t_p ] = trinity_tile_word ( tile_index );
  r = 4;
  [ t_w, t_p ] = word_rotate_ij ( t_w, t_p, r );
  t_h = object_hexity ( t_w, t_p );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d\n', t_h, sum ( t_h ) );
  h2 = h2 + t_h;

  tile_index = 2;
  [ t_w, t_p ] = trinity_tile_word ( tile_index );
  r = 2;
  [ t_w, t_p ] = word_rotate_ij ( t_w, t_p, r );
  t_h = object_hexity ( t_w, t_p );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d\n', t_h, sum ( t_h ) );
  h2 = h2 + t_h;

  tile_index = 3;
  [ t_w, t_p ] = trinity_tile_word ( tile_index );
  r = 2;
  [ t_w, t_p ] = word_rotate_ij ( t_w, t_p, r );
  t_h = object_hexity ( t_w, t_p );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d\n', t_h, sum ( t_h ) );
  h2 = h2 + t_h;

  tile_index = 4;
  [ t_w, t_p ] = trinity_tile_word ( tile_index );
  r = 5;
  [ t_w, t_p ] = word_rotate_ij ( t_w, t_p, r );
  [ t_w, t_p ] = word_reflect_ij ( t_w, t_p );
  t_h = object_hexity ( t_w, t_p );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d\n', t_h, sum ( t_h ) );
  h2 = h2 + t_h;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d %s\n', h2, sum ( h2 ), '  Tile hexity sum' );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d %s\n', g_h, sum ( g_h ), '  Grid hexity' );
%
%  Compute the hexity of each tile in the default configuration.
%  Then apply the necessary rotation and reflection operations to the hexity.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Compute hexity, then configure:\n' );
  fprintf ( 1, '\n' );

  h2 = zeros ( 1, 12 );

  tile_index = 1;
  [ t_w, t_p ] = trinity_tile_word ( tile_index );
  t_h = object_hexity ( t_w, t_p );
  r = 4;
  t_h = hexity_rotate ( t_h, r );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d\n', t_h, sum ( t_h ) );
  h2 = h2 + t_h;

  tile_index = 2;
  [ t_w, t_p ] = trinity_tile_word ( tile_index );
  t_h = object_hexity ( t_w, t_p );
  r = 2;
  t_h = hexity_rotate ( t_h, r );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d\n', t_h, sum ( t_h ) );
  h2 = h2 + t_h;

  tile_index = 3;
  [ t_w, t_p ] = trinity_tile_word ( tile_index );
  t_h = object_hexity ( t_w, t_p );
  r = 2;
  t_h = hexity_rotate ( t_h, r );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d\n', t_h, sum ( t_h ) );
  h2 = h2 + t_h;

  tile_index = 4;
  [ t_w, t_p ] = trinity_tile_word ( tile_index );
  t_h = object_hexity ( t_w, t_p );
  r = 5;
  t_h = hexity_rotate ( t_h, r );
  t_h = hexity_reflect ( t_h );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d\n', t_h, sum ( t_h ) );
  h2 = h2 + t_h;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d %s\n', h2, sum ( h2 ), '  Tile hexity sum' );
  fprintf ( 1, '  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %2d  %3d %s\n', g_h, sum ( g_h ), '  Grid hexity' );

  return
end

