Skip to content

Fix Tesla BaseUnits to match MagneticField dimensions - #1734

Open
tmilnthorp wants to merge 1 commit into
angularsen:masterfrom
tmilnthorp:tmilntho/tesla-baseunits
Open

tmilnthorp wants to merge 1 commit into
angularsen:masterfrom
tmilnthorp:tmilntho/tesla-baseunits

Conversation

@tmilnthorp

Copy link
Copy Markdown
Collaborator

Summary

MagneticField is dimensioned as M·T⁻²·I⁻¹ (tesla = kg·s⁻²·A⁻¹), but the Tesla unit's BaseUnits were defined as meter, kilogram and ampere. That's length instead of time. The wrong set also carried over to the derived BaseUnits of nanotesla, microtesla and millitesla.

- new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, current: ElectricCurrentUnit.Ampere)
+ new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)

Changes

  • Common/UnitDefinitions/MagneticField.json: replace L: Meter with T: Second in Tesla's BaseUnits.
  • Regenerated MagneticField.g.cs. Only the four tesla-family BaseUnits lines change.
  • New test UnitBaseUnits_CoverExactlyTheQuantityBaseDimensions: for every quantity, each unit with defined BaseUnits must specify exactly the base dimensions the quantity has.
    • StandardVolumeFlow is exempt. It is dimensioned as mass flow (M·T⁻¹), but its units are defined by standard volume (L³·T⁻¹), so its BaseUnits intentionally differ.

Testing

  • New test: 129/129 pass with the fix. Reverting the JSON change makes it fail on MagneticField.
  • Full UnitsNet.Tests on net10.0: 52,558 passed, 2 failed. The two failures are FeetInchesTests.TryParseFeetInches with de-CH. They fail the same way on unmodified master (see draft Fix feet/inches parsing with apostrophe grouping #1724).

🤖 Generated with Claude Code

https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG

Tesla is kg·s⁻²·A⁻¹, but its BaseUnits were defined as meter, kilogram
and ampere: length instead of time. This also propagated to the derived
BaseUnits of nanotesla, microtesla and millitesla.

Add a test that every unit's BaseUnits covers exactly its quantity's
BaseDimensions. StandardVolumeFlow is exempt, since it is dimensioned as
mass flow while its units are defined by standard volume.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG
@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98%. Comparing base (3bf1ef4) to head (c5b9bb4).

Additional details and impacted files
@@          Coverage Diff           @@
##           master   #1734   +/-   ##
======================================
  Coverage      98%     98%           
======================================
  Files         515     515           
  Lines       24092   24092           
======================================
  Hits        23692   23692           
  Misses        400     400           
Flag Coverage Δ
net48 97% <100%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

1 participant