Class UnitlessTest

java.lang.Object
org.djunits.unit.UnitlessTest

public class UnitlessTest extends Object
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 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 constructor Unitless(String, String, double, UnitSystem) sets id/name/system and creates a LinearScale with the requested positive factor.
    • testSecondaryConstructorAndNulls

      @Test public void testSecondaryConstructorAndNulls()
      Verify the secondary constructor Unitless(String, String, String, Scale, UnitSystem) accepts an explicit scale and sets fields properly. Also test null-scale rejection.
    • testSiUnitAndOfSi

      @Test public void testSiUnitAndOfSi()
    • testDeriveUnitLinearScale

      @Test public void testDeriveUnitLinearScale()
      Verify Unitless.deriveUnit(String, String, String, double, UnitSystem) on a unit with linear scale composes factors multiplicatively.
    • testDeriveUnitInvalidFactors

      @Test public void testDeriveUnitInvalidFactors()
      Verify deriveUnit(...) rejects invalid factors (0, < 0, non-finite) via LinearScale's constructor. This ensures Unitless derives only with valid linear scales.
    • testDeriveUnitThrowsForNonLinearScale

      @Test public void testDeriveUnitThrowsForNonLinearScale()
      Verify deriveUnit(...) throws UnitRuntimeException when this unit does not have a LinearScale. 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.