Passed
Push — master ( d05325...baece5 )
by Daniel
03:54
created

test_utils.test_diameter()   A

Complexity

Conditions 3

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 10
rs 9.95
c 0
b 0
f 0
cc 3
nop 0
1
import pytest
2
import amd
3
import numpy as np
4
5
6
def test_diameter():
7
8
    hex_cell = np.identity(3)
9
    hex_cell[1, 0] = -0.5
10
    hex_cell[1, 1] = np.sin(np.deg2rad(120.0))
11
    cells_and_diams = [(np.identity(3), np.sqrt(3)), (hex_cell, 2)]
12
    for cell, diam in cells_and_diams:
13
        d = amd.diameter(cell)
14
        if not np.abs(d - diam) < 1e-15:
15
            pytest.fail(f'amd.diameter() of {cell} should be {diam}, got {d}')
16
17
18
def test_cellpar_to_cell():
19
20
    hex_cellpar = np.array([1.0, 1.0, 1.0, 90.0, 90.0, 120.0])
21
    hex_cell = np.identity(3)
22
    hex_cell[1, 0] = -0.5
23
    hex_cell[1, 1] = np.sin(np.deg2rad(120.0))
24
    
25
    cellpar_2 = np.array([1.0, 2.0, 3.0, 60.0, 90.0, 120.0])
26
    cell_2 = np.identity(3)
27
    cell_2[1, 0] = -1
28
    cell_2[1, 1] = 2 * np.sin(np.deg2rad(cellpar_2[5]))
29
    cy = 0.5 / np.sin(np.deg2rad(120))
30
    cell_2[2, 1] = 3 * cy
31
    cell_2[2, 2] = 3 * np.sqrt(1.0 - cy ** 2)
32
    cellpars_and_cells = [(hex_cellpar, hex_cell), (cellpar_2, cell_2)]
33
34
    for cellpar, cell in cellpars_and_cells:
35
        cell_ = amd.cellpar_to_cell(cellpar)
36
        if not np.allclose(cell, cell_):
37
            pytest.fail(
38
            f'amd.cellpar_to_cell() of {cellpar} should be {hex_cell}, got '
39
            f'{cell}'
40
        )
41