-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrades_test.go
43 lines (36 loc) · 1.54 KB
/
trades_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
package main
import (
"encoding/json"
"fmt"
"testing"
"time"
)
func TestTradesToJSON(t *testing.T) {
trades := NewTrades()
var entries []Entry = []Entry{{"2001/01/01", "instr", "instrlong", "possession", "violation", "reason", "change", "volume", time.Now().Unix()}}
trades.NewEntries(entries)
js, err := json.Marshal(*trades.GetTradesSince(0))
if err != nil {
t.Fatal(err)
}
fmt.Println(string(js))
}
func TestMergeEntries(t *testing.T) {
e1 := Entry{"2001/01/01", "instr", "instrlong", "possession", "violation", "reason", "change", "volume", time.Now().Unix()}
e2 := Entry{"2001/01/01", "instr", "instrlong", "possession", "violation", "reason", "change", "volume", time.Now().Unix()}
e3 := Entry{"2001/01/02", "instr", "instrlong", "possession", "violation", "reason", "change", "volume", time.Now().Unix()}
e4 := Entry{"2001/01/03", "instr", "instrlong", "possession", "violation", "reason", "change", "volume", time.Now().Unix()}
if !e1.Equal(e2) {
t.Fail()
}
var entries []Entry = []Entry{e2, e3, e4}
e5 := Entry{"2001/01/01", "instr2", "instrlong", "possession", "violation", "reason", "change", "volume", time.Now().Unix()}
e6 := Entry{"2001/01/01", "instr3", "instrlong", "possession", "violation", "reason", "change", "volume", time.Now().Unix()}
e7 := Entry{"2001/01/01", "instr", "instrlong", "possession", "violation", "reason", "change", "volume", time.Now().Unix()}
var updated []Entry = []Entry{e5, e6, e7}
out, num := MergeEntries(entries, updated)
fmt.Println(len(out), num)
if len(out) != 5 || num != 2 {
t.Fail()
}
}