clean up test generator to produce self-consistent data.

I make these changes with some trepidation, since this puts
a whole lot less stress on the 'scrub' infrastructure.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@10167 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2004-07-06 03:40:57 +00:00
parent 5ac7a28aa8
commit a069fe265f

View File

@ -1005,24 +1005,47 @@ set_tran_random_string(Transaction* trn,
static void
add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
{
Account *account;
Account *acc, *bcc;
Split *s;
/* Gotta have at least two different accounts */
if (1 >= g_list_length (account_list)) return;
/* Set up two splits whose values really are opposites. */
gnc_commodity *com = xaccTransGetCurrency (trn);
int scu = gnc_commodity_get_fraction(com);
gnc_numeric num = get_random_gnc_numeric();
num = gnc_numeric_convert (num, scu, GNC_HOW_RND_ROUND);
account = get_random_list_element (account_list);
s = get_random_split(book, account);
acc = get_random_list_element (account_list);
s = get_random_split(book, acc);
xaccTransAppendSplit(trn, s);
xaccSplitSetValue(s, num);
account = get_random_list_element (account_list);
s = get_random_split(book, account);
if (gnc_commodity_equal (xaccTransGetCurrency(trn),
xaccAccountGetCommodity(acc)))
{
xaccSplitSetAmount(s, num);
}
/* Make sure that each side of the transaction is in
* a different account; otherwise get weirdness in lot
* calculcations. ... Hmm maybe should fix lots in
* this case? */
do {
bcc = get_random_list_element (account_list);
} while (bcc == acc);
s = get_random_split(book, bcc);
xaccTransAppendSplit(trn, s);
xaccSplitSetValue(s, gnc_numeric_neg(num));
if (gnc_commodity_equal (xaccTransGetCurrency(trn),
xaccAccountGetCommodity(bcc)))
{
xaccSplitSetAmount(s, num);
}
}
static void