def test_equations_slice(): A = System() A[0:3] = (2 * A.x, 3 * A.y, 4 * A.z) assert A[A[0]] == [sympy.Eq(A[0], 2 * A.x)] assert A[A[1]] == [sympy.Eq(A[1], 3 * A.y)] assert A[A[2]] == [sympy.Eq(A[2], 4 * A.z)] A[1:6:2] = (20 * A.x, 30 * A.y, 40 * A.z) assert A[A[1]] == [sympy.Eq(A[1], 20 * A.x)] assert A[A[3]] == [sympy.Eq(A[3], 30 * A.y)] assert A[A[5]] == [sympy.Eq(A[5], 40 * A.z)] def badassign(): A[0:3] = (2 * A.x, 3 * A.y) assert raises(ValueError, badassign) def badassign(): A[0:3] = (2 * A.x, 3 * A.y, 4 * A.x, 5 * A.y) assert raises(ValueError, badassign) def badassign(): A[0:] = (2 * A.x, 3 * A.y) assert raises(ValueError, badassign)
def test_attributes(): x2 = eqpy.dummies.x2 assert x2 is not sympy.Dummy('x2') assert raises(AttributeError, lambda: eqpy.dummies.__dunder_should_fail__) assert isinstance(x2, sympy.Dummy) ex2 = eqpy.dummies.x2 assert x2 is not ex2
def test_slice_get(): A = System() x0, x1 = A[:2] assert x0 is A[0] assert x1 is A[1] y1, y2 = A[1:3] assert y1 is x1 z0, z2 = A[:3:2] assert z2 is y2 z2, z4 = A[2:5:2] assert z2 is y2 z2, z1 = A[2:0:-1] assert z2 is y2 assert raises(ValueError, lambda: A[0::2]) assert raises(ValueError, lambda: A[::2]) assert raises(ValueError, lambda: A[0::]) assert raises(ValueError, lambda: A[::])
def test_slice_get(): A = System() x0, x1 = A[:2] assert x0 is A[0] assert x1 is A[1] y1, y2 = A[1:3] assert y1 is x1 z0, z2 = A[:3:2] assert z2 is y2 z2, z4 = A[2:5:2] assert z2 is y2 z2, z1 = A[2:0:-1] assert z2 is y2 assert raises(ValueError, lambda: A[0::2]) assert raises(ValueError, lambda: A[::2]) assert raises(ValueError, lambda: A[0::]) assert raises(ValueError, lambda: A[::])
def test_equations_slice(): A = System() A[0:3] = (2*A.x, 3*A.y, 4*A.z) assert A[A[0]] == [sympy.Eq(A[0], 2*A.x)] assert A[A[1]] == [sympy.Eq(A[1], 3*A.y)] assert A[A[2]] == [sympy.Eq(A[2], 4*A.z)] A[1:6:2] = (20*A.x, 30*A.y, 40*A.z) assert A[A[1]] == [sympy.Eq(A[1], 20*A.x)] assert A[A[3]] == [sympy.Eq(A[3], 30*A.y)] assert A[A[5]] == [sympy.Eq(A[5], 40*A.z)] def badassign(): A[0:3] = (2*A.x, 3*A.y) assert raises(ValueError, badassign) def badassign(): A[0:3] = (2*A.x, 3*A.y, 4*A.x, 5*A.y) assert raises(ValueError, badassign) def badassign(): A[0:] = (2*A.x, 3*A.y) assert raises(ValueError, badassign)
def test_suffix(): A = System() B = System(suffix='_B') assert A.x_B is B.x assert str(B.x) == 'x_B' assert str(B[0]) == '_0_B' C = System(suffix='_C', suffix_include=['x', 1, '2']) assert str(C.x) == 'x_C' assert str(C.y) == 'y' assert str(C[0]) == '_0' assert str(C[1]) == '_1_C' assert str(C[2]) == '_2' D = System(suffix='_D', suffix_exclude=['x', 1, '2']) assert str(D.x) == 'x' assert str(D.y) == 'y_D' assert str(D[0]) == '_0_D' assert str(D[1]) == '_1' assert str(D[2]) == '_2_D' assert raises(ValueError, lambda: System(suffix='_A', suffix_include=['x'], suffix_exclude=['y']))
def test_prefix(): A = System() B = System(prefix='B_') assert A.B_x is B.x assert str(B.x) == 'B_x' assert str(B[0]) == '_B_0' C = System(prefix='C_', prefix_include=['x', 1, '2']) assert str(C.x) == 'C_x' assert str(C.y) == 'y' assert str(C[0]) == '_0' assert str(C[1]) == '_C_1' assert str(C[2]) == '_2' D = System(prefix='D_', prefix_exclude=['x', 1, '2']) assert str(D.x) == 'x' assert str(D.y) == 'D_y' assert str(D[0]) == '_D_0' assert str(D[1]) == '_1' assert str(D[2]) == '_D_2' assert raises(ValueError, lambda: System(prefix='A_', prefix_include=['x'], prefix_exclude=['y']))
def test_suffix(): A = System() B = System(suffix='_B') assert A.x_B is B.x assert str(B.x) == 'x_B' assert str(B[0]) == '_0_B' C = System(suffix='_C', suffix_include=['x', 1, '2']) assert str(C.x) == 'x_C' assert str(C.y) == 'y' assert str(C[0]) == '_0' assert str(C[1]) == '_1_C' assert str(C[2]) == '_2' D = System(suffix='_D', suffix_exclude=['x', 1, '2']) assert str(D.x) == 'x' assert str(D.y) == 'y_D' assert str(D[0]) == '_0_D' assert str(D[1]) == '_1' assert str(D[2]) == '_2_D' assert raises( ValueError, lambda: System( suffix='_A', suffix_include=['x'], suffix_exclude=['y']))
def test_prefix(): A = System() B = System(prefix='B_') assert A.B_x is B.x assert str(B.x) == 'B_x' assert str(B[0]) == '_B_0' C = System(prefix='C_', prefix_include=['x', 1, '2']) assert str(C.x) == 'C_x' assert str(C.y) == 'y' assert str(C[0]) == '_0' assert str(C[1]) == '_C_1' assert str(C[2]) == '_2' D = System(prefix='D_', prefix_exclude=['x', 1, '2']) assert str(D.x) == 'x' assert str(D.y) == 'D_y' assert str(D[0]) == '_D_0' assert str(D[1]) == '_1' assert str(D[2]) == '_D_2' assert raises( ValueError, lambda: System( prefix='A_', prefix_include=['x'], prefix_exclude=['y']))
def test_raises(): assert not raises(None, lambda: None) assert raises(ZeroDivisionError, lambda: 1/0) assert raises(ZeroDivisionError, lambda: raises(TypeError, lambda: 1/0))
def test_raises(): assert not raises(None, lambda: None) assert raises(ZeroDivisionError, lambda: 1 / 0) assert raises(ZeroDivisionError, lambda: raises(TypeError, lambda: 1 / 0))
def test_sympify(): eqpy.nums.x = '1/2' assert eqpy.nums.x == sympy.S('1/2') assert eqpy.nums('2/3') == sympy.S('2/3') assert raises(sympy.SympifyError, lambda: eqpy.nums('1.2.3'))
def test_attributes(): x2 = eqpy.vars.x2 assert x2 is sympy.Symbol('x2') assert raises(AttributeError, lambda: eqpy.vars.__dunder_should_fail__)