Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tests/test_universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from physics import PosVel
from ship import PlayerConfig, PlayerShip
from universe import Planet, PlanetConfig, Universe
from universe import Planet, PlanetConfig, Star, Universe, UniverseOptions


def test_mutual_bounce(monkeypatch: pytest.MonkeyPatch) -> None:
Expand Down Expand Up @@ -180,6 +180,18 @@ def test_gravitational_well() -> None:
)


@pytest.mark.parametrize("small_universe", [True, False])
def test_star_has_majority_of_mass_in_universe(*, small_universe: bool) -> None:
universe, _ = Universe.from_options(UniverseOptions(small=small_universe, splitscreen=True, invincible=False))
star: Star = getattr(universe, "_Universe__star") # Promise me to NEVER do this outside of tests # noqa: B009
star_mass = star.mass
other_mass = sum(
body.mass for body in chain(universe._player_ships, universe._enemy_ships, *universe._planet_chunks.values())
)
total_mass = star_mass + other_mass
assert star.mass / total_mass > 0.99, "Universe's star should contain most of the mass"


def test_planet_generation() -> None:
# Test that planets generated by generate_planet are not too large or too small.

Expand Down