Files
ana-ledger/ledger/deltas_test.go
2023-10-25 08:06:41 -06:00

42 lines
817 B
Go

package ledger
import "testing"
func TestDeltas(t *testing.T) {
t.Run("balances", func(t *testing.T) {
deltas := Deltas{
{Name: "a", Value: 0},
{Name: "b", Value: 1},
{Name: "b", Value: -.999999999999999999999999},
{Name: "b", Value: 1.3},
}
balances := deltas.Balances()
if len(balances) != 1 {
t.Error(len(balances), balances)
}
if balances["b"][""] != 1.3 {
t.Error(balances["b"])
}
})
t.Run("register", func(t *testing.T) {
deltas := Deltas{
{Date: "a", Value: 0.1},
{Date: "a", Value: 2.2},
{Date: "b", Value: 4.3},
}
got := deltas.Register()
t.Logf("%+v", got)
if len(got) != 2 {
t.Error(len(got))
}
if int(10*got["a"][""][""]) != 23 {
t.Error(got["a"][""][""])
}
if int(10*got["b"][""][""]) != 66 {
t.Error(got["b"][""][""])
}
})
}