Class SIUnitTest
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVerifies the int[9]-array constructor: Null and wrong-length arrays are rejected. Input array is defensively copied.voidVerifies theSIUnit.DIMLESSinstance and basic renderers.voidEquality and hashCode contracts across construction paths and negatives.voidExponent algebra: plus, minus, invert, pow.voidFormatting variants: plain (with/without separator), caret powers, and HTML, for two representative units.voidVerifies the 9-argument convenience constructor stores exponents in the documented order.voidSmoke test:SIUnit.ofSi(double)returns anSIQuantity.voidParsing: happy-path and edge cases, including disambiguation ofsrvssandmolvsm.voidImmutability: calling the various renderers must not mutate internal state.voidVerifies thatSIUnit.siAbbreviations()returns a defensive copy.voidVerifiesUnitInterfacegetters exposed bySIUnit.
-
Constructor Details
-
SIUnitTest
public SIUnitTest()
-
-
Method Details
-
testDimless
@Test @DisplayName("DIMLESS: exponents and rendering") public void testDimless()Verifies theSIUnit.DIMLESSinstance 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 ofsrvssandmolvsm. -
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 thatSIUnit.siAbbreviations()returns a defensive copy. -
testUnitInterfaceGetters
@Test @DisplayName("UnitInterface getters: consistent values") public void testUnitInterfaceGetters()VerifiesUnitInterfacegetters exposed bySIUnit. -
testOfSiCreatesQuantity
@Test @DisplayName("ofSi(double): creates SIQuantity") public void testOfSiCreatesQuantity()Smoke test:SIUnit.ofSi(double)returns anSIQuantity. -
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.
-