def test_get_labels(): X = ADnum(1, der=1) Y = ADmath.sin(X) + 3 labs = ADgraph.get_labels(Y) assert labs[X] == 'X0' assert labs[Y] == 'X2' assert len(labs) == 4
def test_get_colorsandsizes(): X = ADnum(1, der=1) Y = ADmath.sin(X) + 3 labs = ADgraph.get_labels(Y) G = ADgraph.gen_graph(Y) cols = ADgraph.get_colors(G, Y) sizes = ADgraph.get_sizes(G, Y, labs) assert len(cols) == 4 assert len(sizes) == 4
def test_ADmath_tanh(): f = ADmath.tanh(ADnum(-5, der=1)) assert f.val == np.tanh(-5) assert f.der == 1 / (np.cosh(-5)**2) assert len(f.graph) == 1
def test_gen_table(): X = ADnum(1, der=1) Y = ADmath.sin(X) + 3 dat = ADgraph.gen_table(Y) assert type(dat) == pandas.core.frame.DataFrame
def test_2xe2x(): x = ADnum(2, der=1) f = 2 * x * ADmath.exp(2 * x) assert f.val == 4 * np.exp(4) assert f.der == 2 * np.exp(4.0) + 8 * np.exp(4)
def test_5x2lnx(): x = ADnum(1, der=1) f = 5 * x**2 * ADmath.log(x) assert f.val == 0.0 assert f.der == 10 * 1.0 * np.log(1.0) + 5 * 1.0
def test_ADmath_sqrtr(): f = ADmath.sqrt(40) assert f == np.sqrt(40)
def test_ADmath_expr(): f = ADmath.exp(-3) assert f == np.exp(-3)
def test_ADmath_tanr(): f = ADmath.tan(4) assert f == np.tan(4)
def test_ADmath_cosr(): f = ADmath.cos(4) assert f == np.cos(4)
def test_ADmath_sinr(): X = np.pi Y = ADmath.sin(X) assert Y == np.sin(np.pi)
def test_ADmath_sqrt(): f = ADmath.sqrt(ADnum(40, der=1)) assert f.val == np.sqrt(40) assert f.der == 1 / (2 * np.sqrt(40)) assert len(f.graph) == 1
def test_ADmath_logistic(): f = ADmath.logistic(ADnum(0, der=1)) assert f.val == .5 assert f.der == .25
def test_ADmath_log(): f = ADmath.log(ADnum(72, der=1)) assert f.val == np.log(72) assert f.der == 1 / 72 assert len(f.graph) == 1
def test_ADmath_exp(): f = ADmath.exp(ADnum(-3, der=1)) assert f.val == np.exp(-3) assert f.der == np.exp(-3) assert len(f.graph) == 1
def test_ADmath_coshr(): f = ADmath.cosh(3) assert f == np.cosh(3)
def test_ADmath_tanhr(): f = ADmath.tanh(-5) assert f == np.tanh(-5)
def test_ADmath_cscr(): f = ADmath.csc(5) assert f == 1 / np.sin(5)
def test_ADmath_logr(): f = ADmath.log(72) assert f == np.log(72)
def test_ADmath_secr(): f = ADmath.sec(6) assert f == 1 / np.cos(6)
def test_xex(): x = ADnum(2, der=1) f = x * ADmath.exp(x) assert f.val == 2.0 * np.exp(2.0) assert f.der == np.exp(2.0) + 2.0 * np.exp(2.0)
def test_ADmath_cotr(): f = ADmath.cot(1) assert f == 1 / np.tan(1)
def test_sinxcosx(): x = ADnum(0, der=1) f = ADmath.sin(x) * ADmath.cos(x) assert f.val == np.sin(0) * np.cos(0) assert f.der == -(np.sin(0)**2) + np.cos(0)**2
def test_ADmath_arcsinr(): f = ADmath.arcsin(.2) assert f == np.arcsin(.2)
def test_ADmath_arccosr(): f = ADmath.arccos(.3) assert f == np.arccos(.3)
def test_ADmath_arctanr(): f = ADmath.arctan(1) assert f == np.arctan(1)
def test_draw_graph(): X = ADnum(1, der=1) Y = ADmath.sin(X) + 3 fig = ADgraph.draw_graph(Y) assert type(fig) == matplotlib.figure.Figure
def test_ADmath_sinhr(): f = ADmath.sinh(2) assert f == np.sinh(2)
def Y(x): return ADmath.sin(x)
def test_ADmath_cosh(): f = ADmath.cosh(ADnum(3, der=1)) assert f.val == np.cosh(3) assert f.der == np.sinh(3) assert len(f.graph) == 1