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_NumberPlane():
    """Test that NumberPlane generates the correct number of lines when its ranges do not cross 0."""
    pos_x_range = (0, 7)
    neg_x_range = (-7, 0)

    pos_y_range = (2, 6)
    neg_y_range = (-6, -2)

    testing_data = [
        (pos_x_range, pos_y_range),
        (pos_x_range, neg_y_range),
        (neg_x_range, pos_y_range),
        (neg_x_range, neg_y_range),
    ]

    for test_data in testing_data:

        x_range, y_range = test_data

        x_start, x_end = x_range
        y_start, y_end = y_range

        plane = NumberPlane(
            x_range=x_range,
            y_range=y_range,
            # x_length = 7,
            axis_config={"include_numbers": True},
        )

        # normally these values would be need to be added by one to pass since there's an
        # overlapping pair of lines at the origin, but since these planes do not cross 0,
        # this is not needed.
        num_y_lines = math.ceil(x_end - x_start)
        num_x_lines = math.floor(y_end - y_start)

        assert len(plane.y_lines) == num_y_lines
        assert len(plane.x_lines) == num_x_lines

    plane = NumberPlane((-5, 5, 0.5),
                        (-8, 8, 2))  # <- test for different step values
    # horizontal lines: -6 -4, -2, 0, 2, 4, 6
    assert len(plane.x_lines) == 7
    # vertical lines: 0, +-0.5, +-1, +-1.5, +-2, +-2.5,
    # +-3, +-3.5, +-4, +-4.5
    assert len(plane.y_lines) == 19
def test_NumberPlane(using_opengl_renderer):
    """Test that NumberPlane generates the correct number of lines when its ranges do not cross 0."""
    pos_x_range = (0, 7)
    neg_x_range = (-7, 0)

    pos_y_range = (2, 6)
    neg_y_range = (-6, -2)

    x_vals = [0, 1.5, 2, 2.8, 4, 6.25]
    y_vals = [2, 5, 4.25, 6, 4.5, 2.75]

    testing_data = [
        (pos_x_range, pos_y_range, x_vals, y_vals),
        (pos_x_range, neg_y_range, x_vals, [-v for v in y_vals]),
        (neg_x_range, pos_y_range, [-v for v in x_vals], y_vals),
        (neg_x_range, neg_y_range, [-v for v in x_vals], [-v for v in y_vals]),
    ]

    for test_data in testing_data:

        x_range, y_range, x_vals, y_vals = test_data

        x_start, x_end = x_range
        y_start, y_end = y_range

        plane = NumberPlane(
            x_range=x_range,
            y_range=y_range,
            # x_length = 7,
            axis_config={"include_numbers": True},
        )

        # normally these values would be need to be added by one to pass since there's an
        # overlapping pair of lines at the origin, but since these planes do not cross 0,
        # this is not needed.
        num_y_lines = math.ceil(x_end - x_start)
        num_x_lines = math.floor(y_end - y_start)

        assert len(plane.y_lines) == num_y_lines
        assert len(plane.x_lines) == num_x_lines

    plane = NumberPlane((-5, 5, 0.5),
                        (-8, 8, 2))  # <- test for different step values
    assert len(plane.x_lines) == 8
    assert len(plane.y_lines) == 20
def test_coords_to_point_vectorized():
    plane = NumberPlane(x_range=[2, 4])

    origin = plane.x_axis.number_to_point(
        plane._origin_shift([plane.x_axis.x_min, plane.x_axis.x_max]), )

    def ref_func(*coords):
        result = np.array(origin)
        for axis, number in zip(plane.get_axes(), coords):
            result += axis.number_to_point(number) - origin
        return result

    coords = [[1], [1, 2], [2, 2], [3, 4]]

    print(f"\n\nTesting coords_to_point {coords}")
    expected = np.round([ref_func(*coord) for coord in coords], 4)
    actual1 = np.round([plane.coords_to_point(*coord) for coord in coords], 4)
    coords[0] = [
        1,
        0,
    ]  # Extend the first coord because you can't vectorize items with different dimensions
    actual2 = np.round(plane.coords_to_point(coords),
                       4)  # Test [x_0,y_0,z_0], [x_1,y_1,z_1], ...
    actual3 = np.round(plane.coords_to_point(*np.array(coords).T),
                       4)  # Test [x_0,x_1,...], [y_0,y_1,...], ...
    print(actual3)

    np.testing.assert_array_equal(expected, actual1)
    np.testing.assert_array_equal(expected, actual2)
    np.testing.assert_array_equal(expected, actual3.T)