forked from alexey-ernest/go-hft-orderbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
limitorder_test.go
60 lines (52 loc) · 1.18 KB
/
limitorder_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
package hftorderbook
import (
"math/rand"
"testing"
)
func TestLimitOrderEmpty(t *testing.T) {
price := 3.141593
l := NewLimitOrder(price)
if l.Price != price || l.TotalVolume() != 0.0 {
t.Errorf("limit order init error")
}
}
func TestLimitOrderAddOrder(t *testing.T) {
price := 3.141593
volume := 25.0
l := NewLimitOrder(price)
o := &Order{ Volume: volume }
l.Enqueue(o)
if l.TotalVolume() != volume {
t.Errorf("total volume counted incorrectly")
}
if l.Size() != 1 {
t.Errorf("it should have size = 1")
}
if o.Limit != &l {
t.Errorf("Parent Limit link should be set for an order")
}
}
func TestLimitOrderAddMultipleOrders(t *testing.T) {
price := 3.141593
volume := 0.0
l := NewLimitOrder(price)
n := 100
for i := 0; i < n; i += 1 {
o := &Order{ Id: i, Volume: rand.Float64() }
volume += o.Volume
l.Enqueue(o)
}
if volume != l.TotalVolume() {
t.Errorf("total volume calculated incorrectly")
}
if l.Size() != n {
t.Errorf("total count calculated incorrectly")
}
o := l.Dequeue()
if l.TotalVolume() != volume - o.Volume {
t.Errorf("total volume calculated incorrectly")
}
if l.Size() != n - 1 {
t.Errorf("total count calculated incorrectly")
}
}