% testLbs2grams.m   test lbs2grams.m
% L. Rush for CISC106, sect 80, 10/01/2007

% Test formula to calculate the number of grams given lbs. 

%%%%%%%%%%%%%%%%%%%%
% 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.00001;

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

% Test 1


actual = lbs2grams(165);
expected = 74844;

diff = abs(expected-actual);

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

% Test 2

actual = lbs2grams(1);
expected = 453.6;

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