Skip to content

test: cover IVector*/Magnitude/Dot/Cross and semantic overload conversions#66

Merged
matt-edmondson merged 1 commit intovectorsfrom
work/issue-54-55
May 9, 2026
Merged

test: cover IVector*/Magnitude/Dot/Cross and semantic overload conversions#66
matt-edmondson merged 1 commit intovectorsfrom
work/issue-54-55

Conversation

@matt-edmondson
Copy link
Copy Markdown
Contributor

Summary

Closes #54 and #55.

Adds Semantics.Test/Quantities/ with two test classes that exercise the unified-vector physics surface end-to-end. No source-generator changes — these tests run against today's emitted code.

VectorQuantityTests (#54)

  • Magnitude: Velocity3D(3,4,0).Magnitude() == Speed(5); works on negative components (Force3D(-3,-4,0).Magnitude() == 5); statically returns the V0 base type; zero vector → zero magnitude.
  • Cross-dimensional Dot/Cross: Force3D.Dot(Displacement3D) == Energy (aligned and perpendicular cases); Force3D.Cross(Displacement3D) == Torque3D; f.Cross(f) == zero.
  • Same-dimension Dot returns the raw storage scalar (no "Speed²" type exists).
  • Vector arithmetic: +, -, unary - preserve dimension and are componentwise.
  • V0 + V0 stays the same V0.
  • Velocity1D.Magnitude of negative value returns positive Speed.

SemanticOverloadTests (#55)

  • Implicit widening: Weight → ForceMagnitude, Distance/Diameter → Length.
  • Explicit narrowing: (Weight)forceMagnitude, (Distance)length.
  • From(base) factory: Weight.From(forceMagnitude), Distance.From(length).
  • Round-trip widen/narrow preserves value.
  • Diameter ↔ Radius via metadata-defined relationships.
  • Storage-type genericity (float, decimal).

Ignored tests (TDD targets for open issues)

These tests are marked [Ignore] with a message linking to the issue, so they don't fail CI today but become unignored when the corresponding fix lands.

The Weight - Weight subtraction currently returns Force1D (the generator's old "option 4" choice from the original strategy doc). One test documents that behaviour and notes #52 as the follow-up — when #52 is implemented, this test will be replaced with the correct Weight - Weight => Weight shape.

Test plan

  • CI runs the new test suite.
  • All non-[Ignore] tests pass (they exercise existing API).
  • The two [Ignore] tests appear in the runner output as skipped, with the issue numbers visible.

🤖 Generated by Claude Code


Generated by Claude Code

Add Semantics.Test/Quantities/ with two test classes that exercise the
unified-vector physics surface end-to-end:

VectorQuantityTests (issue #54)
- Velocity3D.Magnitude(3,4,0) == Speed(5).
- Force3D.Magnitude with negative components is non-negative.
- Magnitude statically returns the V0 base type (Speed for Velocity3D).
- Cross-dimensional Dot: Force3D.Dot(Displacement3D) == Energy.
- Cross-dimensional Cross: Force3D.Cross(Displacement3D) == Torque3D, with
  perpendicular and parallel cases.
- Same-dimension Dot returns the raw storage scalar (no "Speed²" type).
- Vector arithmetic preserves dimension and is componentwise.
- Velocity1D.Magnitude on negative values returns positive Speed (T.Abs).
- V0 + V0 stays the same V0.

SemanticOverloadTests (issue #55)
- Implicit widening of overloads to base (Weight -> ForceMagnitude,
  Distance/Diameter -> Length).
- Explicit narrowing from base (ForceMagnitude -> Weight,
  Length -> Distance).
- From(base) factory.
- Round-trip widen/narrow preserves value.
- Diameter <-> Radius via metadata-defined relationships.
- Float and decimal storage genericity sanity checks.

Two ignored tests serve as TDD targets tied to open issues:
- Mass(3) - Mass(5) should return Mass(2), not Mass(-2): tracked in #52.
- Speed.FromMetersPerSecond(-1) and Mass.FromKilogram(-1) should throw
  ArgumentException: tracked in #50.

The Weight - Weight subtraction currently returns Force1D (the generator's
old "option 4" choice). The test documents that behaviour and links the
follow-up work to #52.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 9, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
0.0% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants