This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 261
/
sellSideStrategy_test.go
112 lines (105 loc) · 2.72 KB
/
sellSideStrategy_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package plugins
import (
"fmt"
"testing"
hProtocol "github.com/stellar/go/protocols/horizon"
"github.com/stellar/kelp/api"
"github.com/stellar/kelp/model"
"github.com/stretchr/testify/assert"
)
func TestComputeOffersToPrune(t *testing.T) {
testCases := []struct {
offerPrices []float64
levelPrices []float64
want []bool
}{
{
offerPrices: []float64{},
levelPrices: []float64{},
want: []bool{},
}, {
offerPrices: []float64{},
levelPrices: []float64{1.0},
want: []bool{},
}, {
offerPrices: []float64{1.0},
levelPrices: []float64{1.0},
want: []bool{false},
}, {
offerPrices: []float64{1.0},
levelPrices: []float64{1.0, 1.2},
want: []bool{false},
}, {
offerPrices: []float64{0.9},
levelPrices: []float64{1.0, 1.2},
want: []bool{false},
}, {
offerPrices: []float64{1.0, 1.2},
levelPrices: []float64{1.0},
want: []bool{false, true},
}, {
offerPrices: []float64{0.9, 1.0},
levelPrices: []float64{1.0},
want: []bool{true, false},
}, {
offerPrices: []float64{10.0, 11.0},
levelPrices: []float64{1.0},
want: []bool{false, true},
}, {
offerPrices: []float64{0.9, 1.2},
levelPrices: []float64{1.0},
want: []bool{true, false},
}, {
offerPrices: []float64{1.0, 1.0},
levelPrices: []float64{1.0},
want: []bool{false, true},
}, {
offerPrices: []float64{1.0, 1.0, 1.2},
levelPrices: []float64{1.0},
want: []bool{false, true, true},
}, {
offerPrices: []float64{1.0, 1.0},
levelPrices: []float64{1.0, 1.0},
want: []bool{false, false},
}, {
offerPrices: []float64{1.0, 1.2},
levelPrices: []float64{1.0, 1.2},
want: []bool{false, false},
}, {
offerPrices: []float64{1.0},
levelPrices: []float64{1.0, 1.0},
want: []bool{false},
}, {
offerPrices: []float64{1.0},
levelPrices: []float64{1.0, 1.2},
want: []bool{false},
},
}
for i, kase := range testCases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
if !assert.Equal(t, len(kase.want), len(kase.offerPrices), "invalid test case") {
return
}
offers := []hProtocol.Offer{}
for _, p := range kase.offerPrices {
num, den, e := model.NumberFromFloat(p, 8).AsRatio()
if !assert.NoError(t, e) {
return
}
offer := hProtocol.Offer{}
offer.PriceR.N = num
offer.PriceR.D = den
offers = append(offers, offer)
}
levels := []api.Level{}
for _, p := range kase.levelPrices {
levels = append(levels, api.Level{
Price: *model.NumberFromFloat(p, 8),
Amount: *model.NumberFromFloat(1, 8),
})
}
result := computeOffersToPrune(offers, levels)
assert.Equal(t, kase.want, result)
})
}
}