-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticker_test.go
112 lines (86 loc) · 2.49 KB
/
ticker_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
package main
import (
"testing"
"time"
v2 "github.com/alpacahq/alpaca-trade-api-go/v2"
"github.com/vartanbeno/go-reddit/v2/reddit"
)
var testPost1 = &reddit.Post{
ID: "i2gvs1",
FullID: "t3_i2gvs1",
Created: &reddit.Timestamp{time.Date(2020, 8, 2, 18, 23, 37, 0, time.UTC)},
Edited: &reddit.Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
Permalink: "/r/test/comments/i2gvs1/this_is_a_title/",
URL: "http://example.com",
Title: "This is a title",
Likes: reddit.Bool(true),
Score: 1,
UpvoteRatio: 1,
NumberOfComments: 0,
SubredditName: "test",
SubredditNamePrefixed: "r/test",
SubredditID: "t5_2qh23",
SubredditSubscribers: 8278,
Author: "v_95",
AuthorID: "t2_164ab8",
}
var testPost2 = &reddit.Post{
ID: "i2gvs1",
FullID: "t3_i2gvs1",
Created: &reddit.Timestamp{time.Date(2020, 8, 2, 18, 23, 37, 0, time.UTC)},
Edited: &reddit.Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
Permalink: "/r/test/comments/i2gvs1/this_is_a_title/",
URL: "http://example.com",
Title: "TEST is the best company ever!!!1!",
Likes: reddit.Bool(true),
Score: 1,
UpvoteRatio: 1,
NumberOfComments: 0,
SubredditName: "test",
SubredditNamePrefixed: "r/test",
SubredditID: "t5_2qh23",
SubredditSubscribers: 8278,
Author: "v_95",
AuthorID: "t2_164ab8",
}
var testBar1 = v2.Bar{
Open: 100.00,
High: 100.00,
Low: 10.00,
Close: 50.00,
Volume: 1000,
Timestamp: time.Date(2020, 8, 2, 18, 23, 37, 0, time.UTC),
}
var testBar2 = v2.Bar{
Open: 200.00,
High: 200.00,
Low: 100.00,
Close: 150.00,
Volume: 11000,
Timestamp: time.Date(2020, 8, 2, 19, 23, 37, 0, time.UTC),
}
func TestCheckMentionsReturnsValues(t *testing.T) {
var testPosts []*reddit.Post
testPosts = append(testPosts, testPost1, testPost2)
result := checkMentions(testPosts, "TEST")
if result == nil {
t.Fatalf(`checkMentions(testPosts, "TEST") = %q`, result)
}
}
func TestCheckMentionsReturnsEmpty(t *testing.T) {
var testPosts []*reddit.Post
testPosts = append(testPosts, testPost1, testPost2)
result := checkMentions(testPosts, "NONE")
if result != nil {
t.Fatalf(`checkMentions(testPosts, "NONE") = %q`, result)
}
}
func TestPriceMovement(t *testing.T) {
var testBars []v2.Bar
testBars = append(testBars, testBar1, testBar2)
expected := 50.00
result := priceMovement(testBars, "TEST")
if result != expected {
t.Fatalf("Expected %f, got %f", expected, result)
}
}