Example #1
0
 def test_allclose(self):
     self.assertTrue(
         np.allclose([1e10, 1e-8] * self.ureg.m,
                     [1.00001e10, 1e-9] * self.ureg.m))
     self.assertFalse(
         np.allclose([1e10, 1e-8] * self.ureg.m,
                     [1.00001e10, 1e-9] * self.ureg.mm))
Example #2
0
 def test_issue_1185(self):
     # Test __pow__
     foo = ureg.Quantity((3, 3), "mm / cm")
     assert np.allclose(foo**ureg.Quantity([2, 3], ""),
                        0.3**np.array([2, 3]))
     assert np.allclose(foo**np.array([2, 3]), 0.3**np.array([2, 3]))
     assert np.allclose(np.array([2, 3])**foo, np.array([2, 3])**0.3)
     # Test __ipow__
     foo **= np.array([2, 3])
     assert np.allclose(foo, 0.3**np.array([2, 3]))
     # Test __rpow__
     assert np.allclose(
         np.array((1, 1)).__rpow__(ureg.Quantity((2, 3), "mm / cm")),
         np.array((0.2, 0.3)),
     )
     assert np.allclose(
         ureg.Quantity((20, 20), "mm / cm").__rpow__(np.array((0.2, 0.3))),
         np.array((0.04, 0.09)),
     )
Example #3
0
 def test_allclose(self):
     assert np.allclose([1e10, 1e-8] * self.ureg.m, [1.00001e10, 1e-9] * self.ureg.m)
     assert not np.allclose(
         [1e10, 1e-8] * self.ureg.m, [1.00001e10, 1e-9] * self.ureg.mm
     )