Class SIPrefixTest

java.lang.Object
org.djunits.unit.si.SIPrefixTest

public class SIPrefixTest extends Object
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, getKiloUnit accept valid keys, reject null/blank/unknown keys, and return stable results.
  • Maps exposed by SIPrefixes are unmodifiable.
  • The FACTORS map resolves typical exponents (e.g., -6 → micro, +3 → kilo, 0 → identity).
  • Enum constants presence and basic invariants.
Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
Author:
Alexander Verbraeck
  • Constructor Details

    • SIPrefixTest

      public SIPrefixTest()
  • Method Details

    • testSiprefixConstructorAndGetters

      @Test @DisplayName("SIPrefix constructor guards and getters") public void testSiprefixConstructorAndGetters()
      Constructor validation for SIPrefix.
      • 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:

      Current implementation returns null for unknown keys; this test will guide you to add the input checks in getSiPrefix, getSiPrefixPer, getSiPrefixKilo.
    • testEnumConstantsPresence

      @Test @DisplayName("Enum presence: NONE, UNIT, UNIT_POS, PER_UNIT, KILO") public void testEnumConstantsPresence()
      Enum constants presence and basic invariants.