forked from robertmartin8/MachineLearningStocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
45 lines (39 loc) · 1.68 KB
/
test_utils.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
import pytest
import utils
def test_status_calc():
"""
Test the status_calc function which generates training labels
"""
assert utils.status_calc(50, 20, 12.2) == 1
assert utils.status_calc(12.003, 10, 15) == 0
assert utils.status_calc(-10, -30, 5) == 1
assert utils.status_calc(-31, -30, 15) == 0
assert utils.status_calc(15, 5, 10) == 1
with pytest.raises(ValueError):
utils.status_calc(12, 10, -3)
def test_data_string_to_float():
"""
data_string_to_float() is a function that needs to meet lots of empirical requirements
owing to the idiosyncrasies of Yahoo Finance's HTML. The main jobs are parsing negatives and
abbreviations of big numbers.
"""
assert utils.data_string_to_float("asdfNaN") == "N/A"
assert utils.data_string_to_float(">N/A\n</") == "N/A"
assert utils.data_string_to_float(">0") == 0
assert utils.data_string_to_float("-3") == -3
assert utils.data_string_to_float("4K") == 4000
assert utils.data_string_to_float("2M") == 2000000
assert utils.data_string_to_float("0.07B") == 70000000
assert utils.data_string_to_float("-100.1K") == -100100
assert utils.data_string_to_float("-0.1M") == -100000
assert utils.data_string_to_float("-0.02B") == -20000000
assert utils.data_string_to_float("-0.00") == 0
assert utils.data_string_to_float("0.00") == 0
assert utils.data_string_to_float("0M") == 0
assert utils.data_string_to_float("010K") == 10000
with pytest.raises(ValueError):
utils.data_string_to_float(">0x")
with pytest.raises(ValueError):
utils.data_string_to_float("10k")
with pytest.raises(ValueError):
utils.data_string_to_float("2KB")