Skip to content

Commit

Permalink
Issue-4087 Improve previous test instead of adding a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
gvauvert committed Jan 3, 2025
1 parent 5f698ea commit 6792aff
Showing 1 changed file with 12 additions and 33 deletions.
45 changes: 12 additions & 33 deletions tests/module/mobject/mobject/test_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pytest

from manim import DL, UR, Circle, Mobject, Rectangle, Square, VGroup
from manim import DL, DR, UL, UR, Circle, Mobject, Rectangle, Square, VGroup


def test_mobject_add():
Expand Down Expand Up @@ -136,18 +136,19 @@ def test_mobject_dimensions_nested_mobjects():


def test_mobject_dimensions_mobjects_with_no_points_are_at_origin():
rect = Rectangle(width=2, height=3)
rect.move_to([-4, -5, 0])
outer_group = VGroup(rect)
for direction in [DL, DR, UL, UR]:
rect = Rectangle(width=2, height=3)
rect.move_to(direction * 10)
outer_group = VGroup(rect)

# This is as one would expect
assert outer_group.width == 2
assert outer_group.height == 3
# This is as one would expect
assert outer_group.width == 2
assert outer_group.height == 3

# Adding a mobject with no points does not change its size
outer_group.add(VGroup())
assert outer_group.width == 2
assert outer_group.height == 3
# Adding a mobject with no points does not change its size
outer_group.add(VGroup())
assert outer_group.width == 2
assert outer_group.height == 3


def test_mobject_dimensions_has_points_and_children():
Expand All @@ -165,25 +166,3 @@ def test_mobject_dimensions_has_points_and_children():
assert inner_rect.width == 2
assert inner_rect.height == 1
assert inner_rect.depth == 0


def test_mobject_width_height():
for flow_order in ["ur", "dl"]:
for is_reversed in [False, True]:
# create a vgroup with some sub-elements
vgroup = VGroup()
sub_vgroup = VGroup()
square = Square(side_length=2.0)
sub_elements = [sub_vgroup, square]
if is_reversed:
sub_elements.reverse()
vgroup.add(sub_elements)
# arrange them to move sub-objects all above or below zero
direction = UR if flow_order == "ur" else DL
vgroup.shift(direction * 10)
vgroup.arrange_in_grid(rows=2, cols=2, flow_order=flow_order)
# These measures should be 2.
assert vgroup.length_over_dim(0) == pytest.approx(2.0)
assert vgroup.length_over_dim(1) == pytest.approx(2.0)
assert vgroup.height == pytest.approx(2.0)
assert vgroup.width == pytest.approx(2.0)

0 comments on commit 6792aff

Please sign in to comment.