def test_point_to_coords(): ax = Axes(x_range=[0, 10, 2]) circ = Circle(radius=0.5).shift(UR * 2) # get the coordinates of the circle with respect to the axes coords = np.around(ax.point_to_coords(circ.get_right()), decimals=4) np.testing.assert_array_equal(coords, (7.0833, 2.6667))
def test_point_to_coords_vectorized(): ax = Axes(x_range=[0, 10, 2]) circ = Circle(radius=0.5).shift(UR * 2) points = np.array( [circ.get_right(), circ.get_left(), circ.get_bottom(), circ.get_top()]) # get the coordinates of the circle with respect to the axes expected = [ np.around(ax.point_to_coords(point), decimals=4) for point in points ] actual = np.around(ax.point_to_coords(points), decimals=4) np.testing.assert_array_equal(expected, actual)
def test_dimension(): """Check that objects have the correct dimension.""" assert Axes().dimension == 2 assert NumberPlane().dimension == 2 assert PolarPlane().dimension == 2 assert ComplexPlane().dimension == 2 assert ThreeDAxes().dimension == 3
def test_expected_ticks_generated(): axes = Axes(x_range=[-2, 2], y_range=[-2, 2], axis_config={"include_ticks": True}) x_axis_range = axes.x_axis.get_tick_range() y_axis_range = axes.y_axis.get_tick_range() assert 1 in x_axis_range assert 1 in y_axis_range assert -1 in x_axis_range assert -1 in y_axis_range
def test_ticks_not_generated_on_origin_for_axes(): axes = Axes( x_range=[-10, 10], y_range=[-10, 10], axis_config={"include_ticks": True} ) x_axis_range = axes.x_axis.get_tick_range() y_axis_range = axes.y_axis.get_tick_range() assert 0 not in x_axis_range assert 0 not in y_axis_range
def test_initial_config(): """Check that all attributes are defined properly from the config.""" cs = CS() assert cs.x_range[0] == round(-config["frame_x_radius"]) assert cs.x_range[1] == round(config["frame_x_radius"]) assert cs.x_range[2] == 1.0 assert cs.y_range[0] == round(-config["frame_y_radius"]) assert cs.y_range[1] == round(config["frame_y_radius"]) assert cs.y_range[2] == 1.0 ax = Axes() np.testing.assert_allclose(ax.get_center(), ORIGIN) np.testing.assert_allclose(ax.y_axis_config["label_direction"], LEFT) with tempconfig({"frame_x_radius": 100, "frame_y_radius": 200}): cs = CS() assert cs.x_range[0] == -100 assert cs.x_range[1] == 100 assert cs.y_range[0] == -200 assert cs.y_range[1] == 200
def test_ticks_generated_from_origin_for_axes(): axes = Axes( x_range=[-PI, PI], y_range=[-PI, PI], axis_config={"include_ticks": True} ) x_axis_range = axes.x_axis.get_tick_range() y_axis_range = axes.y_axis.get_tick_range() assert -2 in x_axis_range assert -1 in x_axis_range assert 0 not in x_axis_range assert 1 in x_axis_range assert 2 in x_axis_range assert -2 in y_axis_range assert -1 in y_axis_range assert 0 not in y_axis_range assert 1 in y_axis_range assert 2 in y_axis_range
def test_initial_config(): """Check that all attributes are defined properly from the config.""" cs = CS() assert cs.x_min == -config["frame_x_radius"] assert cs.x_max == config["frame_x_radius"] assert cs.y_min == -config["frame_y_radius"] assert cs.y_max == config["frame_y_radius"] ax = Axes() assert np.allclose(ax.center_point, ORIGIN) assert np.allclose(ax.y_axis_config["label_direction"], LEFT) with tempconfig({"frame_x_radius": 100, "frame_y_radius": 200}): cs = CS() assert cs.x_min == -100 assert cs.x_max == 100 assert cs.y_min == -200 assert cs.y_max == 200
def test_input_to_graph_point(using_opengl_renderer): ax = Axes() curve = ax.get_graph(lambda x: np.cos(x)) line_graph = ax.get_line_graph([1, 3, 5], [-1, 2, -2], add_vertex_dots=False)[ "line_graph" ] # move a square to PI on the cosine curve. position = np.around(ax.input_to_graph_point(x=PI, graph=curve), decimals=4) assert np.array_equal(position, (2.6928, -0.75, 0)) # test the line_graph implementation position = np.around(ax.input_to_graph_point(x=PI, graph=line_graph), decimals=4) assert np.array_equal(position, (2.6928, 1.2876, 0))
def test_coords_to_point(): ax = Axes() # a point with respect to the axes c2p_coord = np.around(ax.coords_to_point(2, 2), decimals=4) np.testing.assert_array_equal(c2p_coord, (1.7143, 1.5, 0))
def test_coords_to_point(using_opengl_renderer): ax = Axes() # a point with respect to the axes c2p_coord = np.around(ax.coords_to_point(2, 2), decimals=4) assert np.array_equal(c2p_coord, (1.7143, 1.5, 0))