def orthogonal_decompostion(): echo_function("orthogonal_decomposition") v = Vector(2, 3) perp, parall = v.decomposition(Segment(Point(0, 0), Point(0, 1))) echo_single_test("In the Y direction") ans_parall = AffineVector(Point(0, 0), Point(0, 3)) ans_perp = AffineVector(Point(0, 0), Point(2, 0)) assert_true(parall + perp == v) assert_equal(parall, ans_parall) assert_equal(perp, ans_perp) P = Point(0, 2) seg = Segment(P, P.get_polar_point(2, -130)) Q = seg.get_point_proportion(0.5) v = AffineVector(Q, Point(Q.x - 1, Q.y)) perp, paral = v.decomposition(seg) echo_single_test("130 degree : sum") assert_equal(perp + paral, v) echo_single_test("130 degree : orthogonal") assert_true(perp.segment.is_almost_orthogonal(seg, epsilon=0.0001)) ip = perp.inner_product(paral) echo_single_test("130 degree : inner product 1") assert_equal(perp.inner_product(paral), 0) echo_single_test("130 degree : inner product 2") assert_equal(paral.inner_product(perp), 0)
def test_text_parenthesis(): echo_function("test_text_parenthesis") text = "\subfigure[more points (5000)]{%" fd = TestRecall.TikzDecomposition(text) assert_true(fd.points_list == []) assert_true(len(fd.texts_list) == 2) assert_equal(fd.texts_list[0], "\subfigure[more points ") assert_equal(fd.texts_list[1], "5000)]{%")
def test_reverse(): echo_function("test_reverse") x = var('x') curve = ParametricCurve(cos(x), sin(x)).graph(0, 2 * pi).reverse() f1 = cos(-x) f2 = sin(-x) assert_true(curve.f1.sage == f1) assert_true(curve.f2.sage == f2)
def testFGetMinMaxData(): echo_function("testFGetMinMaxData") x, y = var('x,y') F = ImplicitCurve(x**2+y**2 == sqrt(2), (x, -5, 5), (y, -4, 4), plot_points=300) F.plot_points = 10 d = F.get_minmax_data() ans_d = {'xmax': 1.1885897706607917, 'xmin': -1.1885897706608, 'ymax': 1.188452472892108, 'ymin': -1.1884524728921004} assert_true(d == ans_d, failure_message="get_min_max data badly computed.")
def test_is_negative(): echo_function("test_is_negative") echo_single_test("some values") a = -sin(0.5 * pi) assert_true(numerical_is_negative(a)) a = -pi assert_true(numerical_is_negative(a)) a = pi assert_false(numerical_is_negative(a)) echo_single_test("zero is not negative") assert_false(numerical_is_negative(0))
def test_is_negative(): from phystricks.src.Numerical import numerical_is_negative echo_function("test_is_negative") echo_single_test("some values") a = -sin(0.5 * pi) assert_true(numerical_is_negative(a)) a = -pi assert_true(numerical_is_negative(a)) a = pi assert_false(numerical_is_negative(a)) echo_single_test("zero is not negative") assert_false(numerical_is_negative(0))
def comparison(): echo_function("comparison") alpha=AngleMeasure(value_degree=30) beta=AngleMeasure(value_radian=pi/2) assert_true(alpha<beta) assert_true(alpha<=alpha) assert_true(alpha==alpha) assert_false(alpha==beta) assert_true(alpha>=alpha)
def test_non_equalities(): echo_function("test_non_equalities") A = Point(0, 0) B = Point(4.00000000000000 * cos(0.111111111111111 * pi), 0) echo_single_test("difficult not 'almost equal'") assert_false(A.is_almost_equal(B)) echo_single_test("difficult not 'really equal'") assert_false(A == B) v = AffineVector(A, B) u = AffineVector(B, A) w = AffineVector(A, -B) echo_single_test("difficult not 'almost equal' for affine vector") assert_false(v.is_almost_equal(w)) echo_single_test("difficult 'almost equal' for affine vector") assert_true(w.is_almost_equal(-v))
def test_decorator(): echo_function("test_decorator") v = AffineVector(Point(1, 1), Point(2, 2)) echo_single_test("initial value : None") assert_true(v.parameters.color == None) assert_true(v.parameters.style == None) v.parameters.color = "foo" v.parameters.style = "bar" echo_single_test("after fix_origin") w = v.fix_origin(Point(3, 4)) assert_true(w.parameters.color == "foo") assert_true(w.parameters.style == "bar")