% testAvgSpeed.m   test avgSpeed.m
% Andrew Paulus for CISC106, sect 80, 10/01/2007

% Test formula to calculate the average speed given distance traveled and
% time required

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

% tolerance is "how far away from the expected value" the result
% is allowed to be.  Since the calculation involves basic integer
% operation results can be reasonalbly precise

tolerance = 0.0001;

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

% Test 1


actual = avgSpeed(100,30);
expected = 3.33333;

diff = abs(expected-actual);

if (diff < tolerance)
  disp('test 1 passed');
else
  disp('test 1 failed');
  expected
  actual
end
  

% Test 2

actual = avgSpeed(30,3);
expected = 10;

diff = abs(expected-actual);

if (diff < tolerance)
  disp('test 2 passed');
else
  % signal that test failed, and print both expected and actual
  disp('test 2 failed');
  expected
  actual
end
  

% end testAvgSpeed.m






