Test Failed
Push — master ( ad1939...c48554 )
by Austin
01:48
created

test_apoor.test_ibuff()   A

Complexity

Conditions 3

Size

Total Lines 9
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 9
rs 9.95
c 0
b 0
f 0
cc 3
nop 0
1
2
import apoor
3
import pytest
4
5
6
def test_make_scale():
7
    assert apoor.make_scale(0,1,0,10)(0.1) == 1
8
    assert apoor.make_scale(10,0,0,1)(9) == 0.1
9
    assert apoor.make_scale(0,1,0,1,True)(-1) == 0
10
    assert apoor.make_scale(0,1,0,10,True)(11) == 10
11
12
def test_set_seed():
13
    np = apoor.np
14
    n = 0
15
    apoor.set_seed(n)
16
    a = np.random.random()
17
    assert a != np.random.random() or a != np.random.random()
18
    apoor.set_seed(n)
19
    b = np.random.random()
20
    assert a == b
21
22
23
def test_train_test_split():
24
    # Getting started
25
    np = apoor.np
26
    x = np.arange(10)
27
    y = x[::-1]
28
    z = np.arange(0,20,2)
29
    ### Test 1 ###
30
    x_train = np.array([2,8,4,9,1,6,7,3,0])
31
    x_test  = np.array([5])
32
    apoor.set_seed(0)
33
    result = apoor.train_test_split(x)
34
    assert (
35
        (result[0] == x_train).all() and 
36
        (result[1] == x_test).all()
37
    )
38
    ### Test 2 ###
39
    y_train = np.array([7,1,5,0,8,3,2,6,9])
40
    y_test  = np.array([4])
41
    apoor.set_seed(0)
42
    result = apoor.train_test_split(x,y)
43
    assert (
44
        (result[0] == x_train).all() and 
45
        (result[1] == x_test ).all() and 
46
        (result[2] == y_train).all() and 
47
        (result[3] == y_test ).all()
48
    )
49
    ### Test 3 ###
50
    z_train = np.array([4,16,8,18,2,12,14,6,0])
51
    z_test  = np.array([10])
52
    apoor.set_seed(0)
53
    result = apoor.train_test_split(x,y,z)
54
    assert (
55
        (result[0] == x_train).all() and 
56
        (result[1] == x_test ).all() and 
57
        (result[2] == y_train).all() and 
58
        (result[3] == y_test ).all() and
59
        (result[4] == z_train).all() and 
60
        (result[5] == z_test ).all() 
61
    )
62
63
def test_ibuff():
64
    assert list(apoor.ibuff(range(10))) == \
65
        [[i] for i in range(10)]
66
    assert list(apoor.ibuff(range(10),2)) == \
67
        [[i,i+1] for i in range(0,10,2)]
68
    with pytest.raises(TypeError) as e_info:
69
        apoor.ibuff(range(10),1.0)    
70
    with pytest.raises(ValueError) as e_info:
71
        apoor.ibuff(range(10),0)    
72
73
74
75