Index: library/tests/emix_test.cpp
===================================================================
--- library/tests/emix_test.cpp (revision 477)
+++ library/tests/emix_test.cpp (revision 500)
@@ -2,4 +2,9 @@
 #include "stat/exp_family.h"
 #include "stat/emix.h"
+#include "mat_checks.h"
+#include "UnitTest++.h"
+#include "test_util.h"
+
+const double epsilon = 0.00001;
 
 using namespace bdm;
@@ -9,26 +14,5 @@
 using std::endl;
 
-double normcoef ( const epdf* ep, const vec &xb, const vec &yb, int Ngr = 100 ) {
-	mat PPdf ( Ngr + 1, Ngr + 1 );
-	vec rgr ( 2 );
-
-	int i = 0, j = 0;
-	double xstep = ( xb ( 1 ) - xb ( 0 ) ) / Ngr;
-	double ystep = ( yb ( 1 ) - yb ( 0 ) ) / Ngr;
-
-	for ( double x = xb ( 0 ); x <= xb ( 1 ); x += xstep, i++ ) {
-		rgr ( 0 ) = x;
-		j = 0;
-		for ( double y = yb ( 0 ); y <= yb ( 1 ); y += ystep, j++ ) {
-			rgr ( 1 ) = y;
-			PPdf ( i, j ) = exp ( ep->evallog ( rgr ) );
-		}
-	}
-	return sumsum ( PPdf ) *xstep*ystep;
-}
-
-int main() {
-	RNG_randomize();
-
+TEST ( test_emix_old ) {
 	RV x ( "{x }" );
 	RV y ( "{y }" );
@@ -49,6 +33,6 @@
 	M1.set_rv ( xy );
 	M1.set_parameters ( vec ( "1" ), A1, false );
-	cout << "======== test if ARX and emix with one ARX are the same ===" << endl;
 
+	// test if ARX and emix with one ARX are the same
 	epdf* Mm = M1.marginal ( y );
 	epdf* Am = E1.marginal ( y );
@@ -56,12 +40,19 @@
 	mpdf* Ac = E1.condition ( y );
 
-	cout << * ( ( mlnorm<ldmat>* ) Ac ) << endl;
+	mlnorm<ldmat> *wacnd = dynamic_cast<mlnorm<ldmat> *>(Ac);
+	CHECK(wacnd);
+	if ( wacnd ) {
+		CHECK_CLOSE ( mat ( "-0.349953" ), wacnd->_A(), epsilon );
+		CHECK_CLOSE ( vec ( "1.39564" ), wacnd->_mu_const(), epsilon );
+		CHECK_CLOSE ( mat ( "0.939557" ), wacnd->_R(), epsilon );
+	}
 
-	cout << "Mix marg at 0: " << Mm->evallog ( vec_1 ( 0.0 ) ) << endl;
-	cout << "ARX marg at 0: " << Am->evallog ( vec_1 ( 0.0 ) ) << endl;
-	cout << "Mix cond at 0,0: " << Mc->evallogcond ( vec_1 ( 0.0 ), vec_1 ( 0.0 ) ) << endl;
-	cout << "ARX cond at 0,0: " << Ac->evallogcond ( vec_1 ( 0.0 ), vec_1 ( 0.0 ) ) << endl;
+	double same = -1.46433;
+	CHECK_CLOSE ( same, Mm->evallog ( vec_1 ( 0.0 ) ), epsilon );
+	CHECK_CLOSE ( same, Am->evallog ( vec_1 ( 0.0 ) ), epsilon );
+	CHECK_CLOSE ( 0.145974, Mc->evallogcond ( vec_1 ( 0.0 ), vec_1 ( 0.0 ) ), epsilon );
+	CHECK_CLOSE ( -1.92433, Ac->evallogcond ( vec_1 ( 0.0 ), vec_1 ( 0.0 ) ), epsilon );
 
-	cout << "======== Mixture with two components ===" << endl;
+	// mixture with two components
 	Array<epdf*> A2 ( 2 );
 	A2 ( 0 ) = &E1;
@@ -73,27 +64,34 @@
 
 
-	cout << "Mixture normalization: " << normcoef ( &M2, vec ( "-3 3 " ), vec ( "-3 3 " ) ) << endl;
+	// mixture normalization
+	CHECK_CLOSE ( 1.0, normcoef ( &M2, vec ( "-3 3 " ), vec ( "-3 3 " ) ), 0.1 );
 
 	int N = 3;
-	vec ll ( N );
 	vec ll2 ( N );
 	mat Smp = M2.sample_m ( N );
-	ll = M2.evallog_m ( Smp );
+	vec ll = M2.evallog_m ( Smp );
 
 	vec Emu = sum ( Smp, 2 ) / N;
+	CHECK_CLOSE ( vec ( "1.00054 1.0455" ), Emu, 1.0 );
+
 	mat Er = ( Smp * Smp.transpose() ) / N - outer_product ( Emu, Emu );
+	CHECK_CLOSE ( mat ( "0.740142 -0.259015; -0.259015 1.0302" ), Er, 2.0 );
 
-	cout << "original empirical mean: " << Emu << endl;
-	cout << "original empirical variance: " << Er << endl;
+	epdf *nm2mrg = M2.marginal ( y );
+	CHECK ( nm2mrg );
+	shared_ptr<epdf> Mg ( nm2mrg );
+	mpdf *Cn = M2.condition ( x );
+	CHECK ( Cn );
 
-	shared_ptr<epdf> Mg ( dynamic_cast<epdf *> ( M2.marginal ( y ) ) );
-	mpdf* Cn = ( mpdf* ) M2.condition ( x );
-
+#if false
 	it_file it ( "emix_test.it" );
 	it << Name ( "Smp" ) << Smp;
+#endif
 
-	cout << "marginal mean: " << Mg->mean() << endl;
+	// marginal mean
+	CHECK_CLOSE ( vec ( "1.0" ), Mg->mean(), 0.1 );
 
-	cout << "========== putting them back together ======= " << endl;
+#if false
+	// putting them back together
 	mepdf mMg ( Mg );
 	Array<mpdf*> AA ( 2 );
@@ -107,5 +105,4 @@
 	it << Name ( "ll" ) << ll;
 	it << Name ( "ll2" ) << ll2;
-
-
+#endif
 }
