-
Notifications
You must be signed in to change notification settings - Fork 1
/
db_test.go
100 lines (77 loc) · 2.58 KB
/
db_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
package kstreamdb
import (
"os"
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
var inTicks []TickData
var outTicks []TickData
// TestDB method to test the db
func TestDB(t *testing.T) {
db := SetupDatabase("")
t1 := TickData{
TradingSymbol: "TestSym",
IsTradable: true,
Timestamp: time.Now(),
LastTradeTime: time.Now(),
LastPrice: 100.0,
LastTradedQuantity: 5,
AverageTradePrice: 99.0,
VolumeTraded: 555,
TotalBuyQuantity: 500,
TotalSellQuantity: 300,
DayOpen: 98.0,
DayHighPrice: 103.0,
DayLowPrice: 94.0,
LastDayClose: 98.0,
OI: 0,
OIDayHigh: 10,
OIDayLow: 0,
Bid: [...]DepthItem{{Price: 99.9, Quantity: 100, Orders: 3}, {Price: 99.8, Quantity: 133, Orders: 2}, {Price: 99.7, Quantity: 100, Orders: 1}, {Price: 99.6, Quantity: 100, Orders: 3}, {Price: 99.9, Quantity: 1000, Orders: 3}},
Ask: [...]DepthItem{{Price: 100, Quantity: 100, Orders: 2}, {Price: 100.1, Quantity: 33, Orders: 2}, {Price: 100.2, Quantity: 10, Orders: 10}, {Price: 100.3, Quantity: 100, Orders: 3}, {Price: 100.4, Quantity: 1000, Orders: 1}},
}
t2 := TickData{
TradingSymbol: "TSYM",
IsTradable: true,
Timestamp: time.Now(),
LastTradeTime: time.Now(),
LastPrice: 1000.0,
LastTradedQuantity: 66,
AverageTradePrice: 999.0,
VolumeTraded: 555,
TotalBuyQuantity: 500,
TotalSellQuantity: 300,
DayOpen: 98.0,
DayHighPrice: 103.0,
DayLowPrice: 94.0,
LastDayClose: 98.0,
OI: 0,
OIDayHigh: 10,
OIDayLow: 0,
Bid: [...]DepthItem{{Price: 999.9, Quantity: 500, Orders: 3}, {Price: 999.8, Quantity: 133, Orders: 2}, {Price: 999.7, Quantity: 600, Orders: 1}, {Price: 999.6, Quantity: 44, Orders: 3}, {Price: 999.9, Quantity: 80, Orders: 3}},
Ask: [...]DepthItem{{Price: 1000, Quantity: 1000, Orders: 2}, {Price: 1000.1, Quantity: 33, Orders: 2}, {Price: 1000.2, Quantity: 10, Orders: 10}, {Price: 1000.3, Quantity: 1000, Orders: 3}, {Price: 1000.4, Quantity: 10, Orders: 1}},
}
inTicks = make([]TickData, 0)
outTicks = make([]TickData, 0)
inTicks = append(inTicks, t1)
inTicks = append(inTicks, t2)
//t.Logf("Inserting, %+v", inTicks)
db.Insert(inTicks)
db.PlaybackAll(func(t TickData) {
outTicks = append(outTicks, t)
})
//t.Logf("Readback, %+v", outTicks)
if !cmp.Equal(inTicks, outTicks) {
t.Error("DB Insert and Playback Failed")
} else {
t.Log("Insert/Playback is successful")
}
outAllTicks, err := db.LoadAllData()
if (err != nil) || !cmp.Equal(inTicks, outAllTicks) {
t.Error("DB Load Failed")
} else {
t.Log("Load is successful")
}
os.RemoveAll(db.DataPath)
}