fun temporal_values_standardized_to_a_Double()

in plot-api/src/commonTest/kotlin/org/jetbrains/letsPlot/intern/standardizing/StandardizingTest.kt [42:96]


    fun temporal_values_standardized_to_a_Double() {
        // Expected timestamp for 2023-01-01T12:30:45Z
        val expectedTimestamp = 1672576245000L

        val expectedLocalDateTimestamp = KLocalDateTime(2023, 1, 1, 0, 0, 0, 0)
            .toInstant(TimeZone.UTC)
            .toEpochMilliseconds()

        val expectedLocalTimeTimestamp = KLocalDateTime(1970, 1, 1, 12, 30, 45, 0)
            .toInstant(TimeZone.UTC)
            .toEpochMilliseconds()

        // Kotlinx.datetime API
        val kInstant = KInstant.fromEpochMilliseconds(expectedTimestamp)
        val kLocalDate = KLocalDate(2023, 1, 1)
        val kLocalTime = KLocalTime(12, 30, 45)
        val kLocalDateTime = KLocalDateTime(2023, 1, 1, 12, 30, 45)

        val kDuration = kotlin.time.Duration.parse("2h30m45s")
        val expectedDurationMillis = kDuration.inWholeMilliseconds

        val values = listOf<Any>(
            kInstant,
            kLocalDate,
            kLocalTime,
            kLocalDateTime,
            kDuration,
        )

        val expectedValues = values.map {
            when (it) {
                is KLocalDate -> expectedLocalDateTimestamp
                is KLocalTime -> expectedLocalTimeTimestamp
                is KLocalDateTime -> expectedTimestamp      // Same as ZonedDateTime because here we use UTC
                is kotlin.time.Duration -> expectedDurationMillis
                else -> expectedTimestamp
            }.toDouble()
        } + StandardizingTestJvmValues.getExpectedValues()


        val inputValues = values + StandardizingTestJvmValues.getTestValues()
        val standardizedValues = SeriesStandardizing.toList(inputValues)
        inputValues.zip(expectedValues).zip(standardizedValues) { (a, b), c ->
            Triple(a, b, c)
        }
            .forEach { (input, expected, result) ->
                // Expect all results to be Double
                assertTrue(
                    result is Double,
                    "Input: $input, ${input::class}, result expected Double but was: ${result!!::class}"
                )

                assertEquals(expected, result, "Input: $input, ${input::class}")
            }
    }