Correction : Calc.Balance.infer_equilibrium
authorJulien Moutinho <julm+hcompta@autogeree.net>
Thu, 21 May 2015 05:46:34 +0000 (07:46 +0200)
committerJulien Moutinho <julm+hcompta@autogeree.net>
Thu, 21 May 2015 10:13:19 +0000 (12:13 +0200)
cli/Hcompta/CLI/Command/Balance.hs
cli/Hcompta/CLI/Format/Ledger.hs
lib/Hcompta/Calc/Balance.hs
lib/Hcompta/Format/Ledger/Balance.hs
lib/Test/Main.hs

index 3a43c02eee0d86f2e10065879d2cb6132a874f1a..d5ef16137d0eee2f54e8942b26d1efb60c1befb0 100644 (file)
@@ -108,7 +108,7 @@ run context args = do
                Write.debug context $ ppShow $ balance
                Write.debug context $ ppShow $
                        Lib.TreeMap.flatten (const ()) (Balance.by_account balance)
-               let expanded = Balance.expand $ Balance.by_account balance
+               let expanded = Balance.expanded $ Balance.by_account balance
                Write.debug context $ ppShow $ expanded
                with_color <- Write.with_color context IO.stdout
                Ledger.Write.put with_color IO.stdout $ do
index 172d8fcd6dcef22dc745b99f3f87a6232436a057..3119f8ac9e7be1c39dcc92d0e724c36c1103fef0 100644 (file)
@@ -42,14 +42,14 @@ paths _context ps = return ps
 
 equilibre :: Context.Context -> [Ledger.Journal] -> IO ()
 equilibre context journals =
-       case Lib.Foldable.find Ledger.Balance.equilibre journals of
+       case Lib.Foldable.find Ledger.Balance.check_equilibrium journals of
         Nothing -> return ()
-        Just ((tr, eq), path) -> do
+        Just ((tr, deviation), path) -> do
                with_color <- Write.with_color context IO.stdout
                Write.fatal context $ concat
                 [ "the following transaction is not equilibrated, because:"
-                , case eq of
-                        Balance.Equilibre e | not $ Balance.is_equilibrable eq ->
+                , case deviation of
+                        Balance.Deviation dev | not $ Balance.is_equilibrium_inferrable deviation ->
                                concat $ Data.Map.elems $ Data.Map.mapWithKey
                                 (\unit Balance.Unit_Sum{Balance.amount} -> concat
                                        [ "\n- unit \""
@@ -57,7 +57,7 @@ equilibre context journals =
                                        , "\" sums up to the non-null amount: "
                                        , TL.unpack $ Ledger.Write.show with_color $ Ledger.Write.amount amount
                                        ])
-                                e
+                                dev
                         _ -> ""
                 , "\nin ", show $ Transaction.sourcepos tr
                 , concat $ map (\j -> "\nincluded by \"" ++ Ledger.Journal.file j ++ "\"") path
index 3fd1c1406f93f6300aebc0282ff39030448ddaf2..c00cc12540786edb5e36013a32b420b812050d66 100644 (file)
@@ -192,11 +192,12 @@ union b0 b1 =
                 (by_unit b1)
         }
 
--- * The 'Equilibre' type
+-- * The 'Deviation' type
 
--- | See 'equilibre'.
-newtype Equilibre
- =      Equilibre By_Unit
+-- | The 'By_Unit' whose 'Unit_Sum's’ 'amount'
+--   is not zero and possible 'Account' to 'infer_equilibrium'.
+newtype Deviation
+ =      Deviation By_Unit
  deriving (Data, Eq, Read, Show, Typeable)
 
 -- | Return the 'by_unit' of the given 'Balance' with:
@@ -206,11 +207,11 @@ newtype Equilibre
 -- * and remaining 'Unit's having their 'Unit_Sum' 'accounts'
 -- complemented with the 'by_account' of the given 'Balance'
 -- (i.e. now mapping to accounts __not__ involved to build the 'Unit_Sum').
-equilibre :: Balance -> Equilibre
-equilibre balance = do
+deviation :: Balance -> Deviation
+deviation balance = do
        let all_accounts = Lib.TreeMap.flatten (const ()) (by_account balance)
        let max_accounts = Data.Map.size all_accounts
