Skip to content

Commit 162d315

Browse files
committed
add a new test case test_assign_conformation_last_bin_peak to ensure the last bin peak section of the else is covered in assign_conformation
1 parent 7d910e1 commit 162d315

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

tests/test_CodeEntropy/test_entropy.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,51 @@ def test_assign_conformation(self):
16571657
assert np.all(result >= 0)
16581658
assert np.issubdtype(result.dtype, np.floating)
16591659

1660+
def test_assign_conformation_last_bin_peak(self):
1661+
"""
1662+
Test that the last bin in the histogram is correctly evaluated as a peak
1663+
when its population is greater than or equal to its neighbors.
1664+
"""
1665+
1666+
dihedral = MagicMock()
1667+
dihedral.value = MagicMock(side_effect=[5, 10, 250, 260, 350, 355])
1668+
1669+
# Mock trajectory frames
1670+
mock_timesteps = [MagicMock(frame=i) for i in range(6)]
1671+
data_container = MagicMock()
1672+
data_container.trajectory.__getitem__.return_value = mock_timesteps
1673+
1674+
# Create dummy universe and managers
1675+
tprfile = os.path.join(self.test_data_dir, "md_A4_dna.tpr")
1676+
trrfile = os.path.join(self.test_data_dir, "md_A4_dna_xf.trr")
1677+
u = mda.Universe(tprfile, trrfile)
1678+
1679+
args = MagicMock(bin_width=60, temperature=300, selection_string="all")
1680+
run_manager = RunManager("mock_folder/job001")
1681+
level_manager = LevelManager()
1682+
data_logger = DataLogger()
1683+
group_molecules = MagicMock()
1684+
1685+
ce = ConformationalEntropy(
1686+
run_manager, args, u, data_logger, level_manager, group_molecules
1687+
)
1688+
1689+
result = ce.assign_conformation(
1690+
data_container=data_container,
1691+
dihedral=dihedral,
1692+
number_frames=6,
1693+
bin_width=60,
1694+
start=0,
1695+
end=6,
1696+
step=1,
1697+
)
1698+
1699+
# Basic checks
1700+
assert isinstance(result, np.ndarray)
1701+
assert len(result) == 6
1702+
assert np.all(result >= 0)
1703+
assert np.issubdtype(result.dtype, np.floating)
1704+
16601705
def test_conformational_entropy_calculation(self):
16611706
"""
16621707
Test `conformational_entropy_calculation` method to verify

0 commit comments

Comments
 (0)