-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
64 lines (53 loc) · 1.82 KB
/
tests.py
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
import indicators, json
def isclose(a, b, rel_tol=1e-08, abs_tol=0.0):
return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
intervalSecs = 3600*4
data = json.load(open("test_data.json"))
testCandles = list(reversed(data[0]))
result = indicators.sma(testCandles, 3600, 5)
answer = 166.554
if isclose(result, answer):
print("sma test0 passed")
else:
print("sma test0 failed. was %f; expected %f" % (result, answer))
result = indicators.sma(testCandles, 4*3600, 2)
answer = 172.64
if isclose(result, answer):
print("sma test1 passed")
else:
print("sma test1 failed. was %f; expected %f" % (result, answer))
testCandles = list(reversed(data[1]))
result = indicators.sma(testCandles, 3600, 4)
answer = 176.05
if isclose(result, answer):
print("sma test2 passed")
else:
print("sma test2 failed. was %f; expected %f" % (result, answer))
testCandles = list(reversed(data[2]))
answer = 179.189375
result = indicators.wma(4.0, testCandles, 3600, 10)
if isclose(result, answer):
print("wma test0 passed")
else:
print("wma test0 failed. was %f; expected %f" % (result, answer))
testCandles = list(reversed(data[3]))
answer = 181.833333
result = indicators.wma(5.0, testCandles, 2*3600, 8)
if isclose(result, answer):
print("wma test1 passed")
else:
print("wma test1 failed. was %f; expected %f" % (result, answer))
testCandles = list(reversed(data[0]))
answer = 170.85722222222222
result = indicators.wma(-8.0, testCandles, 3600, 8)
if isclose(result, answer):
print("wma test2 passed")
else:
print("wma test2 failed. was %f; expected %f" % (result, answer))
testCandles = list(reversed(data[0]))
answer = 166.877778
result = indicators.wma(8.0, testCandles, 3600, 8)
if isclose(result, answer):
print("wma test3 passed")
else:
print("wma test3 failed. was %f; expected %f" % (result, answer))