def ex_gcd(a, b=0b100011011): # 采用书上的递归方法 if b == 0: return a, 1, 0 else: gcd, x_temp, y_temp = ex_gcd(b, compute.mod(a, b)) x = y_temp y = x_temp ^ compute.mul(y_temp, compute.divide(a, b)) return [gcd, x, y]
def test_divide_zero(): assert np.isinf(divide(1, 0))
def test_divide(a, b, x): res = divide(a, b) assert res == pytest.approx(x)
def test_divide(): x = divide(1, 2) assert x == 0.5
def test_divide(): x = divide(1, 2) assert x == pytest.approx(0.5)
def test_divide_array(): a = np.array([1, 1, 1]) b = np.array([2, 2, 2]) x = divide(a, b) assert_allclose(x, np.array([0.5, 0.5, 0.5]))
def test_divide(): x = divide(1,2) print(x) assert x == 0.5
def test_divide_array(a, b, x): assert_allclose(divide(a, b), x, rtol=1e-4)
def test_multiply(): x = divide(2, 2) assert x == 4
def test_divide_zero(): x = divide(2, 0) assert np.isinf(x)
def test_divide(a, b, x, dtype): res = divide(a, b) assert res == pytest.approx(x) assert np.dtype(type(res)) == dtype
def test_divide : res=divide(1,2) assert res==pytest.approx(x)
def test_divide(lop, rop, res): x = divide(lop, rop) assert x == pytest.approx(res)
def test_divide(a, b, x): res = divide(a, b) print(x) assert res == pytest.approx( x) #better, because can occur some imprecisions due to type