test balances push

This commit is contained in:
Bel LaPointe
2023-10-25 07:16:42 -06:00
parent 29fec124af
commit a76e7b5546
4 changed files with 60 additions and 0 deletions

View File

@@ -9,6 +9,22 @@ type Balances map[string]Balance
type Balance map[Currency]float64
func (balances Balances) PushAll(other Balances) {
for k, v := range other {
if _, ok := balances[k]; !ok {
balances[k] = v
} else {
for k2, v2 := range v {
if _, ok := balances[k][k2]; !ok {
balances[k][k2] = v2
} else {
balances[k][k2] += v2
}
}
}
}
}
func (balances Balances) Push(d Delta) {
if _, ok := balances[d.Name]; !ok {
balances[d.Name] = make(Balance)