Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_cartesian(r, theta):
"""
In this test, we are testing to make sure that `get_cartesian` remains a
wrapper around polcart's `to_cartesian`.
"""
assume(np.isfinite(theta))
assume(np.isfinite(r))
assert get_cartesian(r, theta) == polcart.to_cartesian(r, theta)
def test_convert_rt(r, theta):
assume(r > 0.01 and r < 1e6)
assume(np.isfinite(r) and np.isfinite(theta))
assume(theta <= np.pi and theta >= -np.pi)
x, y = to_cartesian(r, theta)
r_new, theta_new = to_polar(x, y)
assert np.allclose(r, r_new)
assert np.allclose(abs(theta_new), abs(theta))
def test_convert_xy(x, y):
assume(x != 0 and y != 0)
assume(np.isfinite(x) and np.isfinite(y))
assume(abs(x) < 1e6 and abs(y) < 1e6)
assume(abs(x) > 0.01 and abs(y) > 0.01)
# Test radians
r, theta = to_polar(x, y)
x_new, y_new = to_cartesian(r, theta)
assert np.allclose(x, x_new)
assert np.allclose(y, y_new)
# Test degrees
r, theta = to_polar(x, y, theta_units="degrees")
x_new, y_new = to_cartesian(r, theta, theta_units="degrees")
assert np.allclose(x, x_new)
assert np.allclose(y, y_new)
def test_convert_xy(x, y):
assume(x != 0 and y != 0)
assume(np.isfinite(x) and np.isfinite(y))
assume(abs(x) < 1e6 and abs(y) < 1e6)
assume(abs(x) > 0.01 and abs(y) > 0.01)
# Test radians
r, theta = to_polar(x, y)
x_new, y_new = to_cartesian(r, theta)
assert np.allclose(x, x_new)
assert np.allclose(y, y_new)
# Test degrees
r, theta = to_polar(x, y, theta_units="degrees")
x_new, y_new = to_cartesian(r, theta, theta_units="degrees")
assert np.allclose(x, x_new)
assert np.allclose(y, y_new)
def get_cartesian(r, theta):
"""
Returns the cartesian (x,y) coordinates of (r, theta).
:param r: Real-valued radius.
:type r: int, float.
:param theta: Angle
:type theta: int, float.
:returns: to_cartesian(r, theta)
"""
return to_cartesian(r, theta)