% testSineWavVector.m  P. Conrad for CISC106   
% acceptance/regression test for sineWavVector.m


%  >> sineWavVector(4,1,2)
%  ans = 
%        0 1 0 -1 0 1 0 -1 0
%  >>
%  Note that the length of the vector will be 
%   (duration * sampleRate) + 1
%
%  >> sineWavVector(4,1,1)
%  ans = 
%        0 1 0 -1 0
%
%  Note: in following example, x stands for 1/sqrt(2)
%  
%  >> sineWavVector(8,1,1)
%  ans = 
%        0 x 1 x 0 -x -1 -x 0
%

tolerance = 0.0001;

fprintf('test1: ');
expected = [ 0 1 0 -1 0 1 0 -1 0];
actual = sineWavVector(4,1,2);

if (length(expected)~=length(actual))
  fprintf('failed\n');
else
  testPassed = true;
  for k = 1:length(expected);
    if (~ approxEquals(expected(k),actual(k),tolerance));
      testPassed = false;
    end;
  end;
 if(testPassed)
   fprintf('passed\n');
 else
   fprintf('failed\n');
 end;
end;


fprintf('test2: ');
expected = [0 1 0 -1 0];
actual = sineWavVector(4,1,1);

if (length(expected)~=length(actual))
  fprintf('failed\n');
else
  testPassed = true;
  for k = 1:length(expected);
    if (~ approxEquals(expected(k),actual(k),tolerance));
      testPassed = false;
    end;
  end;
 if(testPassed)
   fprintf('passed\n');
 else
   fprintf('failed\n');
 end;
end;


fprintf('test3: ');
x = 1/sqrt(2);
expected = [0 x 1 x  0 -x  -1 -x  0];
actual = sineWavVector(8,1,1);

if (length(expected)~=length(actual))
  fprintf('failed\n');
else
  testPassed = true;
  for k = 1:length(expected);
    if (~ approxEquals(expected(k),actual(k),tolerance));
      testPassed = false;
    end;
  end;
 if(testPassed)
   fprintf('passed\n');
 else
   fprintf('failed\n');
 end;
end;


fprintf('test4: ');
expected = [0 1 0 -1  0 1 0 -1 0];
actual = sineWavVector(8,2,1);

if (length(expected)~=length(actual))
  fprintf('failed\n');
else
  testPassed = true;
  for k = 1:length(expected);
    if (~ approxEquals(expected(k),actual(k),tolerance));
      testPassed = false;
    end;
  end;
 if(testPassed)
   fprintf('passed\n');
 else
   fprintf('failed\n');
 end;
end;




