[test-balsheet-pnl] separate balance-sheet and pnl tests

This is in preparation for balsheet-pnl tests. Note all tests use same
data -- there's no (teardown).
This commit is contained in:
Christopher Lam 2019-11-26 18:11:15 +08:00
parent 119fdc368b
commit 88644451ef

View File

@ -23,7 +23,9 @@
(test-runner-factory gnc:test-runner) (test-runner-factory gnc:test-runner)
(test-begin "balsheet and profit&loss") (test-begin "balsheet and profit&loss")
(null-test) (null-test)
(balsheet-pnl-tests) (create-test-data)
(balance-sheet-tests)
(pnl-tests)
(test-end "balsheet and profit&loss")) (test-end "balsheet and profit&loss"))
(define (options->sxml uuid options test-title) (define (options->sxml uuid options test-title)
@ -80,7 +82,7 @@
(let ((balance-sheet-options (gnc:make-report-options balance-sheet-uuid))) (let ((balance-sheet-options (gnc:make-report-options balance-sheet-uuid)))
(test-assert "null-test" (options->sxml balance-sheet-uuid balance-sheet-options "null-test")))) (test-assert "null-test" (options->sxml balance-sheet-uuid balance-sheet-options "null-test"))))
(define (balsheet-pnl-tests) (define (create-test-data)
;; This function will perform implementation testing on the transaction report. ;; This function will perform implementation testing on the transaction report.
(let* ((env (create-test-env)) (let* ((env (create-test-env))
(account-alist (env-create-account-structure-alist env structure)) (account-alist (env-create-account-structure-alist env structure))
@ -95,23 +97,7 @@
(bank2creditcard (cdr (assoc "CreditCard" account-alist))) (bank2creditcard (cdr (assoc "CreditCard" account-alist)))
(equity (cdr (assoc "Equity" account-alist))) (equity (cdr (assoc "Equity" account-alist)))
(income (cdr (assoc "Income" account-alist))) (income (cdr (assoc "Income" account-alist)))
(income-GBP (cdr (assoc "Income-GBP" account-alist))) (income-GBP (cdr (assoc "Income-GBP" account-alist))))
(YEAR (gnc:time64-get-year (gnc:get-today))))
(define (default-balsheet-testing-options)
(let ((balance-sheet-options (gnc:make-report-options balance-sheet-uuid)))
(set-option! balance-sheet-options "General" "Balance Sheet Date" (cons 'absolute (gnc-dmy2time64 1 1 1971)))
(set-option! balance-sheet-options "Accounts" "Levels of Subaccounts" 'all)
(set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #t)
balance-sheet-options))
(define (default-pnl-testing-options)
(let ((pnl-options (gnc:make-report-options pnl-uuid)))
(set-option! pnl-options "General" "Start Date" (cons 'absolute (gnc-dmy2time64 1 1 1980)))
(set-option! pnl-options "General" "End Date" (cons 'absolute (gnc-dmy2time64 1 1 1981)))
(set-option! pnl-options "Accounts" "Levels of Subaccounts" 'all)
(set-option! pnl-options "Commodities" "Show Exchange Rates" #t)
pnl-options))
;; $100 in Savings account ;; $100 in Savings account
(env-transfer env 01 01 1970 equity bank1savings 100) (env-transfer env 01 01 1970 equity bank1savings 100)
@ -169,12 +155,19 @@
;; a couple INCOME transactions, a decade later ;; a couple INCOME transactions, a decade later
(env-transfer env 01 01 1980 income bank1current 250) (env-transfer env 01 01 1980 income bank1current 250)
(env-transfer env 01 01 1980 income-GBP foreignsavings 500) (env-transfer env 01 01 1980 income-GBP foreignsavings 500)
(env-transfer-foreign env 01 02 1980 income-GBP bank1current 100 170 #:description "earn 100GBP into $170") (env-transfer-foreign env 01 02 1980 income-GBP bank1current 100 170 #:description "earn 100GBP into $170")))
;; Finally we can begin testing balsheet (define (balance-sheet-tests)
(define (default-balsheet-testing-options)
(let ((balance-sheet-options (gnc:make-report-options balance-sheet-uuid)))
(set-option! balance-sheet-options "General" "Balance Sheet Date" (cons 'absolute (gnc-dmy2time64 1 1 1971)))
(set-option! balance-sheet-options "Accounts" "Levels of Subaccounts" 'all)
(set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #t)
balance-sheet-options))
(display "\n\n balsheet tests\n\n") (display "\n\n balsheet tests\n\n")
(let* ((balance-sheet-options (default-balsheet-testing-options)) (let* ((balance-sheet-options (default-balsheet-testing-options))
(sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-default"))) (sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-default")))
(test-equal "total assets = $116,009" (test-equal "total assets = $116,009"
(list "$116,009.00") (list "$116,009.00")
(sxml->table-row-col sxml 1 15 6)) (sxml->table-row-col sxml 1 15 6))
@ -355,9 +348,16 @@
(sxml->table-row-col sxml 1 3 6)) (sxml->table-row-col sxml 1 3 6))
(test-equal "incl-zb-accts=#t" (test-equal "incl-zb-accts=#t"
'("Empty" "$0.00") '("Empty" "$0.00")
(sxml->table-row-col sxml 1 8 #f))) (sxml->table-row-col sxml 1 8 #f)))))
)
(define (pnl-tests)
(define (default-pnl-testing-options)
(let ((pnl-options (gnc:make-report-options pnl-uuid)))
(set-option! pnl-options "General" "Start Date" (cons 'absolute (gnc-dmy2time64 1 1 1980)))
(set-option! pnl-options "General" "End Date" (cons 'absolute (gnc-dmy2time64 1 1 1981)))
(set-option! pnl-options "Accounts" "Levels of Subaccounts" 'all)
(set-option! pnl-options "Commodities" "Show Exchange Rates" #t)
pnl-options))
(display "\n\n pnl tests\n\n") (display "\n\n pnl tests\n\n")
(let* ((pnl-options (default-pnl-testing-options)) (let* ((pnl-options (default-pnl-testing-options))
(sxml (options->sxml pnl-uuid pnl-options "pnl-default"))) (sxml (options->sxml pnl-uuid pnl-options "pnl-default")))
@ -464,5 +464,4 @@
;;make-multilevel ;;make-multilevel
(set-option! pnl-options "Display" "Parent account balances" 'immediate-bal) (set-option! pnl-options "Display" "Parent account balances" 'immediate-bal)
(set-option! pnl-options "Display" "Parent account subtotals" 't) (set-option! pnl-options "Display" "Parent account subtotals" 't)))
)))