Inverting FactorUnitPart calculates the reciprocal of its ratio#28
Closed
zoltan-vespertool wants to merge 1 commit into
Closed
Inverting FactorUnitPart calculates the reciprocal of its ratio#28zoltan-vespertool wants to merge 1 commit into
zoltan-vespertool wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates unit inversion behavior so that inverting a FactorUnitPart returns a FactorUnitPart with a reciprocal ratio (instead of producing a generic UnitPart with a negated power), and adds tests to validate inversion behavior at both Unit and FactorUnitPart levels.
Changes:
- Add
FactorUnitPart::invert()override to return a newFactorUnitPartwith1 / ratio. - Add unit tests for
Unit::invert()covering factor + dimension combinations and double-inversion. - Add a unit test for
FactorUnitPart::invert()to validate type, ratio, dimension, and power.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/FactorUnitPart.php | Overrides invert() to preserve FactorUnitPart semantics and compute reciprocal ratio. |
| tests/FactorUnitPartTest.php | Adds coverage for FactorUnitPart::invert() behavior. |
| tests/UnitTest.php | Adds coverage for unit inversion involving factor parts and repeated inversion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| $factorInverted = $factor->invert(); | ||
|
|
||
| $this->assertEquals(FactorUnitPart::class, get_class($factorInverted)); |
|
|
||
| $this->assertEquals(FactorUnitPart::class, get_class($factorInverted)); | ||
| $this->assertNull($factorInverted->getDimension()); | ||
| $this->assertEquals(0.01, $factorInverted->getRatio()); |
| $inverted = $hundredSquareMeters->invert(); | ||
|
|
||
| $this->assertEquals(-2, $inverted->getDimensions()[Dimension::LENGTH->name]); | ||
| $this->assertEquals(0.01, $inverted->getRatio()); |
Comment on lines
+197
to
+198
| $this->assertEquals($invertedTwice->getRatio(), $hundredSquareMeters->getRatio()); | ||
| $this->assertEquals($invertedTwice->getDimensions(), $hundredSquareMeters->getDimensions()); |
Author
|
Closing as incorporated into #29 |
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.
No description provided.