def test_arcsin_result_var(): val = 0 x = Variable('x', val) obj_generate = elem.arcsin(x) obj_wanted = Variable('x', np.arcsin(val), 1 / np.sqrt(1 - val**2), val / (1 - val**2)**(3 / 2)) assert np.isclose(obj_generate.val, obj_wanted.val) ## ensure same element assert list(obj_generate.der) == list(obj_wanted.der) ## ensure same value assert sum( list( map( lambda x: not np.isclose(obj_generate.der[x], obj_wanted.der[x] ), obj_generate.der))) == 0
def test_arcsin_types(): with pytest.raises(TypeError): elem.arcsin("hi")
def test_arcsin_result_var_notvalid(): val = 2 x = Variable('x', val) with pytest.raises(ValueError): obj_generate = elem.arcsin(x)
def test_arcsin_result_constant_notvalid(): with pytest.raises(ValueError): elem.arcsin(2.0)
def test_arcsin_result_constant(): assert np.isclose(elem.arcsin(1.0), np.arcsin(1.0))