From f8a1fd7cde94f8bbc9bf85d1d20525568ba92525 Mon Sep 17 00:00:00 2001
From: Benjamin Goehry <benjamin.goehry@math.u-psud.fr>
Date: Fri, 13 Jan 2017 16:52:16 +0100
Subject: [PATCH] ajout tests

---
 src/test/TEST R/checkOutput.R | 10 ++++++++++
 src/test/TEST R/covariance.R  |  9 +++++++++
 src/test/TEST R/testEMGLLF.R  | 19 +++++++++++++++++++
 3 files changed, 38 insertions(+)
 create mode 100644 src/test/TEST R/checkOutput.R
 create mode 100644 src/test/TEST R/covariance.R
 create mode 100644 src/test/TEST R/testEMGLLF.R

diff --git a/src/test/TEST R/checkOutput.R b/src/test/TEST R/checkOutput.R
new file mode 100644
index 0000000..1faddaa
--- /dev/null
+++ b/src/test/TEST R/checkOutput.R	
@@ -0,0 +1,10 @@
+checkOutput = function(varName, matrix, refMatrix, tol){
+  print('Checking %s\n',varName);
+  maxError = max(max(max(max(abs(matrix - refMatrix)))));
+  if(maxError >= tol){
+    print('Inaccuracy: max(abs(error)) = %g >= %g\n',maxError,tol)
+  }
+  else{
+    print('OK\n')
+  }
+}
\ No newline at end of file
diff --git a/src/test/TEST R/covariance.R b/src/test/TEST R/covariance.R
new file mode 100644
index 0000000..2dea7f2
--- /dev/null
+++ b/src/test/TEST R/covariance.R	
@@ -0,0 +1,9 @@
+covariance= function(p,a){
+  A = matrix(a, p,p)
+  for{i in 1:p}{
+    for{k  in 1:p}{
+      A[i,]= A[i,]^abs(i-k) 
+    }
+  }
+  return(A=A)
+}
\ No newline at end of file
diff --git a/src/test/TEST R/testEMGLLF.R b/src/test/TEST R/testEMGLLF.R
new file mode 100644
index 0000000..c2f109f
--- /dev/null
+++ b/src/test/TEST R/testEMGLLF.R	
@@ -0,0 +1,19 @@
+testEMGLLF = function(n,p,m,k, phiInit, rhoInit, gamInit, mini, maxi, gamma, lambda, X, Y, tau, ref_phi, ref_rho, ref_pi, ref_LLf, ref_S){
+  testFolder = 'data/'
+  delimiter = '\n'
+  
+  EMG = .Call("EMGLLF_core",phiInit,rhoInit,piInit1,gamInit,mini,maxi,gamma,lambda,X,Y,tau)
+  phi = EMG$phi
+  rho = EMG$rho
+  pi = EMG$pi
+  LLF = EMG$LLF
+  S = EMG$S
+  
+  
+  tol = 1e-5;
+  checkOutput('phi',phi,ref_phi,tol);
+  checkOutput('rho',rho,ref_rho,tol);
+  checkOutput('pi',pi,ref_pi,tol);
+  checkOutput('LLF',LLF,ref_LLF,tol);
+  checkOutput('S',S,ref_S,tol);
+}
-- 
2.44.0