tdd les go

main
Bel LaPointe 2023-10-24 05:51:46 -06:00
parent 703b7b632d
commit 79effffc47
3 changed files with 31 additions and 17 deletions

View File

@ -6,21 +6,11 @@ import (
) )
func TestFileDeltas(t *testing.T) { func TestFileDeltas(t *testing.T) {
f, err := NewFile("./testdata/happy.dat")
if err != nil {
t.Fatal(err)
}
deltas, err := f.Deltas()
if err != nil {
t.Fatal(err)
}
d := func(s string) time.Time { d := func(s string) time.Time {
v, _ := time.Parse("2006-01-02", s) v, _ := time.Parse("2006-01-02", s)
return v return v
} }
want := []Delta{ happy := []Delta{
{ {
Date: d("2022-12-12"), Date: d("2022-12-12"),
Account: "AssetAccount:Cash:Fidelity76", Account: "AssetAccount:Cash:Fidelity76",
@ -47,12 +37,33 @@ func TestFileDeltas(t *testing.T) {
}, },
} }
if len(deltas) != len(want) { cases := map[string][]Delta{
t.Error(len(deltas)) "empty": nil,
"one": happy[:2],
"happy": happy[:],
} }
for i := range want {
if want[i] != deltas[i] { for name, d := range cases {
t.Errorf("[%d] \n\twant=%+v, \n\t got=%+v", i, want[i], deltas[i]) want := d
} t.Run(name, func(t *testing.T) {
f, err := NewFile("./testdata/" + name + ".dat")
if err != nil {
t.Fatal(err)
}
deltas, err := f.Deltas()
if err != nil {
t.Fatal(err)
}
if len(deltas) != len(want) {
t.Error(len(deltas))
}
for i := range want {
if want[i] != deltas[i] {
t.Errorf("[%d] \n\twant=%+v, \n\t got=%+v", i, want[i], deltas[i])
}
}
})
} }
} }

0
ledger/testdata/empty.dat vendored Normal file
View File

3
ledger/testdata/one.dat vendored Normal file
View File

@ -0,0 +1,3 @@
2022-12-12 Electricity / Power Bill TG2PJ-2PLP5 OK
AssetAccount:Cash:Fidelity76 $-97.92
Withdrawal:0:SharedHome:DominionEnergy