-       Equilibre $
+       Deviation $
                Data.Map.foldlWithKey
                 (\m unit Unit_Sum{amount, accounts} ->
                        if Amount.is_zero amount
@@ -226,21 +227,17 @@ equilibre balance = do
                 Data.Map.empty
                 (by_unit balance)
 
-
--- | Return either:
+-- | Return the 'Balance' of the given 'Posting's and either:
 --
---   * 'Left': the 'Posting.By_Account's (lazy list) that cannot be inferred
---   * 'Right': the given 'Posting.By_Account's with inferred 'Amount's inserted.
-infer_equilibre
+--   * 'Left': the 'Posting's that cannot be inferred.
+--   * 'Right': the given 'Posting's with inferred 'Amount's inserted.
+infer_equilibrium
  :: Posting.By_Account
- -> Either [Unit_Sum]
-           Posting.By_Account
-infer_equilibre ps = do
+ -> (Balance, Either [Unit_Sum] Posting.By_Account)
+infer_equilibrium ps = do
        let bal = postings ps nil
-       let Equilibre equ = equilibre bal
-       (\(l, r) -> case l of
-                _:_ -> Left l
-                _   -> Right r) $ do
+       let Deviation dev = deviation bal
+       (\(l, r) -> (bal, case l of { [] -> Right r; _ -> Left l })) $ do
        Lib.Foldable.accumLeftsAndFoldrRights
         (\p -> Data.Map.insertWith
                 (\pn -> (++) pn . Data.List.filter (not . Data.Map.null . Posting.amounts))
@@ -249,50 +246,39 @@ infer_equilibre ps = do
        Data.Foldable.foldr
         (\unit_sum@(Unit_Sum{ amount=amt, accounts }) acc ->
                case Data.Map.size accounts of
-                0 -> acc
                 1 -> (Right $ (Posting.nil $ fst $ Data.Map.elemAt 0 accounts)
-                                { Posting.amounts = Amount.from_List [negate amt] }
-                        ):acc
-                _ -> Left [unit_sum]:acc
-        )
+                        { Posting.amounts = Amount.from_List [negate amt] }):acc
+                _ -> Left [unit_sum]:acc)
         []
-        equ
+        dev
 
 -- ** Tests
 
--- | Return 'True' if and only if the given 'Equilibre' satisfies:
---
--- * 'is_equilibrated',
--- * or 'is_inferrable'.
-is_equilibrable :: Equilibre -> Bool
-is_equilibrable e@(Equilibre eq) =
-       Data.Map.null eq || is_inferrable e
-
--- | Return 'True' if and only if the given 'Equilibre' maps no 'Unit'.
-is_equilibrated :: Equilibre -> Bool
-is_equilibrated (Equilibre eq) = Data.Map.null eq
+-- | Return 'True' if and only if the given 'Deviation' maps no 'Unit'.
+is_at_equilibrium :: Deviation -> Bool
+is_at_equilibrium (Deviation dev) = Data.Map.null dev
 
--- | Return 'True' if and only if the given 'Equilibre'
+-- | Return 'True' if and only if the given 'Deviation'
 -- maps only to 'Unit_Sum's whose 'accounts'
 -- maps exactly one 'Account'.
-is_inferrable :: Equilibre -> Bool
-is_inferrable (Equilibre eq) =
+is_equilibrium_inferrable :: Deviation -> Bool
+is_equilibrium_inferrable (Deviation dev) =
        Data.Foldable.all
         (\Unit_Sum{accounts} -> Data.Map.size accounts == 1)
-        eq
+        dev
 
--- | Return 'True' if and only if the given 'Equilibre'
+-- | Return 'True' if and only if the given 'Deviation'
 -- maps to at least one 'Unit_Sum's whose 'accounts'
 -- maps more than one 'Account'.
-is_non_inferrable :: Equilibre -> Bool
-is_non_inferrable (Equilibre eq) =
+is_equilibrium_non_inferrable :: Deviation -> Bool
+is_equilibrium_non_inferrable (Deviation dev) =
        Data.Foldable.any
         (\Unit_Sum{accounts} -> Data.Map.size accounts > 1)
-        eq
+        dev
 
 -- * The 'Expanded' type
 
--- | See 'expand'.
+-- | Descending propagation of 'Amount's accross 'Account's.
 type Expanded = Lib.TreeMap.TreeMap Account.Name Account_Sum_Expanded
 data Account_Sum_Expanded
  =   Account_Sum_Expanded
