Index: /library/tests/mat_checks.cpp
===================================================================
--- /library/tests/mat_checks.cpp (revision 426)
+++ /library/tests/mat_checks.cpp (revision 428)
@@ -3,4 +3,19 @@
 namespace UnitTest
 {
+
+bool AreClose(const itpp::vec &expected, const itpp::vec &actual,
+	      double tolerance) {
+    if (expected.length() != actual.length()) {
+        return false;
+    }
+
+    for (int i = 0; i < expected.length(); ++i) {
+        if (!AreClose(expected(i), actual(i), tolerance)) {
+	    return false;
+	}
+    }
+
+    return true;
+}
 
 bool AreClose(const itpp::mat &expected, const itpp::mat &actual, double tolerance) {
Index: /library/tests/CMakeLists.txt
===================================================================
--- /library/tests/CMakeLists.txt (revision 426)
+++ /library/tests/CMakeLists.txt (revision 428)
@@ -17,5 +17,4 @@
 
 EXEC(fsqmat_test)
-EXEC(enorm_test)
 EXEC(egiw_test)
 EXEC(emix_test)
@@ -34,5 +33,4 @@
 EXEC(test_particle)
 EXEC(testSmp)
-EXEC(testEpdf)
 EXEC(test_kalman_QR)
 EXEC(test_kalman_QRexh)
@@ -41,5 +39,5 @@
 
 # using UnitTest++
-add_executable(testsuite datalink_test.cpp loggers_test.cpp rv_test.cpp square_mat_test.cpp testsuite.cpp test_user_info.cpp test_shared_ptr.cpp)
+add_executable(testsuite datalink_test.cpp enorm_test.cpp loggers_test.cpp rv_test.cpp square_mat_test.cpp testsuite.cpp test_user_info.cpp test_shared_ptr.cpp)
 target_link_libraries(testsuite bdm itpp testutil unittest)
 
Index: /library/tests/square_mat_test.cpp
===================================================================
--- /library/tests/square_mat_test.cpp (revision 427)
+++ /library/tests/square_mat_test.cpp (revision 428)
@@ -12,7 +12,7 @@
 {
 
-void CheckClose(TestResults &results, const itpp::mat &expected,
-		const itpp::mat &actual, double tolerance,
-		TestDetails const& details) {
+inline void CheckClose(TestResults &results, const itpp::mat &expected,
+		       const itpp::mat &actual, double tolerance,
+		       TestDetails const& details) {
     if (!AreClose(expected, actual, tolerance)) { 
         MemoryOutStream stream;
Index: /library/tests/mat_checks.h
===================================================================
--- /library/tests/mat_checks.h (revision 426)
+++ /library/tests/mat_checks.h (revision 428)
@@ -19,4 +19,7 @@
 namespace UnitTest
 {
+  bool AreClose(const itpp::vec &expected, const itpp::vec &actual,
+		double tolerance);
+
   bool AreClose(const itpp::mat &expected, const itpp::mat &actual,
 		double tolerance);
Index: /library/tests/enorm_test.cpp
===================================================================
--- /library/tests/enorm_test.cpp (revision 394)
+++ /library/tests/enorm_test.cpp (revision 428)
@@ -1,9 +1,38 @@
+#define BDMLIB // not an ideal way to prevent double registration of UI factories...
 #include "stat/exp_family.h"
 #include "stat/emix.h"
+#include "mat_checks.h"
+#include "UnitTest++.h"
+
 using namespace bdm;
 
-//These lines are needed for use of cout and endl
-using std::cout;
-using std::endl;
+const double epsilon = 0.00001;
+
+namespace UnitTest
+{
+
+inline void CheckClose(TestResults &results, const itpp::vec &expected,
+		       const itpp::vec &actual, double tolerance,
+		       TestDetails const& details) {
+    if (!AreClose(expected, actual, tolerance)) { 
+        MemoryOutStream stream;
+        stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;
+
+        results.OnTestFailure(details, stream.GetText());
+    }
+}
+
+inline void CheckClose(TestResults &results, const itpp::mat &expected,
+		       const itpp::mat &actual, double tolerance,
+		       TestDetails const& details) {
+    if (!AreClose(expected, actual, tolerance)) { 
+        MemoryOutStream stream;
+        stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;
+
+        results.OnTestFailure(details, stream.GetText());
+    }
+}
+
+}
 
 double normcoef ( const epdf* ep,const vec &xb, const vec &yb, int Ngr=100 ) {
@@ -25,54 +54,77 @@
 }
 
-int main() {
-	RNG_randomize();
+TEST(test_enorm) {
+    RNG_randomize();
 
-	cout << "Testing enorm(2,2)"<<endl;
-	// Setup model
-	vec mu ( "1.1 -1" );
-	ldmat R ( mat ( "1 -0.5; -0.5 2" ) );
+    // Setup model
+    vec mu("1.1 -1");
+    ldmat R(mat("1 -0.5; -0.5 2"));
 
-	RV x ( "{x }" );
-	RV y ( "{y }" );
+    RV x("{x }");
+    RV y("{y }");
 
-	enorm<ldmat> E;
-	E.set_rv(concat(x,y));
-	E.set_parameters ( mu,R );
-	cout << "enorm mean value:" << E.mean() <<endl;
-	cout << "enorm mean variance:" << R.to_mat() <<endl;
-	cout << "enorm normalizing constant:" << E.lognc() <<endl;
-	cout << " Numerically integrates to [1.0]: " << normcoef ( &E, vec ( "-5 5" ), vec ( "-5 5" ) ) << endl;
+    enorm<ldmat> E;
+    E.set_rv(concat(x,y));
+    E.set_parameters(mu, R);
+    CHECK_EQUAL(mu, E.mean());
+    CHECK_CLOSE(2.11768, E.lognc(), epsilon);
+    CHECK_CLOSE(1.0, normcoef(&E, vec("-5 5"), vec("-5 5")), 0.01);
 
-	int N=1000;
-	vec ll ( N );
-	mat Smp=E.sample ( 1000 );
-	vec Emu = sum ( Smp,2 ) /N;
-	mat Er = ( Smp*Smp.transpose() ) /N - outer_product ( Emu,Emu );
+    int N = 1000;
+    vec ll(N);
+    mat Smp = E.sample(1000);
+    vec Emu = sum(Smp, 2) / N;
+    CHECK_CLOSE(mu, Emu, 0.3);
 
-	cout << "original empirical mean: " <<Emu <<endl;
-	cout << "original empirical variance: " <<Er <<endl;
+    mat Er = (Smp * Smp.T()) / N - outer_product(Emu, Emu);
+    CHECK_CLOSE(R.to_mat(), Er, 0.3);
 
-	epdf* Mg = E.marginal ( y );
-	mpdf* Cn = E.condition ( x );
+    epdf *Mg = E.marginal(y);
+    CHECK_CLOSE(vec("-1"), Mg->mean(), epsilon);
 
+    // putting them back together
+    mpdf *Cn = E.condition(x);
+    mepdf mMg(Mg);
+    Array<mpdf *> A(2);
+    A(0) = Cn;
+    A(1) = &mMg;
+    mprod mEp(A);
+    Smp = mEp.samplecond(vec(0), 1000);
+    Emu = sum(Smp, 2) / N;
+    CHECK_CLOSE(mu, Emu, 0.3);
 
-	cout<< "marginal mean: " << Mg->mean() <<endl;
+    Er = (Smp * Smp.T()) / N - outer_product(Emu, Emu);
+    CHECK_CLOSE(R.to_mat(), Er, 0.3);
 
-	cout << "========== putting them back together ======= "<<endl;
-	mepdf mMg ( Mg );
-	Array<mpdf*> A ( 2 );
-	A ( 0 ) = Cn;
-	A ( 1 ) = &mMg;
-	mprod mEp ( A );
+    // test of pdflog at zero
+    vec zero(0);
+    vec zero2("0 0");
+    CHECK_CLOSE(E.evallog(zero2), mEp.evallogcond(zero2, zero), epsilon);
+}
 
-	Smp=mEp.samplecond ( vec ( 0 ),1000 );
-	Emu = sum ( Smp,2 ) /N;
-	Er = ( Smp*Smp.transpose() ) /N - outer_product ( Emu,Emu );
+// from testEpdf
+TEST(test_enorm_sum) {
+    vec x = "-10:0.1:10";
+    vec y = "-10:0.1:10";
 
-	cout << "composite mean: " <<Emu <<endl;
-	cout << "composite variance: " <<Er <<endl;
-	
-	cout << endl << " test of pdflog at zero "<<endl;
-	cout << "original: " << E.evallog(vec("0 0")) <<endl;
-	cout << "composite: " << mEp.evallogcond(vec("0 0"),vec(0)) << endl;
+    RV rv("{x2 }", "2");
+    vec mu0 = "0.0 0.0";
+    mat V0 = "5 -0.05; -0.05 5.20";
+    fsqmat R(V0);
+
+    enorm<fsqmat> eN;
+    eN.set_rv(rv);
+    eN.set_parameters(mu0, R);
+
+    vec pom(2);
+    double suma = 0.0;
+    for (int i = 0; i < x.length(); i++) {
+	for (int j=0; j<y.length(); j++) {
+	    pom(0) = x(i);
+	    pom(1) = y(j);
+	    suma += exp(eN.evallog(pom));
+	}
+    }
+
+    CHECK_CLOSE(100, suma, 0.1);
 }
Index: /brary/tests/testEpdf.cpp
===================================================================
--- /library/tests/testEpdf.cpp (revision 386)
+++  (revision )
@@ -1,43 +1,0 @@
-
-#include "stat/exp_family.h"
-
-using namespace bdm;
-
-//These lines are needed for use of cout and endl
-using std::cout;
-using std::endl;
-
-
-int main() {
-
-	vec x = "-10:0.1:10";
-	vec y = "-10:0.1:10";
-
-	RV rv ( "{x }","2" );
-	vec mu0 = "0.0 0.0";
-	mat V0 ( "5 -0.05; -0.05 5.20" );
-	fsqmat R = fsqmat ( V0 );
-
-	cout << "====== ENorm ====== " <<endl;
-	enorm<fsqmat> eN;eN.set_rv ( rv );
-	eN.set_parameters ( mu0,R );
-	vec pdf = zeros ( x.length() );
-
-	vec pom ( 2 );
-	double suma=0.0;
-
-	for ( int i=0;i<x.length();i++ ) {
-		for ( int j=0;j<y.length();j++ ) {
-			pom ( 0 ) = x ( i );
-			pom ( 1 ) = y ( j );
-			suma+= exp(eN.evallog ( pom ));
-		}
-	}
-
-	cout << suma <<endl;
-
-	//Exit program:
-	return 0;
-
-}
-
