Test Failed
Push — master ( 3f43e4...2aae79 )
by Daniel
02:48
created

test_calculate.test_AMD()   A

Complexity

Conditions 4

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 4
nop 1
1
import numpy as np
2
import pytest
3
import amd
4
5
6
def test_fail():
7
    pytest.fail('I failed!')
8
9
10
def test_AMD(reference_data):
11
    for name in reference_data:
12
        for s in reference_data[name]:
13
            calc_amd = amd.AMD(s, 100)
14
            if not np.allclose(calc_amd, s.amd):
15
                pytest.fail(f'AMD of structure {s.name} disagrees with reference.\n' + \
16
                            'reference: ' + str(s.amd) + '\ncalculated: ' + str(calc_amd))
17
18
19
def test_PDD(reference_data):
20
    for name in reference_data:
21
        for s in reference_data[name]:
22
            calc_pdd = amd.PDD(s, 100)
23
            if not np.allclose(calc_pdd, s.pdd):
24
                abs_diffs = np.abs(calc_pdd - s.pdd)
25
                print(abs_diffs, np.amax(abs_diffs))
26
                pytest.fail(f'PDD of structure {s.name} disagrees with reference.\n' + \
27
                            'reference: ' + str(s.pdd) + '\ncalculated: ' + str(calc_pdd) + \
28
                            'diffs' + str(np.sort(abs_diffs.flatten())[::-1][:10]))
29
30
31
def test_PDD_to_AMD(reference_data):
32
    for name in reference_data:
33
        for s in reference_data[name]:
34
            calc_pdd = amd.PDD(s, 100)
35
            calc_amd = amd.AMD(s, 100)
36
            amd_from_pdd = amd.PDD_to_AMD(calc_pdd)
37
            if not np.allclose(calc_amd, amd_from_pdd):
38
                pytest.fail(f'Directly calculated AMD of structure {s.name} disagrees with ' + \
39
                            'AMD calculated from PDD.\n')
40
41
42
def test_AMD_finite():
43
    trapezium = np.array([[0,0],[1,1],[3,1],[4,0]])
44
    kite = np.array([[0,0],[1,1],[1,-1],[4,0]])
45
    trap_amd = amd.AMD_finite(trapezium)
46
    kite_amd = amd.AMD_finite(kite)
47
    dist = np.linalg.norm(trap_amd - kite_amd)
48
    if not abs(dist - 0.6180339887498952) < 1e-16:
49
        pytest.fail(f'AMDs of finite sets trapezium and kite are different than expected.\n')
50
51
52
def test_PDD_finite():
53
    trapezium = np.array([[0,0],[1,1],[3,1],[4,0]])
54
    kite = np.array([[0,0],[1,1],[1,-1],[4,0]])
55
    trap_pdd = amd.PDD_finite(trapezium)
56
    kite_pdd = amd.PDD_finite(kite)
57
    dist = amd.EMD(trap_pdd, kite_pdd)
58
    if not abs(dist - 0.874032) < 1e-8:
59
        pytest.fail(f'PDDs of finite sets trapezium and kite are different than expected.\n')
60