Skip to content

Commit

Permalink
Merge branch 'fix-tests' of https://github.com/tjni/atomman
Browse files Browse the repository at this point in the history
  • Loading branch information
lmhale99 committed Oct 3, 2022
2 parents b091a41 + 057d24c commit 90245ef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
11 changes: 6 additions & 5 deletions tests/plot/test_interpolate.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import pytest
import numpy as np

from atomman.plot.interpolate_contour import grid_interpolate_2d
from atomman.plot.interpolate_contour import __grid_interpolate


def test_grid_interpolate_2d():
def test_grid_interpolate():
x = np.array([0, 0, 1])
y = np.array([0, 1, 1])
v = np.array([0, 1, 2])
range = [[0, 1], [0, 1]]
xlim = (0, 1)
ylim = (0, 1)

# extrapolation occurs
grid, _, _ = grid_interpolate_2d(x, y, v, range=range)
grid = __grid_interpolate(x, y, v, xlim=xlim, ylim=ylim)
assert np.any(np.isnan(grid))

# fill in extrapolated points
fill_value = 1234
filled_grid, _, _ = grid_interpolate_2d(x, y, v, range=range, fill_value=fill_value)
filled_grid = __grid_interpolate(x, y, v, xlim=xlim, ylim=ylim, fill_value=fill_value)
np.testing.assert_almost_equal(filled_grid[np.isnan(grid)], fill_value)
4 changes: 2 additions & 2 deletions tests/region/test_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def test_isclose():
plane1 = Plane(normal=[1, 0, 0], point=[1, 0, 0])
plane2 = Plane(normal=[1.0001, 0, 0], point=[1.0001, 1, 1])
assert plane1 != plane2
assert plane1.isclose(plane2, rtol=1e-4, atol=1e-4)
assert plane2.isclose(plane1, rtol=1e-4, atol=1e-4)
assert plane1.isclose(plane2, atol=1e-4)
assert plane2.isclose(plane1, atol=1e-4)


def test_equality():
Expand Down
14 changes: 7 additions & 7 deletions tests/test_unitconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@

class Test_unitconvert:
def test_build_unit(self):
assert pytest.approx(uc.unit['mm'], 10000000.0)
assert pytest.approx(uc.unit['mm']) == 10000000.0
uc.unit['mm'] = 5253.
assert pytest.approx(uc.unit['mm'], 5253.)
assert pytest.approx(uc.unit['mm']) == 5253.
uc.build_unit()
assert pytest.approx(uc.unit['mm'], 10000000.0)
assert pytest.approx(uc.unit['mm']) == 10000000.0

def test_set_and_get_in_units(self):
newton = uc.set_in_units(1e5, 'dyn')
assert pytest.approx(uc.get_in_units(newton, 'kg*m/s^2'), 1.0)
assert pytest.approx(uc.get_in_units(newton, 'kg*m/s^2')) == 1.0

def test_set_literal(self):
value = uc.set_literal('1.124 nm')
assert pytest.approx(value, 11.24)
assert pytest.approx(value) == 11.24

def test_scalar_model(self):
unit = 'mJ/s^2'
v = 1234.214
value = uc.set_in_units(v, unit)
model = uc.model(value, unit)
value2 = uc.value_unit(model)
assert pytest.approx(value, value2)
assert pytest.approx(value) == value2

def test_vector_model(self):
unit = 'mJ/s^2'
Expand All @@ -46,4 +46,4 @@ def test_tensor_model(self):
value = uc.set_in_units(v, unit)
model = uc.model(value, unit)
value2 = uc.value_unit(model)
assert np.allclose(value, value2)
assert np.allclose(value, value2)
8 changes: 4 additions & 4 deletions tests/tools/test_vect_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

class Test_vect_angle:
def test_0(self):
assert pytest.approx(vect_angle([1,0,0], [1,0,0]), 0.0)
assert pytest.approx(vect_angle([1,0,0], [1,0,0])) == 0.0

def test_180(self):
assert pytest.approx(vect_angle([1,0,0], [-1,0,0]), 180.0)
assert pytest.approx(vect_angle([1,0,0], [-1,0,0])) == 180.0

def test_90(self):
assert pytest.approx(vect_angle([1,0,0], [0,1,0]), 90.0)
assert pytest.approx(vect_angle([1,0,0], [0,1,0])) == 90.0

def test_45(self):
assert pytest.approx(vect_angle([1,1,0], [1,1,0]), 45.0)
assert pytest.approx(vect_angle([1,1,0], [1,0,0])) == 45.0

0 comments on commit 90245ef

Please sign in to comment.