% distanceTest.m
% C. Kambhamettu 2008, modified from T Harvey 2007, modified from P. Conrad for CISC106, sect 99, 09/15/2007

% Test formula to calculate the distance between two points
% in the cartesian plane 

%%%%%%%%%%%%%%%%%%%%%%%%
% define the tolerance %
%%%%%%%%%%%%%%%%%%%%%%%%

% tolerance is "how far away from the expected value" the result
% is allowed to be.  Since the calculation involves a square root,
% not all inputs will produce results that can be represented exactly.

tolerance = 0.001;

%%%%%%%%%%%%%%%%%
% Run the tests %
%%%%%%%%%%%%%%%%%

% Test 1

actual = distance(1,5,-2,1);
expected = 5;

diff = abs(expected-actual);

if (diff > tolerance)
  disp('test 1 failed');
  expected               %wouldn't an fprintf be nice here?
  actual
end
  

% Test 2

actual = distance(-2,-3,-4,4);
expected = 7.28;

diff = abs(expected-actual);

if (diff > tolerance)
  disp('test 2 failed');
  expected
  actual
end
  

% Test 3

actual = distance(0,0,3,3);

expected=input('Type in the expected distance between 0,0 and 3,3:') ;

diff = abs(expected-actual);

if (diff > tolerance)
  disp('test 3 failed');
  expected
  actual
end

disp('done');

% end testDistance.m

