ajout tests
authorBenjamin Goehry <benjamin.goehry@math.u-psud.fr>
Fri, 13 Jan 2017 15:52:16 +0000 (16:52 +0100)
committerBenjamin Goehry <benjamin.goehry@math.u-psud.fr>
Fri, 13 Jan 2017 15:52:16 +0000 (16:52 +0100)
src/test/TEST R/checkOutput.R [new file with mode: 0644]
src/test/TEST R/covariance.R [new file with mode: 0644]
src/test/TEST R/testEMGLLF.R [new file with mode: 0644]

diff --git a/src/test/TEST R/checkOutput.R b/src/test/TEST R/checkOutput.R
new file mode 100644 (file)
index 0000000..1faddaa
--- /dev/null
@@ -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 (file)
index 0000000..2dea7f2
--- /dev/null
@@ -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 (file)
index 0000000..c2f109f
--- /dev/null
@@ -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);
+}