function tet_mesh_test007 ( )

%*****************************************************************************80
%
%% tet_mesh_test007() tests tet_mesh_search_naive() and tet_mesh_search_delaunay().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 August 2009
%
%  Author:
%
%    John Burkardt
%
  test_num = 5;
  tet_order = 4;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'tet_mesh_test007():\n' );
  fprintf ( 1, '  tet_mesh_search_naive() uses a naive algorithm\n' );
  fprintf ( 1, '  to search a tetrahedral mesh for the tetrahedron\n' );
  fprintf ( 1, '  containing a point.\n' );
  fprintf ( 1, '  tet_mesh_search_delaunay() uses a faster algorithm\n' );
  fprintf ( 1, '  which is appropriate if the tet mesh is Delaunay.\n' );
%
%  Set up the example tetrahedron mesh.
%
  [ node_num, tet_num ] = tet_mesh_order4_example_size ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  This mesh has tetrahedron order %d\n', tet_order );
  fprintf ( 1, '  The number of tetrahedrons is   %d\n', tet_num );

  [ node_xyz, tet_node ] = tet_mesh_order4_example_set ( node_num, tet_num );
%
%  TET_NEIGHBOR is needed for the Delaunay search.
%
  tet_neighbor = tet_mesh_neighbor_tets ( tet_order, tet_num, tet_node );

  for test = 1 : test_num
%
%  Choose a tetrahedral index at random.
%
    tet1 = randi ( [ 1, tet_num ], 1 );
    fprintf ( 1, '\n' );
    fprintf ( 1, '  Point was chosen from tetrahedron    %8d\n', tet1 );
%
%  Choose a point at random from the tetrahedron.
%
    p = tetrahedron_sample ( node_xyz(1:3,tet_node(1:4,tet1)), 1 );
%
%  Naive search.
%
    [ tet2, step_num ] = tet_mesh_search_naive ( node_num, node_xyz, ...
      tet_order, tet_num, tet_node, p );

    fprintf ( 1, '  Naive search ended in tetrahedron    %8d after %d steps\n', ...
      tet2, step_num );
%
%  Delaunay search.
% 
    [ tet3, face, step_num ] = tet_mesh_search_delaunay ( node_num, ...
      node_xyz, tet_order, tet_num, tet_node, tet_neighbor, p );

    fprintf ( 1, ...
      '  Delaunay search ended in tetrahedron %8d after %d steps.\n', ...
      tet3, step_num );

  end

  return
end
