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)
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)