% testKineticEnergy.m   test kineticEnergy.m
% Becky Buxbaum for CISC106, sect 80, 10/01/2007

% Test formula to calculate translational kinetic energy of a moving object  

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

% tolerance is "how far away from the expected value" the result
% is allowed to be.  Since the calculation involves few approximations,
% the tolerance should be small.

tolerance = 0.0001;

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

% Test 1


actual = kineticEnergy(4,2);
expected = 8;

diff = abs(expected-actual);

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

% Test 2

actual = kineticEnergy(6,2);
expected = 12;

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 testKineticEnergy.m


