40 lines
1000 B
Go
40 lines
1000 B
Go
package ledger
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestRegisterPredictContribution(t *testing.T) {
|
|
// 1n t0 w weight 4
|
|
// 2n t1 w weight 2
|
|
// 4n t2 w weight 1
|
|
input := 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}},
|
|
}
|
|
// 1x4 weight 4 = 16
|
|
// 2x2 weight 2 = 8
|
|
// 4x1 weight 1 = 4
|
|
// (16+8+4) / (4+2+1) = 4
|
|
got, err := RegisterWithContributionPrediction(input, .12)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got) != len(input)+1 {
|
|
t.Error(len(got))
|
|
}
|
|
if balance, ok := got["2001-11"]; !ok {
|
|
t.Error(ok)
|
|
} else if balance["X"][USD] != 20.0 {
|
|
t.Error(balance)
|
|
}
|
|
}
|