Repository navigation
Test unit definitions for wrong base units and ambiguous abbreviations - #1744
Open
tmilnthorp wants to merge 2 commits into
Open
tmilnthorp wants to merge 2 commits into
tmilnthorp wants to merge 2 commits into
Conversation
The conversion tests compare each unit against test values, but nothing checks a unit's BaseUnits against its conversion, or that its abbreviations can be parsed unambiguously. Add tests that check every quantity: - The factor implied by each unit's BaseUnits matches its conversion, relative to the quantity's other units. - No two units of a quantity share an abbreviation in any culture. - Abbreviations use the micro sign (U+00B5) like the generated prefixes, not the Greek letter mu (U+03BC), which parsing treats differently. Existing violations are listed as known, with the reason for each, so the tests catch new mistakes while those are fixed separately. Another test fails when a known violation is fixed but still listed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1744 +/- ##
======================================
Coverage 98% 98%
======================================
Files 515 515
Lines 24092 24092
======================================
Hits 23692 23692
Misses 400 400
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
On .NET Framework, the test runner can shadow copy UnitsNet.dll without its satellite assemblies, so looking next to it found only en-US and the abbreviation tests skipped the other cultures. Look in the test output directory instead, and fail if a localized culture isn't found. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The conversion tests check each unit against test values, but some mistakes in the unit definitions slip past them:
BaseUnitsthat don't match the unit's conversion, like Tesla in Fix Tesla BaseUnits to match MagneticField dimensions #1734.This adds
UnitDefinitionsTests, which checks every quantity at runtime. The tests need no network, tools or secrets, so they run on every PR, including from forks.Checks
BaseUnitsgive the unit's conversion factor. The factor of a unit made of itsBaseUnits(e.g. foot and second forFootPerSecond) must match its actual conversion. Units are compared with the quantity's unit made of SI base units, or with each other if there is none, because a quantity's base unit isn't always made of SI base units. The factors are computed exactly from the conversion expressions. Affine units compare the size of the degree, and logarithmic units are skipped.UnitAbbreviationsCache, including its fallback to en-US, so it sees what parsing sees.A/µsdoesn't matchA/μs.Existing violations
The tests found these, which are listed as known with the reason for each, so the tests pass today and catch new mistakes:
BaseUnits(their conversions are correct):Radioactivity: the curie and rutherford, and their prefixed units, are defined as 1 per second.RadiationExposure: the roentgen is defined as 1 C/kg instead of 2.58e-4.ElectricPotentialChangeRate: the units per minute, hour and microsecond, where time has exponent −4.PressureChangeRate: the units per minute, and pound-force taken as pound.HeatFlux: the units per square millimeter.FluidResistance: three units.Acceleration: knot per second and per minute.AreaDensity.PoundPerThousandSquareFeetandVolumePerLength.LiterPerMeter.ptandpica(DTP and printer's point;UnitParserTestscovers this case).cwt(long and short hundredweight).кгс(kilogram-force and kilopond, which are the same unit).英亩, which means acre.纳米, which means nanometer.мил, the same as Mil.GraySquareMicrometer,AmperePerMicrosecond,VoltPerMicrosecondandGramPerMicroliter.A fourth test fails when a listed violation no longer occurs, so fixing one also means removing it from its list, and the lists only shrink. I plan to fix these in follow-up PRs: the localizations and micro signs first, then the
BaseUnits. TheBaseUnitsfixes change whatGetUnitInfoFor(BaseUnits)andToUnit(UnitSystem)return for those units.Not covered
BaseUnitsdon't cover the quantity's dimensions, such as Tesla andStandardVolumeFlow. Their factors can't be compared. Fix Tesla BaseUnits to match MagneticField dimensions #1734 adds a test for that.SpecificFuelConsumptionhasBaseUnitsmeter and second, but no other unit of that quantity hasBaseUnits.Testing
Radioactivity.Curie: BaseUnits T=Second give 1 Becquerel, but its conversion gives 3.7E+10 (compared to Becquerel).Length.Foot'sBaseUnitsto inch in the JSON.🤖 Generated with Claude Code
https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG