[Gnucash-changes] tweak to attempt to minimize numeric overflows

Linas Vepstas linas at cvs.gnucash.org
Sun Jun 6 23:05:36 EDT 2004


Log Message:
-----------
tweak to attempt to minimize numeric overflows

Modified Files:
--------------
    gnucash/src/engine/test-core:
        test-engine-stuff.c

Revision Data
-------------
Index: test-engine-stuff.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/test-core/test-engine-stuff.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -Lsrc/engine/test-core/test-engine-stuff.c -Lsrc/engine/test-core/test-engine-stuff.c -u -r1.66 -r1.67
--- src/engine/test-core/test-engine-stuff.c
+++ src/engine/test-core/test-engine-stuff.c
@@ -30,6 +30,8 @@
 
 static gint max_group_depth = 4;
 static gint max_group_accounts = 10;
+static gint max_total_accounts = 1000;
+static gint total_num_accounts = 0;
 
 static kvp_value* get_random_kvp_value_depth (int type, gint depth);
 static gpointer get_random_list_element (GList *list);
@@ -143,7 +145,31 @@
 gnc_numeric
 get_random_gnc_numeric(void)
 {
-    return gnc_numeric_create(get_random_gint64(), rand());
+    gint64 deno = rand();
+    gint64 numer = get_random_gint64();
+
+#if 1
+    if (RAND_MAX/2 < rand())
+    {
+       gint64 norm = RAND_MAX / 2000;
+       /* Random number between 1 and 2000 */
+       deno /= norm;
+       deno += 1;
+    }
+    else
+    {
+       gint64 norm = RAND_MAX / 8;
+       /* multiple of 10, between 1 and 100 million */
+       norm = deno / norm;
+       deno = 1;
+       while (norm) 
+       {
+          deno *= 10;
+          norm --;
+       }
+    }
+#endif
+    return gnc_numeric_create(numer, deno);
 }
 
 const char *types[] =
@@ -541,13 +567,15 @@
     return;
 
   num_accounts = get_random_int_in_range (1, 10);
-
   while (num_accounts-- > 0)
   {
     Account *sub = get_random_account (book);
 
     xaccAccountInsertSubAccount (account, sub);
 
+    total_num_accounts ++;
+    if (total_num_accounts > max_total_accounts) return;
+
     account_add_subaccounts (book, sub, depth - 1);
   }
 }
@@ -583,6 +611,7 @@
   g_return_if_fail (book);
   g_return_if_fail (group);
 
+  total_num_accounts = 0;
   depth = get_random_int_in_range (1, max_group_depth);
 
   make_random_group_depth (book, group, depth);


More information about the gnucash-changes mailing list