def test_value2(self): "Test a known solution" cw = CircularWire(self.normalx, self.center, self.radius, self.current) B2 = cw.magnetic_field([1, 0, 0]) B2_expected = np.array([1, 0, 0]) * 2 * np.pi / 2**1.5 * 1e-7 * u.T assert np.all(np.isclose(B2.value, B2_expected.value)) assert B2.unit == u.T
def setup_method(self): self.cw = CircularWire( np.array([0, 0, 1]), np.array([0, 0, 0]) * u.m, 1 * u.m, 1 * u.A ) p1 = np.array([0.0, 0.0, 0.0]) * u.m p2 = np.array([0.0, 0.0, 1.0]) * u.m self.fw = FiniteStraightWire(p1, p2, 1 * u.A)
class Test_GeneralWire: def setup_method(self): self.cw = CircularWire( np.array([0, 0, 1]), np.array([0, 0, 0]) * u.m, 1 * u.m, 1 * u.A ) p1 = np.array([0.0, 0.0, 0.0]) * u.m p2 = np.array([0.0, 0.0, 1.0]) * u.m self.fw = FiniteStraightWire(p1, p2, 1 * u.A) def test_not_callable(self): "Test that `GeneralWire` raises `ValueError` if its first argument is not callale" with pytest.raises(ValueError): GeneralWire("wire", 0, 1, 1 * u.A) def test_close_cw(self): "Test if the GeneralWire is close to the CircularWire it converted from" gw_cw = self.cw.to_GeneralWire() p = np.array([0, 0, 0]) B_cw = self.cw.magnetic_field(p) B_gw_cw = gw_cw.magnetic_field(p) assert np.all(np.isclose(B_cw.value, B_gw_cw.value)) assert B_cw.unit == B_gw_cw.unit def test_repr(self): "Test __repr__ function" gw_cw = self.cw.to_GeneralWire() # round numbers to avoid calculation accuracy mismatch gw_cw.t1 = -3.1516 gw_cw.t2 = +3.1516 assert ( repr(gw_cw) == r"GeneralWire(parametric_eq=curve, t1=-3.1516, t2=3.1516, current=1.0A)" ) def test_close_fw(self): "Test if the GeneralWire is close to the FiniteWire it converted from" gw_fw = self.fw.to_GeneralWire() p = np.array([1, 0, 0]) B_fw = self.fw.magnetic_field(p) B_gw_fw = gw_fw.magnetic_field(p) assert np.all(np.isclose(B_fw.value, B_gw_fw.value)) assert B_fw.unit == B_gw_fw.unit def test_value_error(self): "Test GeneralWire raise ValueError when argument t1>t2" with pytest.raises(ValueError): gw_cw = GeneralWire(lambda t: [0, 0, t], 2, 1, 1.0 * u.A)
def test_repr(self): "Test __repr__ function" cw = CircularWire(self.normalz, self.center, self.radius, self.current) assert ( repr(cw) == r"CircularWire(normal=[0. 0. 1.], center=[0. 0. 0.]m, radius=1.0m, current=1.0A)" )
class Test_GeneralWire: def setup_method(self): self.cw = CircularWire(np.array([0, 0, 1]), np.array([0, 0, 0]) * u.m, 1 * u.m, 1 * u.A) p1 = np.array([0., 0., 0.]) * u.m p2 = np.array([0., 0., 1.]) * u.m self.fw = FiniteStraightWire(p1, p2, 1 * u.A) def test_not_callable(self): "Test that `GeneralWire` raises `ValueError` if its first argument is not callale" with pytest.raises(ValueError): GeneralWire("wire", 0, 1, 1 * u.A) def test_close_cw(self): "Test if the GeneralWire is close to the CircularWire it converted from" gw_cw = self.cw.to_GeneralWire() p = np.array([0, 0, 0]) B_cw = self.cw.magnetic_field(p) B_gw_cw = gw_cw.magnetic_field(p) assert np.all(np.isclose(B_cw.value, B_gw_cw.value)) assert B_cw.unit == B_gw_cw.unit def test_close_fw(self): "Test if the GeneralWire is close to the FiniteWire it converted from" gw_fw = self.fw.to_GeneralWire() p = np.array([1, 0, 0]) B_fw = self.fw.magnetic_field(p) B_gw_fw = gw_fw.magnetic_field(p) assert np.all(np.isclose(B_fw.value, B_gw_fw.value)) assert B_fw.unit == B_gw_fw.unit def test_value_error(self): "Test GeneralWire raise ValueError when argument t1>t2" with pytest.raises(ValueError): gw_cw = GeneralWire(lambda t: [0, 0, t], 2, 1, 1. * u.A)
def test_negative_radius(self): "Test that `FiniteStraightWire` raises `ValueError` if radius < 0" with pytest.raises(ValueError): CircularWire(self.normalz, self.center, -1.0 * u.m, self.current)