Package org.djunits.util
Class ArrayMathTest
java.lang.Object
org.djunits.util.ArrayMathTest
Unit tests for
ArrayMath. The suite aims for 100% line and branch coverage by exercising:
- All functional (allocating) operations:
add,add(a,c),subtract,scaleBy,abs,axpy,multiply,divide,reciprocal - All procedural (into-buffer) operations:
addInto,scaleInto,axpyInto - All error paths:
NullPointerExceptionfornullinputs andIllegalArgumentExceptionfor length mismatches - Edge behavior: empty arrays, in-place destinations (
out == aand/orout == b), division by zero andNaN, reciprocal of 0 andInfinity - Coverage of the private constructor via reflection
Design: Each test documents the scenario and the expected outcome. An assertArrayClose helper is
used with a tight tolerance for floating-point comparisons. 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 TypeMethodDescription(package private) voidVerifiesArrayMath.abs(double[])absolute value, including negative zero andNaN.(package private) voidVerifiesArrayMath.add(double[], double[])on a happy path and length/Null preconditions.(package private) void(package private) voidVerifiesArrayMath.add(double[], double)adds a constant to each element and returns a new array.(package private) voidVerifies fused AXPYArrayMath.axpy(double[], double[], double)and preconditions.(package private) void(package private) voidCovers the private no-arg constructor ofArrayMathto achieve 100% coverage of the class.(package private) voidVerifiesArrayMath.divide(double[], double[])element-wise division, including division by zero and NaN.(package private) voidVerifiesArrayMath.multiply(double[], double[])element-wise product and preconditions.(package private) voidVerifiesArrayMath.reciprocal(double[])including reciprocal of 0 and Infinity.(package private) voidVerifiesArrayMath.scaleBy(double[], double)scaling by a scalar and preconditions.(package private) void(package private) voidVerifiesArrayMath.subtract(double[], double[])element-wise difference and preconditions.
-
Constructor Details
-
ArrayMathTest
public ArrayMathTest()
-
-
Method Details
-
constructorIsNotInstantiableButReachableViaReflection
Covers the private no-arg constructor ofArrayMathto achieve 100% coverage of the class.- Throws:
Exception- when reflection fails (should not happen in normal environments)
-
addArraysFunctional
@Test void addArraysFunctional()VerifiesArrayMath.add(double[], double[])on a happy path and length/Null preconditions. Expected: element-wise sum, new array returned; NPE/IAE on invalid inputs. -
addScalarFunctional
@Test void addScalarFunctional()VerifiesArrayMath.add(double[], double)adds a constant to each element and returns a new array. Also checks empty array path and null precondition. -
subtractFunctional
@Test void subtractFunctional()VerifiesArrayMath.subtract(double[], double[])element-wise difference and preconditions. -
scaleByFunctional
@Test void scaleByFunctional()VerifiesArrayMath.scaleBy(double[], double)scaling by a scalar and preconditions. -
absFunctional
@Test void absFunctional()VerifiesArrayMath.abs(double[])absolute value, including negative zero andNaN. -
axpyFunctional
@Test void axpyFunctional()Verifies fused AXPYArrayMath.axpy(double[], double[], double)and preconditions. -
multiplyFunctional
@Test void multiplyFunctional()VerifiesArrayMath.multiply(double[], double[])element-wise product and preconditions. -
divideFunctional
@Test void divideFunctional()VerifiesArrayMath.divide(double[], double[])element-wise division, including division by zero and NaN. -
reciprocalFunctional
@Test void reciprocalFunctional()VerifiesArrayMath.reciprocal(double[])including reciprocal of 0 and Infinity. -
addIntoProcedural
@Test void addIntoProcedural()VerifiesArrayMath.addInto(double[], double[], double[]).- Normal usage with distinct output buffer
- In-place usage with
out == a - In-place usage with
out == b - All precondition error paths
-
scaleIntoProcedural
@Test void scaleIntoProcedural()VerifiesArrayMath.scaleInto(double[], double, double[]).- Normal usage with distinct output buffer
- In-place usage with
out == a - Null and length precondition errors
-
axpyIntoProcedural
@Test void axpyIntoProcedural()VerifiesArrayMath.axpyInto(double[], double[], double, double[]).- Normal usage with distinct output buffer
- In-place usage with
out == a - In-place usage with
out == b - All precondition error paths
-