[test-engine-extras] don't create splits of opposing amt/value signs

Splits' value and amount should never be of opposite signs. Fix
test book which had created this incorrect value/amount
pair. Strengthen env-create-multisplit-transaction to disallow
test book errors.
This commit is contained in:
Christopher Lam 2021-11-21 23:25:18 +08:00
parent 4903a3e8ce
commit d861c65020
3 changed files with 8 additions and 2 deletions

View File

@ -223,6 +223,9 @@
#:memo memo
#:notes notes))
(define (opposite-signs? a b)
(< (* a b) 0))
;; creates multisplit transaction.
;;
;; input: DD/MM/YY - posting date of transaction
@ -262,6 +265,9 @@
(action (and (> (vector-length split) 3)
(vector-ref split 3)))
(newsplit (xaccMallocSplit book)))
(when (opposite-signs? val amt)
(error "env-create-multisplit-transaction error for" DD '/ MM '/ YY
'opposing-signs: 'val val 'amt amt))
(xaccSplitSetParent newsplit txn)
(xaccSplitSetAccount newsplit acc)
(xaccSplitSetValue newsplit val)

View File

@ -139,7 +139,7 @@
(env-create-multisplit-transaction
env 16 04 2020
(list (vector usd-cash 2500 -2500)
(list (vector usd-cash 2500 2500)
(vector spy -2500 0 "Buy")
)
#:description "Return of Capital"

View File

@ -167,7 +167,7 @@
#:description "Buy MSFT 1500") ;;1500 @ $28.11
(env-transfer-foreign env 20 01 2012 checking-dem dmlr-a 1500 80
#:description "Buy DMLR 80") ;;80 @ DM1500.00
(env-transfer-foreign env 20 02 2012 checking-dem dmlr-a -1610 80
(env-transfer-foreign env 20 02 2012 checking-dem dmlr-a -1610 -80
#:description "Sell DMLR 80") ;;80 @ DM1610.00
(env-transfer-foreign env 20 02 2012 capgain-dem dmlr-a 110 0
#:description "DMLR 80 G/L") ;;80 @ DM1610.00