-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
140 lines (124 loc) · 2.85 KB
/
main_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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"errors"
"fmt"
"math"
"sync"
"testing"
"time"
"github.com/agux/pachon/conf"
"github.com/agux/pachon/global"
"github.com/agux/pachon/model"
"github.com/mjanda/go-dtw"
"github.com/shirou/gopsutil/cpu"
"github.com/ssgreg/repeat"
)
func TestCpu(t *testing.T) {
for x := 0; x < 10; x++ {
s, e := cpu.Percent(0, false)
if e != nil {
panic(e)
}
for _, i := range s {
log.Printf("%+v", i)
}
time.Sleep(time.Second * 2)
}
}
func TestChannel(t *testing.T) {
rc := make(chan int, 5)
rl := make([]int, 0, 16)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
for i := range rc {
time.Sleep(time.Millisecond * 120)
rl = append(rl, i)
}
}()
for i := 0; i < 300; i++ {
rc <- i
}
close(rc)
wg.Wait()
fmt.Printf("size: %d", len(rl))
}
// func TestBlue(t *testing.T) {
// blue()
// }
func TestDTW(t *testing.T) {
// prepare arrays
a := []float64{1, 1, 1, 2, 2, 2, 3, 3, 3, 2, 2, 4, 4, 4, 4}
//b := []float64{1, 1, 2, 2, 3, 3, 2, 4, 4, 4}
c := []float64{7, 9, 3, 1, 10, 20, 30, 3, 4, 6}
dtw := dtw.Dtw{}
// optionally set your own distance function
dtw.DistanceFunction = func(x float64, y float64) float64 {
difference := x - y
return math.Sqrt(difference * difference)
}
dtw.ComputeOptimalPathWithWindow(a, c, 5) // 5 = window size
path := dtw.RetrieveOptimalPath()
log.Printf("Optimal Path: %+v", path)
}
func TestISOWeek(t *testing.T) {
tToday, _ := time.Parse(global.DateFormat, "2017-09-04")
y, w := tToday.ISOWeek()
fmt.Println(y, w)
tToday, _ = time.Parse(global.DateFormat, "2017-09-05")
y, w = tToday.ISOWeek()
fmt.Println(y, w)
}
func TestNilSlice(t *testing.T) {
s := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
s1 := s[5:7]
s[5] = 99
s[6] = 144
s = nil
fmt.Println(s1)
}
func TestMap(t *testing.T) {
m := make(map[int]byte)
modMap(m)
log.Debugf("the map: %+v", m)
}
func modMap(m map[int]byte) {
m[1] = 0
m[2] = 0
m[3] = 0
}
func TestNilPointer(t *testing.T) {
var s []*model.TradeDataBasic
log.Printf("len: %d", len(s))
t.Fail()
}
func TestMapNil(t *testing.T) {
m := map[string]interface{}{
"a": nil,
"b": 0,
}
if x, ok := m["a"]; ok {
log.Debugf("map to nil is ok: %+v", x)
}
}
func TestRepeat(t *testing.T) {
op := func(c int) error {
log.Debugf("retrying: %d", c+1)
return repeat.HintTemporary(errors.New("dumb error"))
}
repeat.Repeat(
repeat.FnWithCounter(op),
repeat.StopOnSuccess(),
repeat.LimitMaxTries(conf.Args.DefaultRetry),
repeat.WithDelay(
repeat.FullJitterBackoff(500*time.Millisecond).WithMaxDelay(10*time.Second).Set(),
),
)
}
func TestUnixTime(t *testing.T) {
log.Debugf("time.Now().Unix(): %+v", time.Now().Unix())
log.Debugf("time.Now().Local().Unix(): %+v", time.Now().Local().Unix())
log.Debugf("time.Now().UnixNano(): %+v", time.Now().UnixNano())
log.Debugf("time.Now().Local().UnixNano(): %+v", time.Now().Local().UnixNano())
}