Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test core_fast added [Issue #28] #30

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions membrane_curvature/lib/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def dict2pickle(name, dict_):
pickle.dump(dict_, pk, protocol=pickle.HIGHEST_PROTOCOL)


def core_fast(traj, jump, n_cells, leaflets, lipid_types, lipid_ref,
box_size, max_width, prefix):
def core_fast(traj, jump, n_cells, leaflets, lipid_types, lipid_ref, max_width, prefix):
"""
Runs core_fast_leaflet for each leaflet

Expand Down
34 changes: 16 additions & 18 deletions membrane_curvature/tests/test_mdakit_membcurv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

import pytest
import sys
import math
import os
import mdtraj as md # This will be gone after refactoring
import itertools as it
from ..lib.mods import core_fast_leaflet, curvature, mean_curvature, gaussian_curvature, dict2pickle
from ..lib.mods import core_fast_leaflet, curvature, mean_curvature, gaussian_curvature, dict2pickle, core_fast
import numpy as np
from numpy.testing import assert_almost_equal
import MDAnalysis as mda
Expand Down Expand Up @@ -188,27 +186,13 @@ def md_ref_beads():
return md_ref_beads


def test_membrane_curvature_imported():
"""Sample test, will always pass so long as import statement worked"""
assert "membrane_curvature" in sys.modules


def test_dict_to_pickle(tmpdir):
name = 'test_pickle_output'
dict_ = {'A': 1, 'B': 2, 'C': 3}
with tmpdir.as_cwd():
dict2pickle(name, dict_)
unpickled = pickle.load(open(name + '.pickle', 'rb'))
assert dict_ == unpickled


def test_gaussian_curvature():
K_test = gaussian_curvature(MEMBRANE_CURVATURE_DATA['z_ref'])
for k, k_test in zip(MEMBRANE_CURVATURE_DATA['gaussian_curvature'], K_test):
assert_almost_equal(k, k_test)


def test_mean_curvature():
def test_mean_curvature():
H_test = mean_curvature(MEMBRANE_CURVATURE_DATA['z_ref'])
for h, h_test in zip(MEMBRANE_CURVATURE_DATA['mean_curvature'], H_test):
assert_almost_equal(h, h_test)
Expand All @@ -224,6 +208,17 @@ def test_core_fast_leaflet(md_ref_beads, mdtraj_po4):
assert_almost_equal(z, z_test)


def test_core_fast(md_ref_beads, mdtraj_po4):
jump = 1
n_cells = 10
max_width = 19
z_calc = np.zeros([n_cells, n_cells])
core_fast_leaflet(z_calc, "upper", mdtraj_po4, jump, n_cells, ["POPC"], md_ref_beads, max_width)
core_fast(mdtraj_po4, jump, n_cells, ["upper"], ["POPC"], md_ref_beads, max_width, 'test')
for z, z_test in zip(MEMBRANE_CURVATURE_DATA['z_avg_coords'], z_calc):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In unit testing we typically try to validate a single function in at least one test. Could you add tests where you check the functionality of core_fast and core_fast_leaflet separately in addition to this one?

assert_almost_equal(z, z_test)


def test_curvature(md_ref_beads, mdtraj_po4):
jump = 1
n_cells = 10
Expand All @@ -239,3 +234,6 @@ def test_curvature(md_ref_beads, mdtraj_po4):

for k, k_test in zip(MEMBRANE_CURVATURE_DATA['gaussian_from_z_avg'][lf], K_test[lf]):
assert_almost_equal(k, k_test)