Passed
Push — master ( 2aae79...c84bae )
by Daniel
02:59
created

test_calculate.test_fail()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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