@@ -308,8 +294,8 @@ data Account_Sum_Expanded
 -- * and every mapped Amount.'Amount.By_Unit'
 -- added with any Amount.'Amount.By_Unit'
 -- of the 'Account's’ for which it is 'Account.ascending'.
-expand :: By_Account -> Expanded
-expand =
+expanded :: By_Account -> Expanded
+expanded =
        Lib.TreeMap.map_by_depth_first
         (\descendants value ->
                let exc = fromMaybe Data.Map.empty value in
@@ -319,7 +305,7 @@ expand =
                        Data.Map.foldr
                         ( Data.Map.unionWith (GHC.Num.+)
                         . ( inclusive
-                                . fromMaybe (error "Oops, should not happen in: Hcompta.Calc.Balance.expand")
+                                . fromMaybe (error "Oops, should not happen in: Hcompta.Calc.Balance.expanded")
                                 . Lib.TreeMap.node_value) )
                         exc $ Lib.TreeMap.nodes $ descendants
                 })
index e2ec71763254816c3c74fcdce4b7b01b8e26ee87..42cfc2c6a21620a2d76a698d913ff3003ad662e6 100644 (file)
@@ -7,22 +7,23 @@ import qualified Hcompta.Format.Ledger.Journal as Journal
 import           Hcompta.Format.Ledger.Journal (Journal(..))
 import qualified Hcompta.Lib.Foldable as Lib.Foldable
 
--- * The 'Balance.Equilibre' type
+-- * The 'Balance.Deviation' type
 
--- | Return the first 'Transaction' (if any) which does not respect 'Balance.is_equilibrable'
+-- | Return the first 'Transaction' (if any) whose 'Posting's
+--   do not sum to a 'Balance' respecting 'Balance.is_inferrable',
 --   with the path of 'Journal's leading to that 'Transaction'.
-equilibre :: Journal -> Maybe ((Transaction, Balance.Equilibre), [Journal])
-equilibre =
+check_equilibrium :: Journal -> Maybe ((Transaction, Balance.Deviation), [Journal])
+check_equilibrium =
        Journal.find
         (\Journal{Journal.transactions} ->
                Lib.Foldable.find
                 (Lib.Foldable.find
                         (\tr -> do
                                let bal = Balance.transaction tr Balance.nil
-                               let eq = Balance.equilibre bal
-                               if Balance.is_equilibrable eq
+                               let dev = Balance.deviation bal
+                               if Balance.is_equilibrium_inferrable dev
                                        then Nothing
-                                       else Just (tr, eq)
+                                       else Just (tr, dev)
                         )
                 )
                 transactions
index 77e00cda0f4c0872ba89a7120cb82b7771aeb6a6..b8684f2e22e3a8f1c1e9104e006deef3da4b0d94 100644 (file)
@@ -300,6 +300,34 @@ test_Hcompta =
                                                         }
                                                        ]
                                                 }
+                                , "[A+$1, B+$1]" ~:
+                                        (Data.List.foldl
+                                                (flip Calc.Balance.posting)
+                                                Calc.Balance.nil
+                                                [ (Posting.nil ("A":|[]))
+                                                        { Posting.amounts=Amount.from_List [ Amount.usd $ 1 ]
+                                                        }
+                                                , (Posting.nil ("B":|[]))
+                                                        { Posting.amounts=Amount.from_List [ Amount.usd $ 1 ]
+                                                        }
+                                                ])
+                                        ~?=
+                                        Calc.Balance.Balance
+                                                { Calc.Balance.by_account =
+                                                       Lib.TreeMap.from_List const
+                                                        [ ("A":|[], Amount.from_List [ Amount.usd $ 1 ])
+                                                        , ("B":|[], Amount.from_List [ Amount.usd $ 1 ])
+                                                        ]
+                                                , Calc.Balance.by_unit =
+                                                       Data.Map.fromList $
+                                                       Data.List.map Calc.Balance.assoc_unit_sum $
+                                                       [ Calc.Balance.Unit_Sum
+                                                        { Calc.Balance.amount = Amount.usd $ 2
+                                                        , Calc.Balance.accounts = Data.Map.fromList $ Data.List.map (,())
+                                                                ["A":|[], "B":|[]]
+                                                        }
+                                                       ]
+                                                }
                                 , "[A+$1+€2, A-$1-€2] = {A+$0+€0, $+0 €+0}" ~:
                                         (Data.List.foldl
                                                 (flip Calc.Balance.posting)
@@ -521,14 +549,14 @@ test_Hcompta =
                                                        ]
                                                 }
                                 ]
