I love how stupid this project is

si units and redefining speed metric as thrust/weight ratio
This commit is contained in:
2026-03-04 16:30:09 -06:00
parent 216879bdd5
commit 00cc8dd9ef
19 changed files with 494 additions and 341 deletions

102
tests/test_units.py Normal file
View File

@@ -0,0 +1,102 @@
"""Tests for the unit-aware formatter."""
from physcom.units import format_quantity
class TestFormatQuantity:
def test_speed_km_h(self):
"""33.33 m/s should display as ~120 km/h."""
result = format_quantity(33.33, "m/s")
assert "km/h" in result
assert "120" in result
def test_speed_km_s(self):
"""10000 m/s should display as 10 km/s."""
result = format_quantity(10000, "m/s")
assert "km/s" in result
def test_distance_km(self):
"""5000 m should display as 5 km."""
result = format_quantity(5000, "m")
assert "km" in result
assert "5" in result
def test_distance_ly(self):
"""9.461e15 m should display as ~1 ly."""
result = format_quantity(9.461e15, "m")
assert "ly" in result
def test_distance_au(self):
"""1.496e11 m should display as ~1 AU."""
result = format_quantity(1.496e11, "m")
assert "AU" in result
def test_mass_tons(self):
"""5000 kg should display as 5 t."""
result = format_quantity(5000, "kg")
assert "t" in result
def test_mass_kg(self):
"""50 kg should display as 50 kg."""
result = format_quantity(50, "kg")
assert "kg" in result
def test_energy_density_wh_kg(self):
"""720000 J/kg should display as 200 Wh/kg."""
result = format_quantity(720000, "J/kg")
assert "Wh/kg" in result
assert "200" in result
def test_time_days(self):
"""86400 s should display as 1 d."""
result = format_quantity(86400, "s")
assert "d" in result
def test_time_years(self):
"""3.156e7 s should display as ~1 yr."""
result = format_quantity(3.156e7, "s")
assert "yr" in result
def test_cost_per_km(self):
"""$/m always displays as $/km."""
result = format_quantity(0.001, "$/m")
assert "$/km" in result
def test_cost_per_ton_km(self):
"""$/(kg·m) always displays as $/t·km."""
result = format_quantity(1e-6, "$/(kg\u00b7m)")
assert "$/t\u00b7km" in result
def test_emissions_g_per_km(self):
"""kg/m always displays as g/km."""
result = format_quantity(1e-4, "kg/m")
assert "g/km" in result
def test_none_returns_dash(self):
assert format_quantity(None, "m/s") == "\u2014"
def test_dimensionless(self):
"""0-1 unit should just return the number."""
result = format_quantity(0.75, "0-1")
assert result == "0.75"
def test_string_input(self):
"""String values should be converted to float."""
result = format_quantity("5000", "m")
assert "km" in result
def test_non_numeric_string(self):
"""Non-numeric string values returned as-is."""
assert format_quantity("true", "m") == "true"
def test_zero(self):
result = format_quantity(0, "m/s")
assert "m/s" in result
def test_area_m2(self):
result = format_quantity(50, "m\u00b2")
assert "m\u00b2" in result
def test_power_density(self):
result = format_quantity(5000, "W/kg")
assert "kW/kg" in result