test_utils   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 32
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A test_diameter() 0 10 3
A test_cellpar_to_cell() 0 20 3
1
import pytest
2
import amd
3
import numpy as np
4
5
6
def test_diameter():
7
    hex_cell = np.identity(3)
8
    hex_cell[1, 0] = -0.5
9
    hex_cell[1, 1] = np.sin(np.deg2rad(120.0))
10
    cells_and_diams = [(np.identity(3), np.sqrt(3)), (hex_cell, 2)]
11
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
    hex_cellpar = np.array([1.0, 1.0, 1.0, 90.0, 90.0, 120.0])
20
    hex_cell = np.identity(3)
21
    hex_cell[1, 0] = -0.5
22
    hex_cell[1, 1] = np.sin(np.deg2rad(120.0))
23
24
    cellpar_2 = np.array([1.0, 2.0, 3.0, 60.0, 90.0, 120.0])
25
    cell_2 = np.identity(3)
26
    cell_2[1, 0] = -1
27
    cell_2[1, 1] = 2 * np.sin(np.deg2rad(cellpar_2[5]))
28
    cy = 0.5 / np.sin(np.deg2rad(120))
29
    cell_2[2, 1] = 3 * cy
30
    cell_2[2, 2] = 3 * np.sqrt(1.0 - cy**2)
31
    cellpars_and_cells = [(hex_cellpar, hex_cell), (cellpar_2, cell_2)]
32
33
    for cellpar, cell in cellpars_and_cells:
34
        cell_ = amd.cellpar_to_cell(cellpar)
35
        if not np.allclose(cell, cell_):
36
            pytest.fail(
37
                f"amd.cellpar_to_cell() of {cellpar} should be {hex_cell}, got "
38
                f"{cell}"
39
            )
40