Package org.djunits.unit
Class UnitlessTest
java.lang.Object
org.djunits.unit.UnitlessTest
Unit tests for
Unitless. Ensures full coverage across constructors, constants, SI mapping, derivation behavior
(linear vs. non-linear), and basic object contracts. 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 TypeMethodDescriptionvoidVerify constants and base behavior:Unitless.SI_UNIT,Unitless.BASE, IDs/names/displays, system, and scale factor.voidVerifyderiveUnit(...)rejects invalid factors (0, < 0, non-finite) viaLinearScale's constructor.voidVerifyUnitless.deriveUnit(String, String, String, double, UnitSystem)on a unit with linear scale composes factors multiplicatively.voidvoidBasic object contract checks for equals, hashCode, and toString.voidVerify the primary constructorUnitless(String, String, double, UnitSystem)sets id/name/system and creates aLinearScalewith the requested positive factor.voidVerify the secondary constructorUnitless(String, String, String, Scale, UnitSystem)accepts an explicit scale and sets fields properly.voidVerify SI mapping:Unitless.siUnit()andUnitless.ofSi(double).
-
Constructor Details
-
UnitlessTest
public UnitlessTest()
-
-
Method Details
-
testConstantsAndBaseBehavior
@Test public void testConstantsAndBaseBehavior()Verify constants and base behavior:Unitless.SI_UNIT,Unitless.BASE, IDs/names/displays, system, and scale factor. -
testPrimaryConstructorLinearScale
@Test public void testPrimaryConstructorLinearScale()Verify the primary constructorUnitless(String, String, double, UnitSystem)sets id/name/system and creates aLinearScalewith the requested positive factor. -
testSecondaryConstructorAndNulls
@Test public void testSecondaryConstructorAndNulls()Verify the secondary constructorUnitless(String, String, String, Scale, UnitSystem)accepts an explicit scale and sets fields properly. Also test null-scale rejection. -
testSiUnitAndOfSi
@Test public void testSiUnitAndOfSi()Verify SI mapping:Unitless.siUnit()andUnitless.ofSi(double). -
testDeriveUnitLinearScale
@Test public void testDeriveUnitLinearScale()VerifyUnitless.deriveUnit(String, String, String, double, UnitSystem)on a unit with linear scale composes factors multiplicatively. -
testDeriveUnitInvalidFactors
@Test public void testDeriveUnitInvalidFactors()VerifyderiveUnit(...)rejects invalid factors (0, < 0, non-finite) viaLinearScale's constructor. This ensures Unitless derives only with valid linear scales. -
testDeriveUnitThrowsForNonLinearScale
@Test public void testDeriveUnitThrowsForNonLinearScale()VerifyderiveUnit(...)throwsUnitRuntimeExceptionwhen this unit does not have aLinearScale. We construct a Unitless with a non-linear-like Scale to hit the exception branch. -
testEqualsHashCodeToString
@Test public void testEqualsHashCodeToString()Basic object contract checks for equals, hashCode, and toString.
-