-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathorderqueue_test.go
66 lines (52 loc) · 1.14 KB
/
orderqueue_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
package orderbook
import (
"testing"
decimal "github.com/geseq/udecimal"
)
func TestOrderQueue(t *testing.T) {
price := decimal.New(100, 0)
oq := newOrderQueue(price)
o1 := NewOrder(
1,
Limit,
Buy,
decimal.New(100, 0),
decimal.New(100, 0),
decimal.Zero,
None,
)
o2 := NewOrder(
2,
Limit,
Buy,
decimal.New(100, 0),
decimal.New(100, 0),
decimal.Zero,
None,
)
head := oq.Append(o1)
tail := oq.Append(o2)
if head == nil || tail == nil {
t.Fatal("Could not append order to the OrderQueue")
}
if !oq.TotalQty().Equal(decimal.New(200, 0)) {
t.Fatalf("Invalid order volume (have: %s, want: 200", oq.TotalQty())
}
if head != o1 || tail != o2 {
t.Fatal("Invalid element value")
}
if oq.head != head || oq.tail != tail {
t.Fatal("Invalid element position")
}
if oq.head.next != oq.tail || oq.tail.prev != head ||
oq.head.prev != nil || oq.tail.next != nil {
t.Fatal("Invalid element link")
}
if o := oq.Remove(head); o != o1 {
t.Fatal("Invalid element value")
}
if !oq.TotalQty().Equal(decimal.New(100, 0)) {
t.Fatalf("Invalid order volume (have: %s, want: 100", oq.TotalQty())
}
t.Log(oq)
}