package ledger import ( "slices" "testing" "time" ) func TestRegisterPrediction(t *testing.T) { t.Run("contribution", func(t *testing.T) { input := newTestRegister() got, err := RegisterWithContributionPrediction(input, time.Hour*24*365) if err != nil { t.Fatal(err) } t.Logf("%+v", got) if len(got) != len(input)+1 { t.Error(len(got)) } if _, ok := got["2001-11"]; !ok { t.Error(ok) } t.Error("not impl") }) t.Run("compounding interest", func(t *testing.T) { input := newTestRegister() got, err := RegisterWithCompoundingInterestPrediction(input, time.Hour*24*365, "X", .04) if err != nil { t.Fatal(err) } t.Logf("%+v", got) if len(got) <= len(input) { t.Error(len(got)) } for _, date := range got.Dates() { for name, balance := range got[date] { t.Logf("%s | %s %s", date, name, balance.Debug()) } } }) } func TestBPIPrediction(t *testing.T) { t.Run("fixed growth", func(t *testing.T) { bpis := BPIs{ USD: BPI{ "2001-01": -1000, "2001-02": 100, }, } got, err := BPIsWithFixedGrowthPrediction(bpis, time.Hour*24*365, string(USD), 0.06) if err != nil { t.Fatal(err) } dates := []string{} for d := range got[USD] { dates = append(dates, d) } slices.Sort(dates) for _, d := range dates { t.Logf("%s | %s %.2f", USD, d, got[USD][d]) } }) } func newTestRegister() map[string]Balances { return map[string]Balances{ "2001-01": Balances{"X": Balance{USD: 1}}, "2001-02": Balances{"X": Balance{USD: 2}}, "2001-03": Balances{"X": Balance{USD: 3}}, "2001-04": Balances{"X": Balance{USD: 4}}, "2001-05": Balances{"X": Balance{USD: 5}}, "2001-06": Balances{"X": Balance{USD: 6}}, "2001-07": Balances{"X": Balance{USD: 8}}, "2001-08": Balances{"X": Balance{USD: 10}}, "2001-09": Balances{"X": Balance{USD: 12}}, "2001-10": Balances{"X": Balance{USD: 16}}, } }