function U03_test_em_mog
%U03_TEST_EM_MOG           Test em_mog.
%
%usage
%  U03_test_em_mog
%
%author
%  saputra@cs.tu-berlin.de

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

% generate data set
mu_1 = [-4; 0];
mu_2 = [4; 0];
mu_3 = [0; sqrt(48)];
ns = 50;
X = [(randn(2, ns) + repmat(mu_1, 1, ns)) (randn(2, ns) + repmat(mu_2, 1, ns)) (randn(2, ns) + repmat(mu_3, 1, ns))];

% run test
if exist(filename, 'file')
    fprintf(['Testing ' filename  '...\n']);
    [pi, mu, sigma] = em_mog(X, 3);
    %[mu, sigma, pi] = em_mog(X, 3);
    %pi=pi';
    assert_equal([1, 3], size(pi), 'Size of pi does not match. Remember: pi has to be a row vector!');
    assert_equal([2, 3], size(mu), 'Size of mu does not match.');
    assert_equal([3, 1], size(sigma), 'Size of sigma does not match. Remember: sigma has to be a (k x 1) cell array!');
    
    fprintf('If you got no error messages then the dimensions of your returned variables are OK.\n');
    fprintf('This does not mean you function works correctly. It''s hard to check whether a result of EM is correct.\n');
else
    fprintf([filename 'not found.\n']);
end

function [] = assert_equal(A, B, error, success)

if max(max(abs(A - B))) > 1e-3
    fprintf(['Error: ' error '\n']);
    expected = A
    got = B
else
    if nargin > 3
        fprintf(['OK: ' success '\n']);
    end
end
