diff --git a/Tests.hs b/Tests.hs index f5fe3ef4e..0de7f7e59 100644 --- a/Tests.hs +++ b/Tests.hs @@ -107,29 +107,6 @@ tests = TestList [ accountNameTreeFrom ["a","a:b"] `is` Node "top" [Node "a" [Node "a:b" []]] accountNameTreeFrom ["a:b:c"] `is` Node "top" [Node "a" [Node "a:b" [Node "a:b:c" []]]] - ,"amount arithmetic" ~: do - let a1 = dollars 1.23 - let a2 = Amount (comm "$") (-1.23) Nothing - let a3 = Amount (comm "$") (-1.23) Nothing - (a1 + a2) `is` Amount (comm "$") 0 Nothing - (a1 + a3) `is` Amount (comm "$") 0 Nothing - (a2 + a3) `is` Amount (comm "$") (-2.46) Nothing - (a3 + a3) `is` Amount (comm "$") (-2.46) Nothing - sum [a2,a3] `is` Amount (comm "$") (-2.46) Nothing - sum [a3,a3] `is` Amount (comm "$") (-2.46) Nothing - sum [a1,a2,a3,-a3] `is` Amount (comm "$") 0 Nothing - let dollar0 = dollar{precision=0} - (sum [Amount dollar 1.25 Nothing, Amount dollar0 (-1) Nothing, Amount dollar (-0.25) Nothing]) - `is` (Amount dollar 0 Nothing) - - ,"mixed amount arithmetic" ~: do - let dollar0 = dollar{precision=0} - (sum $ map (Mixed . (\a -> [a])) - [Amount dollar 1.25 Nothing, - Amount dollar0 (-1) Nothing, - Amount dollar (-0.25) Nothing]) - `is` Mixed [Amount dollar 0 Nothing] - ,"balance report tests" ~: let (opts,args) `gives` es = do l <- sampleledgerwithopts opts args @@ -653,9 +630,6 @@ tests = TestList [ ,"show hours" ~: show (hours 1) ~?= "1.0h" - ,"showMixedAmount" ~: do - showMixedAmount (Mixed []) ~?= "0" - ,"someamount" ~: do let -- | compare a parse result with a MixedAmount, showing the debug representation for clarity assertMixedAmountParse parseresult mixedamount = diff --git a/hledger-lib/Ledger.hs b/hledger-lib/Ledger.hs index 5bb136285..6ca6e7ed1 100644 --- a/hledger-lib/Ledger.hs +++ b/hledger-lib/Ledger.hs @@ -43,9 +43,9 @@ tests_Ledger = TestList [ -- Ledger.Account.tests_Account -- ,Ledger.AccountName.tests_AccountName - -- ,Ledger.Amount.tests_Amount + Ledger.Amount.tests_Amount -- ,Ledger.Commodity.tests_Commodity - Ledger.Dates.tests_Dates + ,Ledger.Dates.tests_Dates -- ,Ledger.IO.tests_IO ,Ledger.Transaction.tests_Transaction -- ,Ledger.Ledger.tests_Ledger diff --git a/hledger-lib/Ledger/Amount.hs b/hledger-lib/Ledger/Amount.hs index 1e79fe460..1362dc42a 100644 --- a/hledger-lib/Ledger/Amount.hs +++ b/hledger-lib/Ledger/Amount.hs @@ -261,3 +261,34 @@ nullmixedamt = Mixed [] missingamt :: MixedAmount missingamt = Mixed [Amount Commodity {symbol="AUTO",side=L,spaced=False,comma=False,precision=0} 0 Nothing] + +tests_Amount = TestList [ + + "showMixedAmount" ~: do + showMixedAmount (Mixed []) ~?= "0" + + ,"amount arithmetic" ~: do + let a1 = dollars 1.23 + let a2 = Amount (comm "$") (-1.23) Nothing + let a3 = Amount (comm "$") (-1.23) Nothing + (a1 + a2) `is` Amount (comm "$") 0 Nothing + (a1 + a3) `is` Amount (comm "$") 0 Nothing + (a2 + a3) `is` Amount (comm "$") (-2.46) Nothing + (a3 + a3) `is` Amount (comm "$") (-2.46) Nothing + sum [a2,a3] `is` Amount (comm "$") (-2.46) Nothing + sum [a3,a3] `is` Amount (comm "$") (-2.46) Nothing + sum [a1,a2,a3,-a3] `is` Amount (comm "$") 0 Nothing + let dollar0 = dollar{precision=0} + (sum [Amount dollar 1.25 Nothing, Amount dollar0 (-1) Nothing, Amount dollar (-0.25) Nothing]) + `is` (Amount dollar 0 Nothing) + + ,"mixed amount arithmetic" ~: do + let dollar0 = dollar{precision=0} + (sum $ map (Mixed . (\a -> [a])) + [Amount dollar 1.25 Nothing, + Amount dollar0 (-1) Nothing, + Amount dollar (-0.25) Nothing]) + `is` Mixed [Amount dollar 0 Nothing] + + + ]