Add component database layer and validated physics core
- components/schema.py + database.py: typed loader for real retail parts (wire, capacitors, switches, sensors, projectile materials) - physics/inductance.py: multilayer solenoid inductance (Wheeler) with ferromagnetic-slug coupling via smooth overlap model and analytic dL/dx - physics/force.py: F = 0.5*I^2*dL/dx with a saturation clamp - physics/circuit.py: coupled [Q,I,x,v] discharge ODE - Validated against textbook RLC analytical solutions (under/over/critically damped) and energy conservation, not just spot-checked by eye - PLAN.md updated with animation (per-run field visualization) and GPU-accelerated batch sweep as explicit later stages Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
45
tests/test_database_loading.py
Normal file
45
tests/test_database_loading.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from pathlib import Path
|
||||
|
||||
from gausse.components.database import ComponentDatabase
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures" / "data"
|
||||
|
||||
|
||||
def test_loads_all_component_types():
|
||||
db = ComponentDatabase.load(FIXTURES)
|
||||
assert len(db.wires) == 2
|
||||
assert len(db.capacitors) == 1
|
||||
assert len(db.switches) == 1
|
||||
assert len(db.sensors) == 2
|
||||
assert len(db.projectile_materials) == 1
|
||||
|
||||
|
||||
def test_wires_by_material_filters_correctly():
|
||||
db = ComponentDatabase.load(FIXTURES)
|
||||
copper = db.wires_by_material("copper")
|
||||
assert len(copper) == 1
|
||||
assert copper[0].part_id == "test-cu-0.5"
|
||||
|
||||
|
||||
def test_capacitors_rated_at_least_filters_by_voltage():
|
||||
db = ComponentDatabase.load(FIXTURES)
|
||||
assert len(db.capacitors_rated_at_least(400.0)) == 1
|
||||
assert len(db.capacitors_rated_at_least(500.0)) == 0
|
||||
|
||||
|
||||
def test_switches_rated_for_current_and_voltage():
|
||||
db = ComponentDatabase.load(FIXTURES)
|
||||
assert len(db.switches_rated_for(20.0, 500.0)) == 1
|
||||
assert len(db.switches_rated_for(30.0, 500.0)) == 0
|
||||
|
||||
|
||||
def test_sensors_by_kind():
|
||||
db = ComponentDatabase.load(FIXTURES)
|
||||
assert len(db.sensors_by_kind("optical")) == 1
|
||||
assert len(db.sensors_by_kind("inductive")) == 1
|
||||
|
||||
|
||||
def test_missing_data_dir_returns_empty_database(tmp_path):
|
||||
db = ComponentDatabase.load(tmp_path)
|
||||
assert db.wires == []
|
||||
assert db.capacitors == []
|
||||
Reference in New Issue
Block a user