test balances push, pushall
This commit is contained in:
@@ -16,4 +16,39 @@ func TestBalances(t *testing.T) {
|
||||
t.Error(ba["z"])
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("pushall", func(t *testing.T) {
|
||||
a := make(Balances)
|
||||
a.Push(Delta{Name: "a", Currency: USD, Value: 0.1})
|
||||
a.Push(Delta{Name: "ab", Currency: USD, Value: 1.2})
|
||||
|
||||
b := make(Balances)
|
||||
b.Push(Delta{Name: "b", Currency: USD, Value: 2.3})
|
||||
b.Push(Delta{Name: "ab", Currency: USD, Value: 3.4})
|
||||
|
||||
b.PushAll(a)
|
||||
|
||||
if len(a) != 2 {
|
||||
t.Error("modified original", len(a), a)
|
||||
}
|
||||
if a["a"][USD] != 0.1 {
|
||||
t.Error("modified original a", a["a"])
|
||||
}
|
||||
if a["ab"][USD] != 1.2 {
|
||||
t.Error("modified original ab", a["ab"])
|
||||
}
|
||||
|
||||
if len(b) != 3 {
|
||||
t.Error("didnt union names", len(b), b)
|
||||
}
|
||||
if b["a"][USD] != 0.1 {
|
||||
t.Error("didnt pull other unique", b["a"])
|
||||
}
|
||||
if b["b"][USD] != 2.3 {
|
||||
t.Error("didnt retain unique", b["b"])
|
||||
}
|
||||
if b["ab"][USD] != 4.6 {
|
||||
t.Error("didnt sum other", b["ab"])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user