Class SIUnitTest

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

public final class SIUnitTest extends Object
Unit tests for SIUnit.

These tests validate construction (array and 9-arg), parsing of SI-dimension strings (including tricky cases for sr vs s and mol vs m), exponent algebra (SIUnit.plus(SIUnit), SIUnit.minus(SIUnit), SIUnit.invert(), SIUnit.pow(int)), formatting variants (plain/with separator/with power marker and HTML), immutability around rendering, SIUnit.siAbbreviations() defensive copies, UnitInterface getters, and a smoke test for SIUnit.ofSi(double).
Fractional dimensionality is intentionally not tested here (feature removed / not in production). 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 (specifications); Test implementation by Copilot.
  • Constructor Details

    • SIUnitTest

      public SIUnitTest()
  • Method Details

    • testDimless

      @Test @DisplayName("DIMLESS: exponents and rendering") public void testDimless()
      Verifies the SIUnit.DIMLESS instance and basic renderers.
      • Dimensionless has all-zero exponents.
      • String renderers produce the documented empty/identity forms.
    • testArrayConstructor

      @Test @DisplayName("int[9] constructor: validation and immutability") public void testArrayConstructor()
      Verifies the int[9]-array constructor:
      • Null and wrong-length arrays are rejected.
      • Input array is defensively copied.
    • testNineArgConstructor

      @Test @DisplayName("9-arg constructor: exponent order") public void testNineArgConstructor()
      Verifies the 9-argument convenience constructor stores exponents in the documented order.
    • testParsing

      @Test @DisplayName("Parsing SI strings: happy path + disambiguation + errors") public void testParsing()
      Parsing: happy-path and edge cases, including disambiguation of sr vs s and mol vs m.
    • testExponentAlgebra

      @Test @DisplayName("Exponent algebra: plus/minus/invert/pow") public void testExponentAlgebra()
      Exponent algebra: plus, minus, invert, pow. Also checks pow(0) and that pow(-1) equals invert().
    • testFormattingVariants

      @Test @DisplayName("Formatting: plain / caret / HTML") public void testFormattingVariants()
      Formatting variants: plain (with/without separator), caret powers, and HTML, for two representative units.
    • testSiAbbreviationsDefensiveCopy

      @Test @DisplayName("siAbbreviations(): defensive copy") public void testSiAbbreviationsDefensiveCopy()
      Verifies that SIUnit.siAbbreviations() returns a defensive copy.
    • testUnitInterfaceGetters

      @Test @DisplayName("UnitInterface getters: consistent values") public void testUnitInterfaceGetters()
      Verifies UnitInterface getters exposed by SIUnit.
    • testOfSiCreatesQuantity

      @Test @DisplayName("ofSi(double): creates SIQuantity") public void testOfSiCreatesQuantity()
      Smoke test: SIUnit.ofSi(double) returns an SIQuantity.
    • testEqualsAndHashCode

      @Test @DisplayName("equals/hashCode across construction paths") public void testEqualsAndHashCode()
      Equality and hashCode contracts across construction paths and negatives.
    • testRenderingNoMutation

      @Test @DisplayName("Rendering must not mutate exponents") public void testRenderingNoMutation()
      Immutability: calling the various renderers must not mutate internal state.