test delta
This commit is contained in:
56
ledger/delta_test.go
Normal file
56
ledger/delta_test.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user