Skip to content

Commit

Permalink
ICU-22781: Add unit tests for withConstantDenominators in MeasureUnit
Browse files Browse the repository at this point in the history
See #3342
  • Loading branch information
younies authored and Squash Bot committed Jan 23, 2025
1 parent 373cbaf commit 2afc016
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.ibm.icu.util.Measure;
import com.ibm.icu.util.MeasureUnit;
import com.ibm.icu.util.ULocale;
import com.ibm.icu.util.MeasureUnit.Complexity;

public class UnitsTest {

Expand Down Expand Up @@ -817,4 +818,38 @@ public TestCase(String name, String category, String usage, String region, Strin
}
}
}

@Test
public void testWithConstantDenominator() {
class TestCase {
String unitIdentifier;
long constantDenominator;
Complexity expectedComplexity;

TestCase(String unitIdentifier, long constantDenominator, Complexity expectedComplexity) {
this.unitIdentifier = unitIdentifier;
this.constantDenominator = constantDenominator;
this.expectedComplexity = expectedComplexity;
}
}

TestCase[] testCases = {
new TestCase("meter-per-second", 100, Complexity.COMPOUND),
new TestCase("meter-per-100-second", 0, Complexity.COMPOUND),
new TestCase("portion", 100, Complexity.COMPOUND),
new TestCase("portion-per-100", 0, Complexity.SINGLE),
};

for (TestCase testCase : testCases) {
MeasureUnit unit = MeasureUnit.forIdentifier(testCase.unitIdentifier);
unit = unit.withConstantDenominator(testCase.constantDenominator);

long actualDenominator = unit.getConstantDenominator();
Complexity actualComplexity = unit.getComplexity();

assertEquals(testCase.constantDenominator, actualDenominator);
assertEquals(testCase.expectedComplexity, actualComplexity);
}

}
}

0 comments on commit 2afc016

Please sign in to comment.