Repository: JetBrains/kotlin
File: libraries/stdlib/test/numbers/MathTest.kt (Kotlin)

Code before:
            assertEquals(abs(exact), acosh(cosh(exact)))
        }
        for (approx in listOf(Double.MIN_VALUE, 0.00001, 1.0, 100.0, 710.0)) {
            assertAlmostEquals(approx, acosh(cosh(approx)))
            assertAlmostEquals(approx, acosh(cosh(-approx)))
        }
        for (invalid in listOf(-1.0, 0.0, 0.99999, Double.NaN)) {
            assertTrue(acosh(invalid).isNaN())
        }
    }

    @Test fun inverseHyperbolicTan() {
        for (exact in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0, Double.MIN_VALUE, -Double.MIN_VALUE)) {
            assertEquals(exact, atanh(tanh(exact)))
        }
        for (approx in listOf(0.00001)) {
            assertAlmostEquals(approx, atanh(tanh(approx)))
        }

        for (invalid in listOf(-1.00001, 1.00001, Double.NaN, Double.MAX_VALUE, -Double.MAX_VALUE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)) {
            assertTrue(atanh(invalid).isNaN())
        }
    }

    @Test fun cubeRoots() {
        assertEquals(3.0, cbrt(27.0))
        assertEquals(-3.0, cbrt(-27.0))

        assertEquals(Double.POSITIVE_INFINITY, cbrt(Double.POSITIVE_INFINITY))
        assertEquals(Double.NEGATIVE_INFINITY, cbrt(Double.NEGATIVE_INFINITY))

        assertEquals(+0.0, cbrt(+0.0))
        assertEquals(-0.0, cbrt(-0.0))

        assertEquals(Double.NaN, cbrt(Double.NaN))

        val smallestNormal = Double.fromBits(0x0010000000000000)
        val smallestValue = Double.fromBits(0x1L) // denormal

        // Test -cbrt(x) == cbrt(-x)
        val reprocityValues = doubleArrayOf(
            smallestNormal,
            smallestValue,
            -0.1,
            -27.0,
            -0.0,
            0.0,
            0.1,
            27.0,
            Double.POSITIVE_INFINITY,
            Double.NEGATIVE_INFINITY,

Review comment (suggestion):
I propose to restructure this test a bit by introducing a list of pairs of source value and the corresponding expected result. These values can all be positive and later be used in the second part of test ensuring `cbrt(-x) == -cbrt(x)`

Please add more numbers, not necessary round ones, from various ranges of Double/Float value domain.

Code after:

    @Test fun inverseHyperbolicSin() {
        for (exact in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0, Double.MIN_VALUE, -Double.MIN_VALUE, 0.00001)) {
            assertEquals(exact, asinh(sinh(exact)))
        }
        for (approx in listOf(Double.MIN_VALUE, 0.1, 1.0, 100.0, 710.0)) {
            assertAlmostEquals(approx, asinh(sinh(approx)))
            assertAlmostEquals(-approx, asinh(sinh(-approx)))
        }
        assertTrue(asinh(Double.NaN).isNaN())
    }

    @Test fun inverseHyperbolicCos() {
        for (exact in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0)) {
            assertEquals(abs(exact), acosh(cosh(exact)))
        }
        for (approx in listOf(Double.MIN_VALUE, 0.00001, 1.0, 100.0, 710.0)) {
            assertAlmostEquals(approx, acosh(cosh(approx)))
            assertAlmostEquals(approx, acosh(cosh(-approx)))
        }
        for (invalid in listOf(-1.0, 0.0, 0.99999, Double.NaN)) {
            assertTrue(acosh(invalid).isNaN())
        }
    }

    @Test fun inverseHyperbolicTan() {
        for (exact in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0, Double.MIN_VALUE, -Double.MIN_VALUE)) {
            assertEquals(exact, atanh(tanh(exact)))
        }
        for (approx in listOf(0.00001)) {
            assertAlmostEquals(approx, atanh(tanh(approx)))
        }

        for (invalid in listOf(-1.00001, 1.00001, Double.NaN, Double.MAX_VALUE, -Double.MAX_VALUE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)) {
            assertTrue(atanh(invalid).isNaN())
        }
    }

    @Test fun cubeRoots() {
        val testingPairs = mapOf(
            Double.NaN to Double.NaN,
            Double.POSITIVE_INFINITY to Double.POSITIVE_INFINITY,
            Double.NEGATIVE_INFINITY to Double.NEGATIVE_INFINITY,
            Double.fromBits(0x0010000000000000) to 2.812644285236262E-103, // smallest normal value
            Double.fromBits(0x1L) to 1.7031839360032603E-108, // smallest value (denormal)
            Double.MAX_VALUE to 5.643803094122362E102,
            0.0 to 0.0,
            0.9 to 0.9654893846056297,
            9.9 to 2.1472291690189413,
            27.0 to 3.0,
            399.1289 to 7.362710510208026,