diff --git a/ledger/delta_test.go b/ledger/delta_test.go new file mode 100644 index 0000000..5804c0d --- /dev/null +++ b/ledger/delta_test.go @@ -0,0 +1,56 @@ +package ledger + +import ( + "testing" + "time" + + "github.com/howeyc/ledger" + "github.com/howeyc/ledger/decimal" +) + +func TestDelta(t *testing.T) { + d, err := time.Parse("2006-01-02", "2099-08-07") + if err != nil { + t.Fatal(err) + } + delta := newDelta(d, ledger.Account{ + Name: "name", + Balance: decimal.NewFromFloat(34.56), + Comment: "comment", + }) + + if delta.Date != d { + t.Error(delta.Date) + } + if delta.Account != "name" { + t.Error(delta.Account) + } + if delta.Value != 34.56 { + t.Error(delta.Value) + } + if delta.Currency != USD { + t.Error(delta.Currency) + } + t.Log(delta) + + d2, _ := time.Parse("2006-01-02", "2099-09-08") + delta2 := newDelta(d2, ledger.Account{ + Name: "name", + Balance: decimal.NewFromFloat(11.11), + Comment: "comment", + }) + + combined := delta.Plus(delta2) + if combined.Date != d2 { + t.Error(combined.Date) + } + if combined.Account != "name" { + t.Error(combined.Account) + } + if combined.Value != 45.67 { + t.Error(combined.Value) + } + if combined.Currency != USD { + t.Error(combined.Currency) + } +}