Skip to content

Commit c111a66

Browse files
committed
Move xyz_cartn tests to TestAtom class.
Also add extra test for Atom.xyz_cartn property. Resolve long standing FIXME note.
1 parent 038c34a commit c111a66

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

diffpy/Structure/tests/TestAtom.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import numpy
2424

2525
from diffpy.Structure.atom import Atom
26+
from diffpy.Structure.lattice import Lattice
2627

2728
##############################################################################
2829
class TestAtom(unittest.TestCase):
@@ -82,17 +83,27 @@ def test___init__(self):
8283
# """check Atom.__copy__()
8384
# """
8485
# return
85-
#
86-
# def test__get_xyz_cartn(self):
87-
# """check Atom._get_xyz_cartn()
88-
# """
89-
# return
90-
#
91-
# def test__set_xyz_cartn(self):
92-
# """check Atom._set_xyz_cartn()
93-
# """
94-
# return
95-
#
86+
87+
def test_xyz_cartn(self):
88+
"""check Atom.xyz_cartn property
89+
"""
90+
hexagonal = Lattice(1, 1, 1, 90, 90, 120)
91+
a0 = Atom('C', [0, 0, 0], lattice=hexagonal)
92+
a1 = Atom('C', [1, 1, 1], lattice=hexagonal)
93+
self.assertTrue(all(a0.xyz_cartn == 0))
94+
rc1 = numpy.array([0.75 ** 0.5, 0.5, 1])
95+
self.assertTrue(numpy.allclose(rc1, a1.xyz_cartn))
96+
a1.xyz_cartn[2] = 0
97+
self.assertTrue(numpy.allclose([1, 1, 0], a1.xyz))
98+
a1.xyz_cartn[:2] = 0
99+
self.assertTrue(all(a1.xyz == 0))
100+
a3 = Atom('C', [1, 2, 3])
101+
self.assertTrue(numpy.array_equal(a3.xyz, a3.xyz_cartn))
102+
a3.xyz_cartn = 1.3
103+
self.assertTrue(all(1.3 == a3.xyz_cartn))
104+
self.assertTrue(all(1.3 == a3.xyz))
105+
return
106+
96107
# def test__get_anisotropy(self):
97108
# """check Atom._get_anisotropy()
98109
# """

diffpy/Structure/tests/TestStructure.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,6 @@ def assertListAlmostEqual(self, l1, l2, places=None):
5858
for i in range(len(l1)):
5959
self.assertAlmostEqual(l1[i], l2[i], places)
6060

61-
# FIXME move into TestAtom
62-
def test_cartesian(self):
63-
"""check conversion to cartesian coordinates"""
64-
from math import sqrt
65-
stru = self.stru
66-
s_rc0 = stru[0].xyz_cartn
67-
f_rc0 = 3*[0.0]
68-
s_rc1 = stru[1].xyz_cartn
69-
f_rc1 = [sqrt(0.75), 0.5, 1.]
70-
self.assertListAlmostEqual(s_rc0, f_rc0)
71-
self.assertListAlmostEqual(s_rc1, f_rc1)
72-
7361
# def test___init__(self):
7462
# """check Structure.__init__()
7563
# """

0 commit comments

Comments
 (0)