Files
solver/tests/test_dof.py
forbes-0023 98051ba0c9 feat: add Phase 1 constraint solver addon, move prior content to GNN/
- Move existing OndselSolver, GNN ML layer, and tooling into GNN/
  directory for integration in later phases
- Add Create addon scaffold: package.xml, Init.py
- Add expression DAG with eval, symbolic diff, simplification
- Add parameter table with fixed/free variable tracking
- Add quaternion rotation as polynomial Expr trees
- Add RigidBody entity (7 DOF: position + unit quaternion)
- Add constraint classes: Coincident, DistancePointPoint, Fixed
- Add Newton-Raphson solver with symbolic Jacobian + numpy lstsq
- Add pre-solve passes: substitution + single-equation
- Add DOF counting via Jacobian SVD rank
- Add KindredSolver IKCSolver bridge for kcsolve integration
- Add 82 unit tests covering all modules

Registers as 'kindred' solver via kcsolve.register_solver() when
loaded by Create's addon_loader.
2026-02-20 20:35:47 -06:00

50 lines
1.5 KiB
Python

"""Tests for DOF counting."""
import pytest
from kindred_solver.dof import count_dof
from kindred_solver.expr import Const, Var
from kindred_solver.params import ParamTable
class TestDOF:
def test_unconstrained(self):
"""2 free params, no residuals → DOF = 2."""
pt = ParamTable()
pt.add("x", 0.0)
pt.add("y", 0.0)
assert count_dof([], pt) == 2
def test_fully_constrained(self):
"""1 free param, 1 independent residual → DOF = 0."""
pt = ParamTable()
x = pt.add("x", 1.0)
residuals = [x - Const(3.0)]
assert count_dof(residuals, pt) == 0
def test_under_constrained(self):
"""2 free params, 1 residual → DOF = 1."""
pt = ParamTable()
x = pt.add("x", 1.0)
y = pt.add("y", 1.0)
residuals = [x + y - Const(5.0)]
assert count_dof(residuals, pt) == 1
def test_redundant_constraints(self):
"""2 free params, 3 residuals (2 independent) → DOF = 0."""
pt = ParamTable()
x = pt.add("x", 1.0)
y = pt.add("y", 1.0)
residuals = [
x - Const(3.0),
y - Const(4.0),
x + y - Const(7.0), # redundant (sum of first two)
]
assert count_dof(residuals, pt) == 0
def test_no_free_params(self):
"""All fixed → DOF = 0."""
pt = ParamTable()
pt.add("x", 1.0, fixed=True)
residuals = [Const(0.0)]
assert count_dof(residuals, pt) == 0