function counterfeit_detection_compressed_test ( k )

%*****************************************************************************80
%
%% counterfeit_detection_compressed_test tests counterfeit_detection_compressed.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    10 March 2019
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Kurt Bryan, Tanya Leise,
%    Making do with less: an introduction to compressed sensing,
%    SIAM Review,
%    Volume 55, Number 3, September 2013, pages 547-566.
%
%  Input:
%
%    integer k, the number of random subsets to test.
%    If n = 100, k = 20 is reasonable.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'counterfeit_detection_compressed_test\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test counterfeit_detection_compressed,\n' );
  fprintf ( 1, '  which seeks to identify multiple counterfeit coins among n coins\n' );
  fprintf ( 1, '  using compressed sensing techniques.\n' );

  correct = 17.0;

  problem = 2;

  if ( problem == 1 )
    n = 7;
    fake_num = 1;
  else
    n = 100;
    fake_num = 3;
  end

  coin(1:n,1) = correct;
%
%  randsample() is only available with the statistic and machine learning toolbox.
%
% fake = randsample ( n, fake_num );
  fake = ksub_random2 ( n, fake_num );

  fake = sort ( fake );
  coin(fake) = correct + 3.0 * rand ( fake_num, 1 );

  suspect = counterfeit_detection_compressed ( n, coin, correct, k );
  suspect_num = length ( suspect );
%
%  Compare actual fake to your suspect.
%
  fprintf ( 1, '  %d coins were checked.\n', n );
  fprintf ( 1, '  Correct coin weight is %g\n', correct );
  fprintf ( 1, '  There were %d fakes;\n', fake_num );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Fake     Index  Weight:\n' );
  fprintf ( 1, '\n' );
  for i = 1 : fake_num
    fprintf ( 1, '  #%d:        %3d  %g\n', i, fake(i), coin(fake(i)) );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  %d random subsets were weighed.\n', k );
  fprintf ( 1, '  The function found %d suspects.\n', suspect_num );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Suspect  Index  Weight:\n' );
  fprintf ( 1, '\n' );
  for i = 1 : suspect_num
    fprintf ( 1, '  #%d:        %3d   %g\n', i, suspect(i), coin(suspect(i)) );
  end
%
%  Declare success or failure.
%
  success = true;

  if ( suspect_num ~= fake_num )
    success = false;
  end

  for i = 1 : fake_num
    if ( fake(i) ~= suspect(i) )
      success = false;
    end
  end

  fprintf ( 1, '\n' );
  if ( success )
    fprintf ( 1, '  The test succeeded\n' );
  else
    fprintf ( 1, '  The test failed.\n' );
  end

  return
end

