indriya icon indicating copy to clipboard operation
indriya copied to clipboard

Incorrect equality between Quantity

Open fillumina opened this issue 3 years ago • 0 comments

The following test defines two quantities that should be equals but because they are using a different Unit class they are not. I think this impacts the usability of the library. Regards.

@Test
public void shouldNotEqualizeQuantities() {
    // uses TransformedUnit
    Quantity<Mass> w1 = Quantities.getQuantity(12.5, MetricPrefix.KILO(GRAM));

    // uses BasicUnit
    Quantity<Mass> w2 = (Quantity<Mass>) Quantities.getQuantity("12.5 kg");

    assertFalse(w1.equals(w2));
    assertFalse(w2.equals(w1));

    // workaround
    assertEquals(w1.toString(), w2.toString());
}

fillumina avatar Oct 22 '22 10:10 fillumina