function square_surface_distance_test ( )

%*****************************************************************************80
%
%% square_surface_distance_test() tests square_surface_distance().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 January 2021
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../square_surface_distance' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'square_surface_distance_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test square_surface_distance()\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  The mean distance between two random points on the surface\n' );
  fprintf ( 1, '  of a square can be computed as:\n' );
  fprintf ( 1, '    mu = ( 3 mu_diff + mu_same ) / 4\n' );
  fprintf ( 1, '  where:\n' );
  fprintf ( 1, '    mu_diff = mean distance, points are on different sides\n' );
  fprintf ( 1, '    mu_same = mean distance, points are on same side.\n' );

  n = 10000;
  [ dmu, dvar ] = square_surface_distance_stats ( n );
  dmu_diff_exact = ( 2.0 + sqrt ( 2.0 ) + 5.0 * log ( 1.0 + sqrt ( 2.0 ) ) ) / 9.0;
  dmu_same_exact = 1.0 / 3.0;
  dmu_exact = ( 3.0 * dmu_diff_exact + dmu_same_exact ) / 4.0;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Using N = %d sample points,\n', n );
  fprintf ( 1, '  Exact mean distance (diff) = %g\n', dmu_diff_exact );
  fprintf ( 1, '  Exact mean distance (same) = %g\n', dmu_same_exact );
  fprintf ( 1, '  Exact mean distance        = %g\n', dmu_exact );
  fprintf ( 1, '  Estimated mean distance    = %g\n', dmu );
  fprintf ( 1, '  Estimated variance         = %g\n', dvar );

  n = 10000;
  square_surface_distance_histogram ( n );
  filename = 'square_surface_distance_histogram.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'square_surface_distance_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../square_surface_distance' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

