function U02_test_pca
%U02_TEST_PCA           Test PCA.
%
%Your PCA function must *not* center the data!!!
%
%usage
%  U02_test_pca
%
%author
%  saputra@cs.tu-berlin.de

% filename of script to test
filename = 'PCA.m';

% data
X = [
   0.620350139445525   0.135175444758437   1.183719539936857  -0.716428623725855   0.106814075934588   2.212554078989681  -1.680542777522645   0.008934115676568
   5.079127388759098  -0.556160040161770  -0.061718647133300  -2.622237558015624   7.392864872075875   6.034103024384587  -2.294136536423504   3.347799563349179
   0.634890923594887  -0.069520005020221  -0.007714830891663  -0.327779694751953   0.924108109009484   0.754262878048073  -0.286767067052938   0.418474945418647 ];

m = 2;

% correct results
correct_Z = [
   0.000000000000001  -0.000000000000000  -0.000000000000000  -0.000000000000000   0.000000000000001   0.000000000000000  -0.000000000000000   0.000000000000000
   0.241451624679969  -0.226701139502802  -1.177529274921587   0.265958918169822   1.136435832509665  -1.168077599461355   1.271697872161680   0.553510036896045 ];

correct_U = [
  -0.166669742451379  -0.986012777275828  -0.000000000000000
  -0.978398665047805   0.165382698152069  -0.124034734589208
  -0.122299833130975   0.020672837269008   0.992277876713668 ];

correct_D = 1.0e+02 * [1.466203213045900   0.061464821519444   0.000000000000000];

% run test
if exist(filename, 'file')
    fprintf(['Testing ' filename  '...\n']);
    [Z, U, D] = PCA(X, m);
    assert_equal(size(correct_Z), size(Z), 'Size of matrix Z does not match.');
    assert_equal(size(correct_U), size(U), 'Size of matrix U does not match.');
    assert_equal(size(correct_D), size(D), 'Size of vector D does not match (is D maybe a column instead of a row vector?)');
    assert_equal(correct_Z, Z, 'Matrix Z isn''t correct.', 'Matrix Z is correct.');
    assert_equal(correct_U, U, 'Matrix U isn''t correct.', 'Matrix U is correct.');
    assert_equal(correct_D, D, 'Matrix D isn''t correct.', 'Matrix D is correct.');
else
    fprintf([filename 'not found.\n']);
end
