Skip to content

Inverting FactorUnitPart calculates the reciprocal of its ratio#28

Closed
zoltan-vespertool wants to merge 1 commit into
masterfrom
inverting-factorunitpart
Closed

Inverting FactorUnitPart calculates the reciprocal of its ratio#28
zoltan-vespertool wants to merge 1 commit into
masterfrom
inverting-factorunitpart

Conversation

@zoltan-vespertool

Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings May 12, 2026 12:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 new FactorUnitPart with 1 / 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());
Comment thread tests/UnitTest.php
$inverted = $hundredSquareMeters->invert();

$this->assertEquals(-2, $inverted->getDimensions()[Dimension::LENGTH->name]);
$this->assertEquals(0.01, $inverted->getRatio());
Comment thread tests/UnitTest.php
Comment on lines +197 to +198
$this->assertEquals($invertedTwice->getRatio(), $hundredSquareMeters->getRatio());
$this->assertEquals($invertedTwice->getDimensions(), $hundredSquareMeters->getDimensions());
@zoltan-vespertool

zoltan-vespertool commented May 12, 2026

Copy link
Copy Markdown
Author

Closing as incorporated into #29

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