Exemple #1
0
    def test_equal(self):
        x = self.q.magnitude
        u = self.Q_(np.ones(x.shape))

        self.assertSequenceEqual(u, u)
        self.assertSequenceEqual(u == u, u.magnitude == u.magnitude)
        self.assertSequenceEqual(u == 1, u.magnitude == 1)
Exemple #2
0
    def test_equal(self):
        x = self.q.magnitude
        u = self.Q_(np.ones(x.shape))

        self.assertSequenceEqual(u, u)
        self.assertSequenceEqual(u == u, u.magnitude == u.magnitude)
        self.assertSequenceEqual(u == 1, u.magnitude == 1)
Exemple #3
0
 def test_reversible_op(self):
     """
     """
     x = self.q.magnitude
     u = self.Q_(np.ones(x.shape))
     self.assertSequenceEqual(x / self.q, u * x / self.q)
     self.assertSequenceEqual(x * self.q, u * x * self.q)
     self.assertSequenceEqual(x + u, u + x)
     self.assertSequenceEqual(x - u, -(u - x))
Exemple #4
0
 def test_reversible_op(self):
     """
     """
     x = self.q.magnitude
     u = self.Q_(np.ones(x.shape))
     self.assertSequenceEqual(x / self.q, u * x / self.q)
     self.assertSequenceEqual(x * self.q, u * x * self.q)
     self.assertSequenceEqual(x + u, u + x)
     self.assertSequenceEqual(x - u, -(u - x))
Exemple #5
0
 def test_reversible_op(self):
     """This fails because x / self.q returns an array, not Quantity.
     Division is handled by the ndarray code.
     """
     x = self.q.magnitude
     u = self.Q_(np.ones(x.shape))
     self.assertSequenceEqual(x / self.q, u * x / self.q)
     self.assertSequenceEqual(x * self.q, u * x * self.q)
     self.assertSequenceEqual(x + u, u + x)
     self.assertSequenceEqual(x - u, -(u - x))
Exemple #6
0
 def test_reversible_op(self):
     """This fails because x / self.q returns an array, not Quantity.
     Division is handled by the ndarray code.
     """
     x = self.q.magnitude
     u = self.Q_(np.ones(x.shape))
     self.assertSequenceEqual(x / self.q, u * x / self.q)
     self.assertSequenceEqual(x * self.q, u * x * self.q)
     self.assertSequenceEqual(x + u, u + x)
     self.assertSequenceEqual(x - u, -(u - x))
Exemple #7
0
    def test_issue39(self):
        x = np.matrix([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
        ureg = UnitRegistry()
        q = ureg.meter * x
        self.assertIsInstance(q, ureg.Quantity)
        self.assertSequenceEqual(q.magnitude, x)
        self.assertEquals(q.units, ureg.meter.units)
        q = x * ureg.meter
        self.assertIsInstance(q, ureg.Quantity)
        self.assertSequenceEqual(q.magnitude, x)
        self.assertEquals(q.units, ureg.meter.units)

        m = np.matrix(2 * np.ones(3, 3))
        qq = q * m
        self.assertIsInstance(qq, ureg.Quantity)
        self.assertSequenceEqual(qq.magnitude, x * m)
        self.assertEquals(qq.units, ureg.meter.units)
        qq = m * q
        self.assertIsInstance(qq, ureg.Quantity)
        self.assertSequenceEqual(qq.magnitude, x * m)
        self.assertEquals(qq.units, ureg.meter.units)
Exemple #8
0
    def test_issue37(self):
        x = np.ma.masked_array([1, 2, 3], mask=[True, True, False])
        ureg = UnitRegistry()
        q = ureg.meter * x
        self.assertIsInstance(q, ureg.Quantity)
        self.assertSequenceEqual(q.magnitude, x)
        self.assertEquals(q.units, ureg.meter.units)
        q = x * ureg.meter
        self.assertIsInstance(q, ureg.Quantity)
        self.assertSequenceEqual(q.magnitude, x)
        self.assertEquals(q.units, ureg.meter.units)

        m = np.ma.masked_array(2 * np.ones(3, 3))
        qq = q * m
        self.assertIsInstance(qq, ureg.Quantity)
        self.assertSequenceEqual(qq.magnitude, x * m)
        self.assertEquals(qq.units, ureg.meter.units)
        qq = m * q
        self.assertIsInstance(qq, ureg.Quantity)
        self.assertSequenceEqual(qq.magnitude, x * m)
        self.assertEquals(qq.units, ureg.meter.units)
Exemple #9
0
    def test_issue39(self):
        x = np.matrix([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
        ureg = UnitRegistry()
        q = ureg.meter * x
        self.assertIsInstance(q, ureg.Quantity)
        self.assertSequenceEqual(q.magnitude, x)
        self.assertEquals(q.units, ureg.meter.units)
        q = x * ureg.meter
        self.assertIsInstance(q, ureg.Quantity)
        self.assertSequenceEqual(q.magnitude, x)
        self.assertEquals(q.units, ureg.meter.units)

        m = np.matrix(2 * np.ones(3,3))
        qq = q * m
        self.assertIsInstance(qq, ureg.Quantity)
        self.assertSequenceEqual(qq.magnitude, x * m)
        self.assertEquals(qq.units, ureg.meter.units)
        qq = m * q
        self.assertIsInstance(qq, ureg.Quantity)
        self.assertSequenceEqual(qq.magnitude, x * m)
        self.assertEquals(qq.units, ureg.meter.units)
Exemple #10
0
    def test_issue37(self):
        x = np.ma.masked_array([1, 2, 3], mask=[True, True, False])
        ureg = UnitRegistry()
        q = ureg.meter * x
        self.assertIsInstance(q, ureg.Quantity)
        self.assertSequenceEqual(q.magnitude, x)
        self.assertEquals(q.units, ureg.meter.units)
        q = x * ureg.meter
        self.assertIsInstance(q, ureg.Quantity)
        self.assertSequenceEqual(q.magnitude, x)
        self.assertEquals(q.units, ureg.meter.units)

        m = np.ma.masked_array(2 * np.ones(3,3))
        qq = q * m
        self.assertIsInstance(qq, ureg.Quantity)
        self.assertSequenceEqual(qq.magnitude, x * m)
        self.assertEquals(qq.units, ureg.meter.units)
        qq = m * q
        self.assertIsInstance(qq, ureg.Quantity)
        self.assertSequenceEqual(qq.magnitude, x * m)
        self.assertEquals(qq.units, ureg.meter.units)