Skip to content

Commit

Permalink
Merge pull request #135 from DrDaleks/master
Browse files Browse the repository at this point in the history
QuantityDimension: Fixed divide(Dimension dim) where dim is a product
  • Loading branch information
keilw authored Sep 18, 2018
2 parents 5ab3fc2 + 347cc50 commit ceea0c2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import tech.units.indriya.AbstractUnit;
import tech.units.indriya.unit.BaseUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.Units;

import java.io.Serializable;
Expand Down Expand Up @@ -220,7 +221,7 @@ public QuantityDimension multiply(QuantityDimension that) {
* @since 1.0
*/
public Dimension divide(Dimension that) {
return this.multiply(that.pow(-1));
return that instanceof QuantityDimension ? this.divide((QuantityDimension) that) : this.divide(that);
}

/**
Expand All @@ -232,7 +233,7 @@ public Dimension divide(Dimension that) {
* @since 1.0
*/
public QuantityDimension divide(QuantityDimension that) {
return this.multiply(that.pow(-1));
return new QuantityDimension(ProductUnit.ofQuotient(pseudoUnit, that.pseudoUnit));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,28 @@ public void divisionIsDoneCorrectlyInOverloadedQuantityDimensionMethod() {
assertEquals("[L]/[M]", result.toString());
}

/**
* Verifies that the division is done correctly on powered units. Relies on the toString method to
* verify the result.
*/
@Test
public void divisionIsDoneCorrectlyOnPoweredBaseUnits() {
Dimension m2 = QuantityDimension.MASS.pow(2);
Dimension result = QuantityDimension.LENGTH.divide(m2);
assertEquals("[L]/[M]²", result.toString());
}

/**
* Verifies that the division is done correctly on powered units. Relies on the toString method to
* verify the result.
*/
@Test
public void divisionIsDoneCorrectlyOnPoweredProductUnits() {
Dimension ml = QuantityDimension.MASS.multiply(QuantityDimension.LENGTH);
Dimension result = QuantityDimension.LENGTH.divide(ml);
assertEquals("1/[M]", result.toString());
}

/**
* Verifies that raising to a power is done correctly by checking that multiplication with itself is the same as raising to the power of two.
*/
Expand Down

0 comments on commit ceea0c2

Please sign in to comment.