Initial version
This commit is contained in:
BIN
test/data/water/topol.tpr
Normal file
BIN
test/data/water/topol.tpr
Normal file
Binary file not shown.
BIN
test/data/water/traj.xtc
Normal file
BIN
test/data/water/traj.xtc
Normal file
Binary file not shown.
7
test/test_atoms.py
Normal file
7
test/test_atoms.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from mdevaluate import atoms
|
||||
|
||||
|
||||
def test_compare_regex():
|
||||
assert atoms.compare_regex(['OW', ], 'O')[0] == False
|
||||
assert atoms.compare_regex(['WO', ], 'O')[0] == False
|
||||
assert atoms.compare_regex(['O', ], 'O')[0] == True
|
39
test/test_checksum.py
Normal file
39
test/test_checksum.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from mdevaluate import checksum
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
def test_checksum():
|
||||
salt = checksum.SALT
|
||||
checksum.SALT = ''
|
||||
assert checksum.checksum(1) == 304942582444936629325699363757435820077590259883
|
||||
assert checksum.checksum('42') == checksum.checksum(42)
|
||||
cs1 = checksum.checksum(999)
|
||||
checksum.SALT = '999'
|
||||
assert cs1 != checksum.checksum(999)
|
||||
|
||||
a = np.array([1, 2, 3])
|
||||
assert checksum.checksum(a) == checksum.checksum(a.tobytes())
|
||||
|
||||
checksum.SALT = salt
|
||||
|
||||
|
||||
def test_version():
|
||||
|
||||
@checksum.version(1)
|
||||
def f1():
|
||||
pass
|
||||
|
||||
cs1 = checksum.checksum(f1)
|
||||
|
||||
@checksum.version(1)
|
||||
def f1(x, y):
|
||||
return x + y
|
||||
|
||||
assert cs1 == checksum.checksum(f1)
|
||||
|
||||
@checksum.version(2)
|
||||
def f1(x, y):
|
||||
pass
|
||||
|
||||
assert cs1 != checksum.checksum(f1)
|
31
test/test_coordinates.py
Normal file
31
test/test_coordinates.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import os
|
||||
import pytest
|
||||
|
||||
import mdevaluate
|
||||
from mdevaluate import coordinates
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def trajectory(request):
|
||||
return mdevaluate.open(os.path.join(os.path.dirname(__file__), 'data/water'))
|
||||
|
||||
|
||||
def test_coordinates_getitem(trajectory):
|
||||
"""
|
||||
Tests for the Coordinates class.
|
||||
"""
|
||||
assert isinstance(trajectory[0], coordinates.CoordinateFrame)
|
||||
assert isinstance(trajectory[len(trajectory) - 1], coordinates.CoordinateFrame)
|
||||
i = 0
|
||||
dt = trajectory[1].time - trajectory[0].time
|
||||
for f in trajectory:
|
||||
assert f.step == i
|
||||
assert round(f.time, 3) == round(i * dt, 3)
|
||||
i += 1
|
||||
sl = trajectory[0::10]
|
||||
assert isinstance(sl, coordinates.Coordinates)
|
||||
i = 0
|
||||
for f in sl:
|
||||
assert f.step == i
|
||||
assert round(f.time, 3) == round(i * dt, 3)
|
||||
i += 10
|
14
test/test_pbc.py
Normal file
14
test/test_pbc.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from pytest import approx
|
||||
|
||||
from mdevaluate import pbc
|
||||
import numpy as np
|
||||
|
||||
|
||||
def test_pbc_diff():
|
||||
x = np.random.rand(10, 3)
|
||||
y = np.random.rand(10, 3)
|
||||
box = np.ones((3,))
|
||||
|
||||
assert (pbc.pbc_diff(x, x, box) == approx(0))
|
||||
dxy = (pbc.pbc_diff(x, y, box)**2).sum(axis=1)**0.5
|
||||
assert (dxy <= 0.75**0.5).all()
|
46
test/test_utils.py
Normal file
46
test/test_utils.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from copy import copy
|
||||
import pytest
|
||||
import numpy as np
|
||||
|
||||
from mdevaluate import utils
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def logdata(request):
|
||||
xdata = np.logspace(-1, 3, 50)
|
||||
ydata = np.exp(- (xdata)**0.7)
|
||||
return xdata, ydata
|
||||
|
||||
|
||||
def test_filon_fourier_transformation(logdata):
|
||||
xdata, ydata = logdata
|
||||
|
||||
xdata_zero = copy(xdata)
|
||||
xdata_zero[0] = 0
|
||||
_, filon = utils.filon_fourier_transformation(xdata_zero, ydata)
|
||||
assert not np.isnan(filon).any(), 'There are NaN values in the filon result!'
|
||||
|
||||
freqs = np.logspace(-4, 1)
|
||||
filon_freqs, filon_imag = utils.filon_fourier_transformation(
|
||||
xdata, xdata, frequencies=freqs, derivative='linear', imag=True
|
||||
)
|
||||
|
||||
assert (freqs == filon_freqs).all()
|
||||
|
||||
freqs, filon_real = utils.filon_fourier_transformation(
|
||||
xdata, xdata, frequencies=freqs, derivative='linear', imag=False
|
||||
)
|
||||
assert np.isclose(filon_imag.real, filon_real).all()
|
||||
|
||||
|
||||
def test_histogram():
|
||||
data = np.random.rand(100)
|
||||
bins = np.linspace(0, 1)
|
||||
np_hist = np.histogram(data, bins=bins)[0]
|
||||
ut_hist = utils.histogram(data, bins=bins)[0]
|
||||
assert (np_hist == ut_hist).all()
|
||||
|
||||
bins = np.linspace(0.3, 1.5)
|
||||
np_hist = np.histogram(data, bins=bins)[0]
|
||||
ut_hist = utils.histogram(data, bins=bins)[0]
|
||||
assert (np_hist == ut_hist).all()
|
Reference in New Issue
Block a user