-                        , "expand" ~: TestList
+                        , "expanded" ~: TestList
                                 [ "nil_By_Account" ~:
-                                        Calc.Balance.expand
+                                        Calc.Balance.expanded
                                                 Calc.Balance.nil_By_Account
                                         ~?=
                                         Lib.TreeMap.empty
                                 , "A+$1 = A+$1" ~:
-                                        Calc.Balance.expand
+                                        Calc.Balance.expanded
                                                (Lib.TreeMap.from_List const
                                                 [ ("A":|[], Amount.from_List [ Amount.usd $ 1 ]) ])
                                         ~?=
@@ -539,7 +567,7 @@ test_Hcompta =
                                                         })
                                                 ])
                                 , "A/A+$1 = A+$1 A/A+$1" ~:
-                                        Calc.Balance.expand
+                                        Calc.Balance.expanded
                                                (Lib.TreeMap.from_List const
                                                 [ ("A":|["A"], Amount.from_List [ Amount.usd $ 1 ]) ])
                                         ~?=
@@ -554,7 +582,7 @@ test_Hcompta =
                                                         })
                                                 ])
                                 , "A/B+$1 = A+$1 A/B+$1" ~:
-                                        Calc.Balance.expand
+                                        Calc.Balance.expanded
                                                (Lib.TreeMap.from_List const
                                                 [ ("A":|["B"], Amount.from_List [ Amount.usd $ 1 ]) ])
                                         ~?=
@@ -569,7 +597,7 @@ test_Hcompta =
                                                         })
                                                 ])
                                 , "A/B/C+$1 = A+$1 A/B+$1 A/B/C+$1" ~:
-                                        Calc.Balance.expand
+                                        Calc.Balance.expanded
                                                (Lib.TreeMap.from_List const
                                                 [ ("A":|["B", "C"], Amount.from_List [ Amount.usd $ 1 ]) ])
                                         ~?=
@@ -588,7 +616,7 @@ test_Hcompta =
                                                         })
                                                 ])
                                 , "A+$1 A/B+$1 = A+$2 A/B+$1" ~:
-                                        Calc.Balance.expand
+                                        Calc.Balance.expanded
                                                (Lib.TreeMap.from_List const
                                                 [ ("A":|[], Amount.from_List [ Amount.usd $ 1 ])
                                                 , ("A":|["B"], Amount.from_List [ Amount.usd $ 1 ])
@@ -605,7 +633,7 @@ test_Hcompta =
                                                         })
                                                 ])
                                 , "A+$1 A/B+$1 A/B/C+$1 = A+$3 A/B+$2 A/B/C+$1" ~:
-                                        Calc.Balance.expand
+                                        Calc.Balance.expanded
                                                (Lib.TreeMap.from_List const
                                                 [ ("A":|[], Amount.from_List [ Amount.usd $ 1 ])
                                                 , ("A":|["B"], Amount.from_List [ Amount.usd $ 1 ])
@@ -627,7 +655,7 @@ test_Hcompta =
                                                         })
                                                 ])
                                 , "A+$1 A/B+$1 A/B/C+$1 A/B/C/D+$1 = A+$4 A/B+$3 A/B/C+$2 A/B/C/D+$1" ~:
-                                        Calc.Balance.expand
+                                        Calc.Balance.expanded
                                                (Lib.TreeMap.from_List const
                                                 [ ("A":|[], Amount.from_List [ Amount.usd $ 1 ])
                                                 , ("A":|["B"], Amount.from_List [ Amount.usd $ 1 ])
@@ -654,7 +682,7 @@ test_Hcompta =
                                                         })
                                                 ])
                                 , "A+$1 A/B+$1 A/BB+$1 AA/B+$1 = A+$3 A/B+$1 A/BB+$1 AA+$1 AA/B+$1" ~:
-                                        Calc.Balance.expand
+                                        Calc.Balance.expanded
                                                (Lib.TreeMap.from_List const
                                                 [ ("A":|[], Amount.from_List [ Amount.usd $ 1 ])
                                                 , ("A":|["B"], Amount.from_List [ Amount.usd $ 1 ])
@@ -685,9 +713,9 @@ test_Hcompta =
                                                         })
                                                 ])
                                 ]
