Ejemplo n.º 1
0
 def test_to_from_string_roundtrip(self, precision, alwayssign, imag):
     p_in = self.phase * 1j if imag else self.phase
     s = p_in.to_string(precision=precision, alwayssign=alwayssign)
     p = Phase.from_string(s)
     # We cannot get exact round-tripping, since we treat fractional
     # near 0 as if it is near 0.25.
     assert np.allclose((p - p_in).value, 0, atol=2**-53, rtol=0)
Ejemplo n.º 2
0
 def test_from_string_with_exponents(self):
     p = Phase.from_string('9876543210.0123456789e-01')
     assert p == Phase(987654321, .00123456789)
     p = Phase.from_string('9876543210.0123456789D-01')
     assert p == Phase(987654321, .00123456789)
     # Check that we avoid round-off errors (in fractional phase).
     assert p != Phase(9876543210 * 1e-1, .0123456789 * 1e-1)
     p = Phase.from_string('9876543210.0123456789e-01j')
     assert p == Phase(987654321j, .00123456789j)
     p = Phase.from_string('9876543210.0123456789e1j')
     assert p == Phase(98765432100j, .123456789j)
     p = Phase.from_string('9876543210.0123456789e-12j')
     assert p == Phase(0j, .0098765432100123456789j)
     # Really not suited for large exponents...
     p = Phase.from_string('9876543210.0123456789e12j')
     assert p == Phase(9876543210012345678900j, 0j)
Ejemplo n.º 3
0
 def test_from_string_invalid(self, item):
     with pytest.raises(ValueError):
         Phase.from_string(item)
Ejemplo n.º 4
0
 def test_to_from_string_alwayssign(self):
     ph = Phase([[-10], [20]], [-0.4, 0.4])
     s = ph.to_string(alwayssign=True)
     ph2 = Phase.from_string(s)
     # No worries about round-off, since fractions relatively large.
     assert np.all(ph == ph2)
Ejemplo n.º 5
0
 def test_from_string_basic(self):
     p = Phase.from_string('9876543210.0123456789')
     assert p == Phase(9876543210, .0123456789)
     p = Phase.from_string('9876543210.0123456789j')
     assert p == Phase(9876543210j, .0123456789j)