|
19 | 19 | import unittest |
20 | 20 |
|
21 | 21 | import numpy |
| 22 | +import pytest |
22 | 23 |
|
23 | 24 | from diffpy.structure.spacegroups import GetSpaceGroup |
24 | 25 | from diffpy.structure.symmetryutilities import ( |
@@ -109,24 +110,12 @@ def test_positionDifference(self): |
109 | 110 | self.assertTrue(numpy.allclose(positionDifference([1.2, -0.1, 2.75], [0.1, 0.4, 0.25]), [0.1, 0.5, 0.5])) |
110 | 111 | return |
111 | 112 |
|
112 | | - def test_position_difference(self): |
113 | | - """Check position_difference in normal and boundary cases.""" |
114 | | - self.assertTrue(numpy.allclose(position_difference([0.1, 0.9, 0.2], [0.8, 0.1, 0.8]), [0.3, 0.2, 0.4])) |
115 | | - self.assertTrue(numpy.allclose(position_difference([1.2, -0.1, 2.75], [0.1, 0.4, 0.25]), [0.1, 0.5, 0.5])) |
116 | | - return |
117 | | - |
118 | 113 | def test_nearestSiteIndex(self): |
119 | 114 | """Check nearestSiteIndex with single and multiple sites.""" |
120 | 115 | self.assertEqual(nearestSiteIndex([[0.1, 0.9, 0.2], [0.8, 0.1, 0.8]], [0.8, 0.1, 0.8]), 1) |
121 | 116 | self.assertEqual(nearestSiteIndex([[1.2, -0.1, 2.75]], [0.7, 0.4, 0.25]), 0) |
122 | 117 | return |
123 | 118 |
|
124 | | - def test_nearest_site_index(self): |
125 | | - """Check nearest_site_index with single and multiple sites.""" |
126 | | - self.assertEqual(nearest_site_index([[0.1, 0.9, 0.2], [0.8, 0.1, 0.8]], [0.8, 0.1, 0.8]), 1) |
127 | | - self.assertEqual(nearest_site_index([[1.2, -0.1, 2.75]], [0.7, 0.4, 0.25]), 0) |
128 | | - return |
129 | | - |
130 | 119 | def test_expandPosition(self): |
131 | 120 | """Check expandPosition()""" |
132 | 121 | # ok again Ni example |
@@ -674,5 +663,46 @@ def test_UparValues(self): |
674 | 663 |
|
675 | 664 | # ---------------------------------------------------------------------------- |
676 | 665 |
|
| 666 | + |
| 667 | +@pytest.mark.parametrize( |
| 668 | + "xyz0, xyz1, expected", |
| 669 | + [ |
| 670 | + pytest.param( # C1: Generic case for symmetry mapping for periodic lattice |
| 671 | + [0.1, 0.9, 0.2], |
| 672 | + [0.8, 0.1, 0.8], |
| 673 | + [0.3, 0.2, 0.4], |
| 674 | + ), |
| 675 | + pytest.param( # C2: Boundary case for entries with mapping on difference equal to 0.5 |
| 676 | + [1.2, -0.1, 2.75], |
| 677 | + [0.1, 0.4, 0.25], |
| 678 | + [0.1, 0.5, 0.5], |
| 679 | + ), |
| 680 | + ], |
| 681 | +) |
| 682 | +def test_position_difference(xyz0, xyz1, expected): |
| 683 | + actual = position_difference(xyz0, xyz1) |
| 684 | + assert numpy.allclose(actual, expected) |
| 685 | + |
| 686 | + |
| 687 | +@pytest.mark.parametrize( |
| 688 | + "sites, xyz, expected", |
| 689 | + [ |
| 690 | + pytest.param( # C1: We have two sites, and the xyz is closest to the index 1 site |
| 691 | + [[0.1, 0.9, 0.2], [0.8, 0.1, 0.8]], |
| 692 | + [0.8, 0.1, 0.8], |
| 693 | + 1, |
| 694 | + ), |
| 695 | + pytest.param( # C2: we have one site, and the xyz is closest to the index 0 site by default |
| 696 | + [[1.2, -0.1, 2.75]], |
| 697 | + [0.7, 0.4, 0.25], |
| 698 | + 0, |
| 699 | + ), |
| 700 | + ], |
| 701 | +) |
| 702 | +def test_nearest_site_index(sites, xyz, expected): |
| 703 | + actual = nearest_site_index(sites, xyz) |
| 704 | + assert actual == expected |
| 705 | + |
| 706 | + |
677 | 707 | if __name__ == "__main__": |
678 | 708 | unittest.main() |
0 commit comments