class TestSimulatedCrystalCounter(unittest.TestCase):

    def setUp(self):
        self.diff = MockScannable()
        self.wl = MockScannable()
        self.wl.pos = 1.
        self.eq = MockEquation()
        self.scc = SimulatedCrystalCounter('det', self.diff, Fourc(), self.wl,
                                           self.eq)

    def testInit(self):
        self.assertEquals(list(self.scc.getInputNames()), ['det_count'])
        self.assertEquals(list(self.scc.getExtraNames()), [])
        self.assertEquals(self.scc.chiMissmount, 0.)
        self.assertEquals(self.scc.phiMissmount, 0.)

    def testCalcUB(self):
        UB = matrix([[2 * pi, 0, 0], [0, 2 * pi, 0], [0, 0, 2 * pi]])
        mneq_(self.scc.UB, UB)

    def testGetHkl(self):
        self.diff.pos = [60, 30, 0, 0]
        hkl = self.scc.getHkl()
        self.assert_(nearlyEqual(hkl, (1, 0, 0), .0000001),
                     "%s!=\n%s" % (hkl, (1, 0, 0)))

        self.diff.pos = [60, 31, 0, 0]
        hkl = self.scc.getHkl()
        self.assert_(nearlyEqual(hkl,
                                 (0.999847695156391, 0.017452406437283574, 0),
                                 .0000001), "%s!=\n%s" % (hkl, (1, 0, 0)))

    def testGetPosition(self):
        self.diff.pos = [60, 30, 0, 0]
        self.scc.asynchronousMoveTo(2)
        count = self.scc.getPosition()
        self.assert_(nearlyEqual(self.eq.dHkl, (0, 0, 0), .00001))
        self.assertEqual(count, 2)

        self.diff.pos = [60, 31, 0, 0]
        count = self.scc.getPosition()
        dHkl = (0.999847695156391 - 1, .017452406437283574, 0)
        self.assert_(nearlyEqual(self.eq.dHkl, dHkl, .00001),
                      "%s!=\n%s" % (self.eq.dHkl, dHkl))
        self.assertEqual(count, 2)

    def test__repr__(self):
        self.diff.pos = [60, 30, 0, 0]
        print self.scc.__repr__()
Example #2
0
class TestSimulatedCrystalCounter(object):
    def setup_method(self):
        self.diff = MockScannable()
        self.wl = MockScannable()
        self.wl.pos = 1.
        self.eq = MockEquation()
        self.scc = SimulatedCrystalCounter('det', self.diff, Fourc(), self.wl,
                                           self.eq)

    def testInit(self):
        assert list(self.scc.getInputNames()) == ['det_count']
        assert list(self.scc.getExtraNames()) == []
        assert self.scc.chiMissmount == 0.
        assert self.scc.phiMissmount == 0.

    def testCalcUB(self):
        UB = matrix([[2 * pi, 0, 0], [0, 2 * pi, 0], [0, 0, 2 * pi]])
        mneq_(self.scc.UB, UB)

    def testGetHkl(self):
        self.diff.pos = [60, 30, 0, 0]
        hkl = self.scc.getHkl()
        assert hkl == approx((1, 0, 0))

        self.diff.pos = [60, 31, 0, 0]
        hkl = self.scc.getHkl()
        assert hkl == approx((0.999847695156391, 0.017452406437283574, 0))

    def testGetPosition(self):
        self.diff.pos = [60, 30, 0, 0]
        self.scc.asynchronousMoveTo(2)
        count = self.scc.getPosition()
        assert self.eq.dHkl == approx((0, 0, 0))
        assert count == 2

        self.diff.pos = [60, 31, 0, 0]
        count = self.scc.getPosition()
        dHkl = (0.999847695156391 - 1, .017452406437283574, 0)
        assert self.eq.dHkl == approx(dHkl)
        assert count == 2

    def test__repr__(self):
        self.diff.pos = [60, 30, 0, 0]
        print self.scc.__repr__()