From 1fd196911ebf1fc4e5140cf1f891f77c35cdb5d1 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Wed, 4 Apr 2018 11:40:16 +0200
Subject: [PATCH] Factorize code in norm tests

---
 tests/spm_tests.h   | 14 ++++++++++++++
 tests/z_spm_tests.c | 44 ++++----------------------------------------
 2 files changed, 18 insertions(+), 40 deletions(-)

diff --git a/tests/spm_tests.h b/tests/spm_tests.h
index 758c720c..f742e181 100644
--- a/tests/spm_tests.h
+++ b/tests/spm_tests.h
@@ -87,4 +87,18 @@ void s_spm_print_check( char *filename, const spmatrix_t *spm );
 int  s_spm_matvec_check( int trans, const spmatrix_t *spm );
 int  s_spm_norm_check( const spmatrix_t *spm );
 
+static inline
+void spm_norm_print_result( double norms, double normd, double result )
+{
+    if ( (result >= 0.) && (result < 1.) ) {
+        printf("SUCCESS !\n");
+    } else {
+        printf("FAILED !\n");
+        ret++;
+    }
+
+    printf("   Nsparse = %e, Ndense = %e\n", norms, normd );
+    printf("  | Nsparse - Ndense | / Ndense = %e\n", result);
+}
+
 #endif /* _spm_tests_h_ */
diff --git a/tests/z_spm_tests.c b/tests/z_spm_tests.c
index 6d74e8f8..71c58b2b 100644
--- a/tests/z_spm_tests.c
+++ b/tests/z_spm_tests.c
@@ -204,16 +204,7 @@ z_spm_norm_check( const spmatrix_t *spm )
     norms = spmNorm( SpmMaxNorm, spm );
     normd = LAPACKE_zlange( LAPACK_COL_MAJOR, 'M', spm->gNexp, spm->gNexp, A, spm->gNexp );
     result = fabs(norms - normd) / (normd * eps);
-
-    if ( (result >= 0.) && (result < 1.) ) {
-        printf("SUCCESS !\n");
-    } else {
-        printf("FAILED !\n");
-        ret++;
-    }
-
-    printf("   Nsparse = %e, Ndense = %e\n", norms, normd );
-    printf("  | Nsparse - Ndense | / Ndense = %e\n", result);
+    spm_norm_print_result( norms, normd, result );
 
     /**
      * Test Norm Inf
@@ -223,16 +214,7 @@ z_spm_norm_check( const spmatrix_t *spm )
     normd = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', spm->gNexp, spm->gNexp, A, spm->gNexp );
     result = fabs(norms - normd) / (normd * eps);
     result = result * ((double)(spm->gNexp)) / ((double)(spm->gnnzexp));
-
-    if ( (result >= 0.) && (result < 1.) ) {
-        printf("SUCCESS !\n");
-    } else {
-        printf("FAILED !\n");
-        ret++;
-    }
-
-    printf("   Nsparse = %e, Ndense = %e\n", norms, normd );
-    printf("  | Nsparse - Ndense | / Ndense = %e\n", result);
+    spm_norm_print_result( norms, normd, result );
 
     /**
      * Test Norm One
@@ -242,16 +224,7 @@ z_spm_norm_check( const spmatrix_t *spm )
     normd = LAPACKE_zlange( LAPACK_COL_MAJOR, 'O', spm->gNexp, spm->gNexp, A, spm->gNexp );
     result = fabs(norms - normd) / (normd * eps);
     result = result * ((double)(spm->gNexp)) / ((double)(spm->gnnzexp));
-
-    if ( (result >= 0.) && (result < 1.) ) {
-        printf("SUCCESS !\n");
-    } else {
-        printf("FAILED !\n");
-        ret++;
-    }
-
-    printf("   Nsparse = %e, Ndense = %e\n", norms, normd );
-    printf("  | Nsparse - Ndense | / Ndense = %e\n", result);
+    spm_norm_print_result( norms, normd, result );
 
     /**
      * Test Norm Frobenius
@@ -261,16 +234,7 @@ z_spm_norm_check( const spmatrix_t *spm )
     normd = LAPACKE_zlange( LAPACK_COL_MAJOR, 'F', spm->gNexp, spm->gNexp, A, spm->gNexp );
     result = fabs(norms - normd) / (normd * eps);
     result = result / ((double)spm->gnnzexp);
-
-    if ( (result >= 0.) && (result < 1.) ) {
-        printf("SUCCESS !\n");
-    } else {
-        printf("FAILED !\n");
-        ret++;
-    }
-
-    printf("   Nsparse = %e, Ndense = %e\n", norms, normd );
-    printf("  | Nsparse - Ndense | / Ndense = %e\n", result);
+    spm_norm_print_result( norms, normd, result );
 
     free(A);
     return ret;
-- 
GitLab