forked from i25959341/orderbook
-
Notifications
You must be signed in to change notification settings - Fork 2
/
order_test.go
35 lines (27 loc) · 879 Bytes
/
order_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
package orderbook
import (
"encoding/json"
"testing"
"time"
"github.com/shopspring/decimal"
)
func TestNewOrder(t *testing.T) {
t.Log(NewOrder("order-1", Sell, decimal.New(100, 0), decimal.New(100, 0), time.Now().UTC()))
}
func TestOrderJSON(t *testing.T) {
data := []*Order{
NewOrder("one", Buy, decimal.New(11, -1), decimal.New(11, 1), time.Now().UTC()),
NewOrder("two", Buy, decimal.New(22, -1), decimal.New(22, 1), time.Now().UTC()),
NewOrder("three", Sell, decimal.New(33, -1), decimal.New(33, 1), time.Now().UTC()),
NewOrder("four", Sell, decimal.New(44, -1), decimal.New(44, 1), time.Now().UTC()),
}
result, _ := json.Marshal(data)
t.Log(string(result))
data = []*Order{}
_ = json.Unmarshal(result, &data)
t.Log(data)
err := json.Unmarshal([]byte(`[{"side":"fake"}]`), &data)
if err == nil {
t.Fatal("can unmarshal unsupported value")
}
}