[grisbi-cvs] grisbi/src gsb_real.c, 1.38, 1.39 gsb_real.h, 1.16, 1.17 gsb_real_cunit.c, 1.7, 1.8

Mickaƫl Remars mykeul at users.sourceforge.net
Wed May 20 21:49:31 CEST 2009


Update of /cvsroot/grisbi/grisbi/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv21442/src

Modified Files:
	gsb_real.c gsb_real.h gsb_real_cunit.c 
Log Message:
Added a new unit-test on gsb_real_normalize(), most of the assertions fail with the current version of the function

Index: gsb_real.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_real.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- gsb_real.c	17 May 2009 15:53:25 -0000	1.38
+++ gsb_real.c	20 May 2009 19:49:29 -0000	1.39
@@ -52,8 +52,6 @@
                         gint currency_number,
                         gboolean show_symbol );
 static gsb_real gsb_real_get_from_string_normalized ( const gchar *string, gint default_exponent );
-static gboolean gsb_real_normalize ( gsb_real *number_1,
-                        gsb_real *number_2 );
 static gdouble gsb_real_real_to_double ( gsb_real number );
 /*END_STATIC*/
 

Index: gsb_real_cunit.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_real_cunit.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- gsb_real_cunit.c	20 May 2009 19:32:01 -0000	1.7
+++ gsb_real_cunit.c	20 May 2009 19:49:29 -0000	1.8
@@ -184,6 +184,48 @@
     g_free(s);
 }
 
+void gsb_real_cunit__gsb_real_normalize()
+{
+    gsb_real a;
+    gsb_real b;
+    a.mantissa = 1;
+    a.exponent = 0;
+    b.mantissa = 31415;
+    b.exponent = 4;
+    CU_ASSERT_EQUAL ( TRUE, gsb_real_normalize ( &a, &b ) );
+    CU_ASSERT_EQUAL ( 10000, a.mantissa );
+    CU_ASSERT_EQUAL ( 4, a.exponent );
+    CU_ASSERT_EQUAL ( 31415, b.mantissa );
+    CU_ASSERT_EQUAL ( 4, b.exponent );
+
+    a.mantissa = 0x7FFFFFFF;
+    a.exponent = 1;
+    b.mantissa = 11;
+    b.exponent = 0;
+    CU_ASSERT_EQUAL ( TRUE, gsb_real_normalize ( &a, &b ) );
+    CU_ASSERT_EQUAL ( 0x7FFFFFFF, a.mantissa );
+    CU_ASSERT_EQUAL ( 1, a.exponent );
+    CU_ASSERT_EQUAL ( 110, b.mantissa );
+    CU_ASSERT_EQUAL ( 1, b.exponent );
+
+    a.mantissa = 11;
+    a.exponent = 0;
+    b.mantissa = 0x7FFFFFFF;
+    b.exponent = 1;
+    CU_ASSERT_EQUAL ( TRUE, gsb_real_normalize ( &a, &b ) );
+    CU_ASSERT_EQUAL ( 110, a.mantissa );
+    CU_ASSERT_EQUAL ( 1, a.exponent );
+    CU_ASSERT_EQUAL ( 0x7FFFFFFF, b.mantissa );
+    CU_ASSERT_EQUAL ( 1, b.exponent );
+
+    a.mantissa = 0x7FFFFFFF;
+    a.exponent = 1;
+    b.mantissa = 0x7FFFFFFF;
+    b.exponent = 0;
+    // Impossible to normalize without losing precision
+    CU_ASSERT_EQUAL ( FALSE, gsb_real_normalize ( &a, &b ) );
+}
+
 void gsb_real_cunit__gsb_real_add ( void )
 {
     gsb_real a = {1, 0};
@@ -292,6 +334,7 @@
 
     if((NULL == CU_add_test(pSuite, "of gsb_real_get_from_string()",   gsb_real_cunit__gsb_real_get_from_string))
     || (NULL == CU_add_test(pSuite, "of gsb_real_raw_format_string()", gsb_real_cunit__gsb_real_raw_format_string))
+    || (NULL == CU_add_test(pSuite, "of gsb_real_gsb_real_normalize()",  gsb_real_cunit__gsb_real_normalize))
     || (NULL == CU_add_test(pSuite, "of gsb_real_add()",               gsb_real_cunit__gsb_real_add))
     || (NULL == CU_add_test(pSuite, "of gsb_real_sub()",               gsb_real_cunit__gsb_real_sub))
        )

Index: gsb_real.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_real.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- gsb_real.h	17 May 2009 15:53:25 -0000	1.16
+++ gsb_real.h	20 May 2009 19:49:29 -0000	1.17
@@ -21,6 +21,8 @@
                         gsb_real number_2 );
 gsb_real gsb_real_adjust_exponent ( gsb_real number,
                         gint return_exponent );
+gboolean gsb_real_normalize ( gsb_real *number_1,
+                        gsb_real *number_2 );
 gint gsb_real_cmp ( gsb_real number_1,
                         gsb_real number_2 );
 gsb_real gsb_real_div ( gsb_real number_1,



More information about the cvs mailing list