-                        , "equilibre" ~: TestList
+                        , "deviation" ~: TestList
                                 [ "{A+$1, $1}" ~:
-                                       (Calc.Balance.equilibre $
+                                       (Calc.Balance.deviation $
                                                Calc.Balance.Balance
                                                 { Calc.Balance.by_account =
                                                        Lib.TreeMap.from_List const
@@ -705,7 +733,7 @@ test_Hcompta =
                                                        ]
                                                 })
                                         ~?=
-                                        (Calc.Balance.Equilibre $
+                                        (Calc.Balance.Deviation $
                                                Data.Map.fromList $
                                                Data.List.map Calc.Balance.assoc_unit_sum $
                                                [ Calc.Balance.Unit_Sum
@@ -714,17 +742,48 @@ test_Hcompta =
                                                         ["B":|[]]
                                                 }
                                                ])
+                                , "{A+$1 B+$1, $2}" ~:
+                                       (Calc.Balance.deviation $
+                                               Calc.Balance.Balance
+                                                { Calc.Balance.by_account =
+                                                       Lib.TreeMap.from_List const
+                                                        [ ("A":|[], Amount.from_List [ Amount.usd $ 1 ])
+                                                        , ("B":|[], Amount.from_List [ Amount.usd $ 1 ])
+                                                        ]
+                                                , Calc.Balance.by_unit =
+                                                       Data.Map.fromList $
+                                                       Data.List.map Calc.Balance.assoc_unit_sum $
+                                                       [ Calc.Balance.Unit_Sum
+                                                        { Calc.Balance.amount = Amount.usd $ 2
+                                                        , Calc.Balance.accounts = Data.Map.fromList $ Data.List.map (,())
+                                                                [ "A":|[]
+                                                                , "B":|[]
+                                                                ]
+                                                        }
+                                                       ]
+                                                })
+                                        ~?=
+                                        (Calc.Balance.Deviation $
+                                               Data.Map.fromList $
+                                               Data.List.map Calc.Balance.assoc_unit_sum $
+                                               [ Calc.Balance.Unit_Sum
+                                                { Calc.Balance.amount = Amount.usd $ 2
+                                                , Calc.Balance.accounts = Data.Map.fromList $ Data.List.map (,())
+                                                        [
+                                                        ]
+                                                }
+                                               ])
                                 ]
