Package org.djunits.unit.si
Class SIPrefixTest
java.lang.Object
org.djunits.unit.si.SIPrefixTest
Tests for
SIPrefix and SIPrefixes.
This suite validates:
- Public constructor guards on
SIPrefix: nulls and zero factor are rejected. - Getter semantics: textual vs display prefix, name, and numeric factor for known prefixes.
- Public lookups on
SIPrefixes:getUnit,getPerUnit,getKiloUnitaccept valid keys, reject null/blank/unknown keys, and return stable results. - Maps exposed by
SIPrefixesare unmodifiable. - The
FACTORSmap resolves typical exponents (e.g., -6 → micro, +3 → kilo, 0 → identity). - Enum constants presence and basic invariants.
- Author:
- Alexander Verbraeck
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVerify presence and numeric semantics for "" in the public maps now that you allow empty-string as the “no SI prefix” marker.voidEnum constants presence and basic invariants.voidFACTORS map: exponent → prefix.voidgetSiPrefixPer(String) should return proper results for valid keys, including the empty string "" to indicate "no SI prefix" in the per-unit set.voidgetSiPrefix(String) should return proper results for valid keys, including the empty string "" to indicate "no SI prefix".voidKILO-default maps: KILO and PER_KILO.voidLookup functions: desired public input checking (null/blank/unknown).voidPublic maps should be unmodifiable.voidPER_UNIT (reciprocal) prefixes map: presence and representative reciprocal values.voidConstructor validation forSIPrefix.voidSIPrefixes enum toString() should equal the enum constant name, and valueOf(toString()) should round-trip to the same constant.voidUNIT_POS prefixes contain only factors > 1 (no milli/centi/...).voidBasic presence and values in UNIT prefixes map.
-
Constructor Details
-
SIPrefixTest
public SIPrefixTest()
-
-
Method Details
-
testSiprefixConstructorAndGetters
@Test @DisplayName("SIPrefix constructor guards and getters") public void testSiprefixConstructorAndGetters()Constructor validation forSIPrefix.- null textual prefix → NPE
- null name → NPE
- null display prefix → NPE
- factor == 0 → IllegalArgumentException or runtime exception (as per implementation)
- valid construction returns stable getters
-
testGetSiPrefixValidKeys
@Test @DisplayName("getSiPrefix: valid keys (incl. \"\") return correct prefix") public void testGetSiPrefixValidKeys()getSiPrefix(String) should return proper results for valid keys, including the empty string "" to indicate "no SI prefix". -
testGetSiPrefixPerValidKeys
@Test @DisplayName("getSiPrefixPer: valid keys (incl. \"\") return correct prefix") public void testGetSiPrefixPerValidKeys()getSiPrefixPer(String) should return proper results for valid keys, including the empty string "" to indicate "no SI prefix" in the per-unit set. -
testEmptyStringEntriesInMaps
@Test @DisplayName("Empty-string entries exist: UNIT/PER_UNIT/KILO and have expected factors") public void testEmptyStringEntriesInMaps()Verify presence and numeric semantics for "" in the public maps now that you allow empty-string as the “no SI prefix” marker. -
testSiprefixesEnumToStringAndValueOf
@Test @DisplayName("SIPrefixes.toString() equals name() and valueOf(toString()) round-trips") public void testSiprefixesEnumToStringAndValueOf()SIPrefixes enum toString() should equal the enum constant name, and valueOf(toString()) should round-trip to the same constant. -
testUnitPrefixesPresenceAndValues
@Test @DisplayName("UNIT_PREFIXES: expected keys and representative values") public void testUnitPrefixesPresenceAndValues()Basic presence and values in UNIT prefixes map. -
testPerUnitPrefixesValues
@Test @DisplayName("PER_UNIT_PREFIXES: reciprocal values") public void testPerUnitPrefixesValues()PER_UNIT (reciprocal) prefixes map: presence and representative reciprocal values. -
testKiloAndPerKiloBehavior
@Test @DisplayName("KILO & PER_KILO: offset behavior and identity at \'k\' / \'/k\'") public void testKiloAndPerKiloBehavior()KILO-default maps: KILO and PER_KILO.- KILO_PREFIXES: "" (empty) is 1e-3 relative to kilo-default; large prefixes scale positively.
- PER_KILO_PREFIXES: "/" is 1e3; "/k" is 1.0 identity for per-kilo.
- getSiPrefixKilo("k") should be identity → factor 1.0 (this currently requires adding "k" to KILO_PREFIXES).
-
testUnitPosContainsOnlyPositivePrefixes
@Test @DisplayName("UNIT_POS contains only >1 prefixes") public void testUnitPosContainsOnlyPositivePrefixes()UNIT_POS prefixes contain only factors > 1 (no milli/centi/...). -
testFactorsExponentResolution
@Test @DisplayName("FACTORS map: exponent resolution") public void testFactorsExponentResolution()FACTORS map: exponent → prefix.- 3 → kilo
- -6 → micro
- 0 → identity (empty textual/display)
-
testMapsAreUnmodifiable
@Test @DisplayName("All public maps are unmodifiable") public void testMapsAreUnmodifiable()Public maps should be unmodifiable. -
testLookupInputValidationDesired
@Test @DisplayName("Lookup methods should validate inputs (NPE/IAE)") public void testLookupInputValidationDesired()Lookup functions: desired public input checking (null/blank/unknown).These assertions encode what should be enforced on the public API:
null→NullPointerException- blank →
IllegalArgumentException - unknown →
IllegalArgumentException - blank is valid only for KILO-lookup of "" key (handled in a separate test)
nullfor unknown keys; this test will guide you to add the input checks ingetSiPrefix,getSiPrefixPer,getSiPrefixKilo. -
testEnumConstantsPresence
@Test @DisplayName("Enum presence: NONE, UNIT, UNIT_POS, PER_UNIT, KILO") public void testEnumConstantsPresence()Enum constants presence and basic invariants.
-