-                        , "is_equilibrable" ~: TestList
+                        , "is_equilibrium_inferrable" ~: TestList
                                 [ "nil" ~: TestCase $
                                                (@=?) True $
-                                               Calc.Balance.is_equilibrable $
-                                               Calc.Balance.equilibre $
+                                               Calc.Balance.is_equilibrium_inferrable $
+                                               Calc.Balance.deviation $
                                                Calc.Balance.nil
                                 , "{A+$0, $+0}" ~: TestCase $
                                                (@=?) True $
-                                               Calc.Balance.is_equilibrable $
-                                               Calc.Balance.equilibre $
+                                               Calc.Balance.is_equilibrium_inferrable $
+                                               Calc.Balance.deviation $
                                                Calc.Balance.Balance
                                                 { Calc.Balance.by_account =
                                                        Lib.TreeMap.from_List const
@@ -742,8 +801,8 @@ test_Hcompta =
                                                 }
                                 , "{A+$1, $+1}" ~: TestCase $
                                                (@=?) False $
-                                               Calc.Balance.is_equilibrable $
-                                               Calc.Balance.equilibre $
+                                               Calc.Balance.is_equilibrium_inferrable $
+                                               Calc.Balance.deviation $
                                                Calc.Balance.Balance
                                                 { Calc.Balance.by_account =
                                                        Lib.TreeMap.from_List const
@@ -761,8 +820,8 @@ test_Hcompta =
                                                 }
                                 , "{A+$0+€0, $0 €+0}" ~: TestCase $
                                                (@=?) True $
-                                               Calc.Balance.is_equilibrable $
-                                               Calc.Balance.equilibre $
+                                               Calc.Balance.is_equilibrium_inferrable $
+                                               Calc.Balance.deviation $
                                                Calc.Balance.Balance
                                                 { Calc.Balance.by_account =
                                                        Lib.TreeMap.from_List const
@@ -785,8 +844,8 @@ test_Hcompta =
                                                 }
                                 , "{A+$1, B-$1, $+0}" ~: TestCase $
                                                (@=?) True $
-                                               Calc.Balance.is_equilibrable $
-                                               Calc.Balance.equilibre $
+                                               Calc.Balance.is_equilibrium_inferrable $
+                                               Calc.Balance.deviation $
                                                Calc.Balance.Balance
                                                 { Calc.Balance.by_account =
                                                        Lib.TreeMap.from_List const
@@ -805,8 +864,8 @@ test_Hcompta =
                                                 }
                                 , "{A+$1 B, $+1}" ~: TestCase $
                                                (@=?) True $
-                                               Calc.Balance.is_equilibrable $
-                                               Calc.Balance.equilibre $
+                                               Calc.Balance.is_equilibrium_inferrable $
+                                               Calc.Balance.deviation $
                                                 Calc.Balance.Balance
                                                         { Calc.Balance.by_account =
                                                                Lib.TreeMap.from_List const
@@ -825,8 +884,8 @@ test_Hcompta =
                                                         }
                                 , "{A+$1 B+€1, $+1 €+1}" ~: TestCase $
                                                (@=?) True $
-                                               Calc.Balance.is_equilibrable $
-                                               Calc.Balance.equilibre $
+                                               Calc.Balance.is_equilibrium_inferrable $
+                                               Calc.Balance.deviation $
                                                Calc.Balance.Balance
                                                 { Calc.Balance.by_account =
                                                        Lib.TreeMap.from_List const
@@ -850,8 +909,8 @@ test_Hcompta =
                                                 }
                                 , "{A+$1 B-$1+€1, $+0 €+1}" ~: TestCase $
                                                (@=?) True $
-                                               Calc.Balance.is_equilibrable $
-                                               Calc.Balance.equilibre $
+                                               Calc.Balance.is_equilibrium_inferrable $
+                                               Calc.Balance.deviation $
                                                Calc.Balance.Balance
                                                 { Calc.Balance.by_account =
                                                        Lib.TreeMap.from_List const
@@ -875,8 +934,8 @@ test_Hcompta =
                                                 }
                                 , "{A+$1+€2+£3 B-$1-€2-£3, $+0 €+0 £+0}" ~: TestCase $
                                                (@=?) True $
-                                               Calc.Balance.is_equilibrable $
-                                               Calc.Balance.equilibre $
+                                               Calc.Balance.is_equilibrium_inferrable $
+                                               Calc.Balance.deviation $
                                                Calc.Balance.Balance
                                                 { Calc.Balance.by_account =
                                                        Lib.TreeMap.from_List const
@@ -904,9 +963,9 @@ test_Hcompta =
                                                        ]
                                                 }
                                 ]
-                        , "infer_equilibre" ~: TestList
+                        , "infer_equilibrium" ~: TestList
                                 [ "{A+$1 B}" ~:
-                                        (Calc.Balance.infer_equilibre $
+                                        (snd $ Calc.Balance.infer_equilibrium $
                                                Posting.from_List
                                                 [ (Posting.nil ("A":|[]))
                                                         { Posting.amounts=Amount.from_List [ Amount.usd $ 1 ] }
@@ -922,7 +981,7 @@ test_Hcompta =
                                                         { Posting.amounts=Amount.from_List [ Amount.usd $ -1 ] }
                                                 ])
                                 , "{A+$1 B-1€}" ~:
-                                        (Calc.Balance.infer_equilibre $
+                                        (snd $ Calc.Balance.infer_equilibrium $
                                                Posting.from_List
                                                 [ (Posting.nil ("A":|[]))
                                                         { Posting.amounts=Amount.from_List [ Amount.usd $ 1 ] }
@@ -941,6 +1000,20 @@ test_Hcompta =
                                                 , (Posting.nil ("B":|[]))
                                                         { Posting.amounts=Amount.from_List [ Amount.eur $ -1 ] }
                                                 ])
+                                , "{A+$1 B+$1}" ~:
+                                        (snd $ Calc.Balance.infer_equilibrium $
+                                               Posting.from_List
+                                                [ (Posting.nil ("A":|[]))
+                                                        { Posting.amounts=Amount.from_List [ Amount.usd $ 1 ] }
+                                                , (Posting.nil ("B":|[]))
+                                                        { Posting.amounts=Amount.from_List [ Amount.usd $ 1 ] }
+                                                ])
+                                        ~?=
+                                        (Left
+                                                [ Calc.Balance.Unit_Sum
+                                                        { Calc.Balance.amount = Amount.usd $ 2
+                                                        , Calc.Balance.accounts = Data.Map.fromList []}
+                                                ])
                                 ]
                         ]
                 ]