[K/N] Migrate all stdlib_external tests to new testing infra ^KT-61259
- Move backend.native/tests/stdlib_external to runtime/test This mirrors tests location (in relation to sources) on other backends. - Remove all backend.native/tests tasks using stdlib_external. Additionally remove now unused KonanGTest. - Include complete native-wasm/test and runtime/test in native/native.test - In runtime/test/numbers/MathTest.kt leave only native-specific part.
This commit is contained in:
committed by
Space Team
parent
c9e4b71010
commit
9ab6a5ff56
@@ -117,9 +117,6 @@ allprojects {
|
||||
// backend.native/tests/external
|
||||
ext.testOutputExternal = rootProject.file("$testOutputRoot/external")
|
||||
|
||||
// backend.native/tests/stdlib_external
|
||||
ext.testOutputStdlib = rootProject.file("$testOutputRoot/stdlib")
|
||||
|
||||
// backend.native/tests/framework
|
||||
ext.testOutputFramework = rootProject.file("$testOutputRoot/framework")
|
||||
|
||||
@@ -129,7 +126,6 @@ allprojects {
|
||||
ext.testOutputFileCheck = rootProject.file("$testOutputRoot/filecheck")
|
||||
}
|
||||
testOutputExternal.mkdirs()
|
||||
testOutputStdlib.mkdirs()
|
||||
|
||||
konanArtifacts {
|
||||
library('testLibrary') {
|
||||
@@ -2616,21 +2612,6 @@ standaloneTest("unhandled_exception") {
|
||||
source = "runtime/exceptions/unhandled_exception.kt"
|
||||
}
|
||||
|
||||
standaloneTest("runtime_math_exceptions") {
|
||||
source = "stdlib_external/numbers/MathExceptionTest.kt"
|
||||
flags = ['-tr']
|
||||
}
|
||||
|
||||
standaloneTest("runtime_math") {
|
||||
source = "stdlib_external/numbers/MathTest.kt"
|
||||
flags = ['-tr']
|
||||
}
|
||||
|
||||
standaloneTest("runtime_math_harmony") {
|
||||
source = "stdlib_external/numbers/HarmonyMathTests.kt"
|
||||
flags = ['-tr']
|
||||
}
|
||||
|
||||
tasks.register("catch3", KonanLocalTest) {
|
||||
useGoldenData = true
|
||||
source = "codegen/try/catch3.kt"
|
||||
@@ -5630,26 +5611,6 @@ if (isAppleTarget(project)) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates tasks to build and execute Harmony regex tests with GTEST logger.
|
||||
*/
|
||||
KotlinNativeTestKt.createTest(project, 'harmonyRegexTest', KonanGTest) { task ->
|
||||
task.enabled = !isAggressiveGC // TODO: Investigate why too slow
|
||||
task.useFilter = false
|
||||
task.testLogger = KonanTest.Logger.GTEST
|
||||
|
||||
def sources = UtilsKt.getFilesToCompile(project, ["../../../libraries/stdlib/native-wasm/test/harmony_regex"], [])
|
||||
|
||||
konanArtifacts {
|
||||
program('harmonyRegexTest', targets: [target.name]) {
|
||||
srcFiles sources
|
||||
baseDir "$testOutputStdlib/harmonyRegexTest"
|
||||
extraOpts '-tr'
|
||||
extraOpts project.globalTestArgs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (UtilsKt.getTestTargetSupportsCodeCoverage(project)) {
|
||||
tasks.register("coverage_basic_program", CoverageTest) {
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package test.collections
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// TODO: consider moving to common stdlib tests.
|
||||
class KT42428Test {
|
||||
|
||||
private val listOfLetterIndexPairs = ('a'..'z').withIndex().map { (i, c) -> "$c" to i }
|
||||
|
||||
private val mapOfLetterToIndex = listOfLetterIndexPairs.toMap()
|
||||
|
||||
@Test fun testListOfPairsToMapEntriesContainsMapEntry() {
|
||||
testMapEntriesContainsMapEntry(listOfLetterIndexPairs.toMap(), "h", 7)
|
||||
}
|
||||
|
||||
@Test fun testMapToMutableMapEntriesContainsMapEntry() {
|
||||
testMapEntriesContainsMapEntry(mapOfLetterToIndex.toMutableMap(), "h", 7)
|
||||
}
|
||||
|
||||
@Test fun testHashMapEntriesContainsMapEntry() {
|
||||
testMapEntriesContainsMapEntry(HashMap(mapOfLetterToIndex), "h", 7)
|
||||
}
|
||||
|
||||
@Test fun testLinkedHashMapEntriesContainsMapEntry() {
|
||||
testMapEntriesContainsMapEntry(LinkedHashMap(mapOfLetterToIndex), "h", 7)
|
||||
}
|
||||
|
||||
// Based on https://youtrack.jetbrains.com/issue/KT-42428.
|
||||
private fun testMapEntriesContainsMapEntry(map: Map<String, Int>, key: String, value: Int) {
|
||||
data class SimpleEntry<out K, out V>(override val key: K, override val value: V) : Map.Entry<K, V> {
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is Map.Entry<*, *> && key == other.key && value == other.value
|
||||
|
||||
override fun hashCode(): Int = key.hashCode() xor value.hashCode()
|
||||
|
||||
override fun toString(): String = "$key=$value"
|
||||
}
|
||||
|
||||
|
||||
assertTrue(map.keys.contains(key))
|
||||
|
||||
// This one requires special efforts to make it work this way.
|
||||
// map.entries can in fact be `MutableSet<MutableMap.MutableEntry>`,
|
||||
// which [contains] method takes [MutableEntry], so the compiler may generate special bridge
|
||||
// returning false for values that aren't [MutableEntry] (including [SimpleEntry]).
|
||||
assertTrue(map.entries.contains(SimpleEntry(key, value)))
|
||||
|
||||
assertTrue(map.entries.toSet().contains(SimpleEntry(key, value)))
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package test.collections.js
|
||||
|
||||
actual fun <V> stringMapOf(vararg pairs: Pair<String, V>): HashMap<String, V> = hashMapOf<String, V>(*pairs)
|
||||
actual fun <V> linkedStringMapOf(vararg pairs: Pair<String, V>): LinkedHashMap<String, V> = linkedMapOf(*pairs)
|
||||
actual fun stringSetOf(vararg elements: String): HashSet<String> = hashSetOf(*elements)
|
||||
actual fun linkedStringSetOf(vararg elements: String): LinkedHashSet<String> = linkedSetOf(*elements)
|
||||
@@ -1,824 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test.numbers.harmony_math
|
||||
|
||||
import kotlin.math.*
|
||||
import kotlin.test.*
|
||||
|
||||
class HarmonyMath {
|
||||
|
||||
fun assertEquals(expected: Double, actual: Double, tolerance: Double? = null) =
|
||||
assertEquals(null, expected, actual, tolerance)
|
||||
|
||||
fun assertEquals(expected: Float, actual: Float, tolerance: Float? = null) =
|
||||
assertEquals(null, expected, actual, tolerance)
|
||||
|
||||
fun Double.Companion.isNaN(v: Double) = v.isNaN()
|
||||
fun Float.Companion.isNaN(v: Float) = v.isNaN()
|
||||
|
||||
fun pow(a: Double, b: Double) = a.pow(b)
|
||||
fun pow(a: Float, b: Float) = a.pow(b)
|
||||
|
||||
fun ulp(v: Double) = v.ulp
|
||||
fun ulp(v: Float) = v.ulp
|
||||
|
||||
fun assertEquals(message: String?, expected: Int, actual: Int) = assertEquals(expected, actual, message)
|
||||
fun assertEquals(message: String?, expected: Long, actual: Long) = assertEquals(expected, actual, message)
|
||||
|
||||
fun assertEquals(message: String?, expected: Double, actual: Double, tolerance: Double? = null) {
|
||||
val tolerance_ = tolerance?.let { abs(it) } ?: 0.000000000001
|
||||
if (abs(expected - actual) > tolerance_) {
|
||||
assertEquals(expected, actual, message)
|
||||
}
|
||||
}
|
||||
|
||||
fun assertEquals(message: String?, expected: Float, actual: Float, tolerance: Float? = null) {
|
||||
val tolerance_ = tolerance?.let { abs(it) } ?: 0.0000001f
|
||||
if (abs(expected - actual) > tolerance_) {
|
||||
assertEquals(expected, actual, message)
|
||||
}
|
||||
}
|
||||
|
||||
fun assertTrue(message: String? = null, condition: Boolean) = assertTrue(condition, message)
|
||||
|
||||
internal var HYP = sqrt(2.0)
|
||||
|
||||
internal var OPP = 1.0
|
||||
|
||||
internal var ADJ = 1.0
|
||||
|
||||
/* Required to make previous preprocessor flags work - do not remove */
|
||||
internal var unused = 0
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.abs(Double)
|
||||
*/
|
||||
@Test fun absD() {
|
||||
// Test for abs(Double): Double
|
||||
|
||||
assertTrue("Incorrect Double abs value",
|
||||
abs(-1908.8976) == 1908.8976)
|
||||
assertTrue("Incorrect Double abs value",
|
||||
abs(1908.8976) == 1908.8976)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.abs(float)
|
||||
*/
|
||||
@Test fun absF() {
|
||||
// Test for abs(float): float
|
||||
assertTrue("Incorrect float abs value",
|
||||
abs(-1908.8976f) == 1908.8976f)
|
||||
assertTrue("Incorrect float abs value",
|
||||
abs(1908.8976f) == 1908.8976f)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.abs(int)
|
||||
*/
|
||||
@Test fun absI() {
|
||||
// Test for abs(int): int
|
||||
assertTrue("Incorrect int abs value", abs(-1908897) == 1908897)
|
||||
assertTrue("Incorrect int abs value", abs(1908897) == 1908897)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.abs(long)
|
||||
*/
|
||||
@Test fun absJ() {
|
||||
// Test for abs(long): long
|
||||
assertTrue("Incorrect long abs value",
|
||||
abs(-19088976000089L) == 19088976000089L)
|
||||
assertTrue("Incorrect long abs value",
|
||||
abs(19088976000089L) == 19088976000089L)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.acos(Double)
|
||||
*/
|
||||
@Test fun acosD() {
|
||||
// Test for acos(Double): Double
|
||||
val r = cos(acos(ADJ / HYP))
|
||||
val lr = r.toBits()
|
||||
val t = (ADJ / HYP).toBits()
|
||||
assertTrue("Returned incorrect arc cosine", lr == t || lr + 1 == t || lr - 1 == t)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.asin(Double)
|
||||
*/
|
||||
@Test fun asinD() {
|
||||
// Test for asin(Double): Double
|
||||
val r = sin(asin(OPP / HYP))
|
||||
val lr = r.toBits()
|
||||
val t = (OPP / HYP).toBits()
|
||||
assertTrue("Returned incorrect arc sine", lr == t || lr + 1 == t || lr - 1 == t)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.atan(Double)
|
||||
*/
|
||||
@Test fun atanD() {
|
||||
// Test for atan(Double): Double
|
||||
val answer = tan(atan(1.0))
|
||||
assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0 && answer >= 9.9999999999999983E-1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.atan2(Double, Double)
|
||||
*/
|
||||
@Test fun atan2DD() {
|
||||
// Test for atan2(Double, Double): Double
|
||||
val answer = atan(tan(1.0))
|
||||
assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0 && answer >= 9.9999999999999983E-1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.ceil(Double)
|
||||
*/
|
||||
@Test fun ceilD() {
|
||||
// Test for ceil(Double): Double
|
||||
assertEquals("Incorrect ceiling for Double",
|
||||
79.0, ceil(78.89), 0.0)
|
||||
assertEquals("Incorrect ceiling for Double",
|
||||
-78.0, ceil(-78.89), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.withSign(Double)
|
||||
*/
|
||||
@Test fun withSign_D() {
|
||||
for (i in COPYSIGN_DD_CASES.indices) {
|
||||
val magnitude = COPYSIGN_DD_CASES[i]
|
||||
val absMagnitudeBits = abs(magnitude).toBits()
|
||||
val negMagnitudeBits = (-abs(magnitude)).toBits()
|
||||
|
||||
assertTrue("The result should be NaN.", Double.isNaN(Double.NaN.withSign(magnitude)))
|
||||
|
||||
for (j in COPYSIGN_DD_CASES.indices) {
|
||||
val sign = COPYSIGN_DD_CASES[j]
|
||||
val resultBits = magnitude.withSign(sign).toBits()
|
||||
|
||||
if (sign > 0 || (+0.0).toBits() == sign.toBits() || 0.0.toBits() == sign.toBits()) {
|
||||
assertEquals(
|
||||
"If the sign is positive, the result should be positive.",
|
||||
absMagnitudeBits, resultBits)
|
||||
}
|
||||
if (sign < 0 || (-0.0).toBits() == sign.toBits()) {
|
||||
assertEquals(
|
||||
"If the sign is negative, the result should be negative.",
|
||||
negMagnitudeBits, resultBits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("The result should be NaN.", Double.isNaN(Double.NaN.withSign(Double.NaN)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.withSign(Float)
|
||||
*/
|
||||
@Test fun withSign_F() {
|
||||
for (i in COPYSIGN_FF_CASES.indices) {
|
||||
val magnitude = COPYSIGN_FF_CASES[i]
|
||||
val absMagnitudeBits = abs(magnitude).toBits()
|
||||
val negMagnitudeBits = (-abs(magnitude)).toBits()
|
||||
|
||||
assertTrue("The result should be NaN.", Float.isNaN(Float.NaN.withSign(magnitude)))
|
||||
|
||||
for (j in COPYSIGN_FF_CASES.indices) {
|
||||
val sign = COPYSIGN_FF_CASES[j]
|
||||
val resultBits = magnitude.withSign(sign).toBits()
|
||||
if (sign > 0 || (+0.0f).toBits() == sign.toBits() || 0.0f.toBits() == sign.toBits()) {
|
||||
assertEquals(
|
||||
"If the sign is positive, the result should be positive.",
|
||||
absMagnitudeBits, resultBits)
|
||||
}
|
||||
if (sign < 0 || (-0.0f).toBits() == sign.toBits()) {
|
||||
assertEquals(
|
||||
"If the sign is negative, the result should be negative.",
|
||||
negMagnitudeBits, resultBits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("The result should be NaN.", Float.isNaN(Float.NaN.withSign(Float.NaN)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.cos(Double)
|
||||
*/
|
||||
@Test fun cosD() {
|
||||
// Test for cos(Double): Double
|
||||
assertEquals("Incorrect answer", 1.0, cos(0.0), 0.0)
|
||||
assertEquals("Incorrect answer", 0.5403023058681398, cos(1.0), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.cosh(Double)
|
||||
*/
|
||||
@Test fun cosh_D() {
|
||||
// Test for special situations
|
||||
assertTrue(Double.isNaN(cosh(Double.NaN)))
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, cosh(Double.POSITIVE_INFINITY), 0.0)
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, cosh(Double.NEGATIVE_INFINITY), 0.0)
|
||||
assertEquals("Should return 1.0", 1.0, cosh(+0.0), 0.0)
|
||||
assertEquals("Should return 1.0", 1.0, cosh(-0.0), 0.0)
|
||||
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, cosh(1234.56), 0.0)
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, cosh(-1234.56), 0.0)
|
||||
assertEquals("Should return 1.0000000000005", 1.0000000000005, cosh(0.000001), 0.0)
|
||||
assertEquals("Should return 1.0000000000005", 1.0000000000005, cosh(-0.000001), 0.0)
|
||||
assertEquals("Should return 5.212214351945598", 5.212214351945598, cosh(2.33482), 0.0)
|
||||
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, cosh(Double.MAX_VALUE), 0.0)
|
||||
assertEquals("Should return 1.0", 1.0, cosh(Double.MIN_VALUE), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.exp(Double)
|
||||
*/
|
||||
@Test fun expD() {
|
||||
// Test for exp(Double): Double
|
||||
assertTrue("Incorrect answer returned for simple power", abs(exp(4.0) - E * E * E * E) < 0.1)
|
||||
assertTrue("Incorrect answer returned for larger power", ln(abs(exp(5.5)) - 5.5) < 10.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.expm1(Double)
|
||||
*/
|
||||
@Test fun expm1_D() {
|
||||
// Test for special cases
|
||||
assertTrue("Should return NaN", Double.isNaN(expm1(Double.NaN)))
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, expm1(Double.POSITIVE_INFINITY), 0.0)
|
||||
assertEquals("Should return -1.0", -1.0, expm1(Double.NEGATIVE_INFINITY), 0.0)
|
||||
|
||||
assertEquals(0.0.toBits(), expm1(0.0).toBits())
|
||||
assertEquals(+0.0.toBits(), expm1(+0.0).toBits())
|
||||
assertEquals((-0.0).toBits(), expm1(-0.0).toBits())
|
||||
|
||||
assertEquals("Should return -9.999950000166666E-6",
|
||||
-9.999950000166666E-6, expm1(-0.00001))
|
||||
assertEquals("Should return 1.0145103074469635E60",
|
||||
1.0145103074469635E60, expm1(138.16951162), 0.0)
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, expm1(123456789123456789123456789.4521584223), 0.0)
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, expm1(Double.MAX_VALUE), 0.0)
|
||||
assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, expm1(Double.MIN_VALUE), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.floor(Double)
|
||||
*/
|
||||
@Test fun floorD() {
|
||||
assertEquals("Incorrect floor for int", 42.0, floor(42.0), 0.0)
|
||||
assertEquals("Incorrect floor for -int", -2.0, floor(-2.0), 0.0)
|
||||
assertEquals("Incorrect floor for zero", 0.0, floor(0.0), 0.0)
|
||||
|
||||
assertEquals("Incorrect floor for +Double", 78.0, floor(78.89), 0.0)
|
||||
assertEquals("Incorrect floor for -Double", -79.0, floor(-78.89), 0.0)
|
||||
assertEquals("floor large +Double", 3.7314645675925406E19, floor(3.7314645675925406E19), 0.0)
|
||||
assertEquals("floor large -Double", -8.173521839218E12, floor(-8.173521839218E12), 0.0)
|
||||
assertEquals("floor small Double", 0.0, floor(1.11895241315E-102), 0.0)
|
||||
|
||||
// Compare toString representations here since -0.0 = +0.0, and
|
||||
// NaN != NaN and we need to distinguish
|
||||
|
||||
assertEquals(Double.NaN.toString(), floor(Double.NaN).toString(), "Floor failed for NaN")
|
||||
assertEquals((+0.0).toString(), floor(+0.0).toString(), "Floor failed for +0.0")
|
||||
assertEquals((-0.0).toString(), floor(-0.0).toString(), "Floor failed for -0.0")
|
||||
assertEquals(Double.POSITIVE_INFINITY.toString(), floor(Double.POSITIVE_INFINITY).toString(),
|
||||
"Floor failed for +infinity")
|
||||
assertEquals(Double.NEGATIVE_INFINITY.toString(), floor(Double.NEGATIVE_INFINITY).toString(),
|
||||
"Floor failed for -infinity")
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.hypot(Double, Double)
|
||||
*/
|
||||
@Test fun hypot_DD() {
|
||||
// Test for special cases
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, hypot(Double.POSITIVE_INFINITY,
|
||||
1.0), 0.0)
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, hypot(Double.NEGATIVE_INFINITY,
|
||||
123.324), 0.0)
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, hypot(-758.2587,
|
||||
Double.POSITIVE_INFINITY), 0.0)
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, hypot(5687.21,
|
||||
Double.NEGATIVE_INFINITY), 0.0)
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, hypot(Double.POSITIVE_INFINITY,
|
||||
Double.NEGATIVE_INFINITY), 0.0)
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, hypot(Double.NEGATIVE_INFINITY,
|
||||
Double.POSITIVE_INFINITY), 0.0)
|
||||
assertTrue("Should be NaN", Double.isNaN(hypot(Double.NaN,
|
||||
2342301.89843)))
|
||||
assertTrue("Should be NaN", Double.isNaN(hypot(-345.2680,
|
||||
Double.NaN)))
|
||||
|
||||
assertEquals("Should return 2396424.905416697", 2396424.905416697, hypot(12322.12, -2396393.2258), 0.0)
|
||||
assertEquals("Should return 138.16958070558556", 138.16958070558556,
|
||||
hypot(-138.16951162, 0.13817035864), 0.0)
|
||||
assertEquals("Should return 1.7976931348623157E308",
|
||||
1.7976931348623157E308, hypot(Double.MAX_VALUE, 211370.35), 0.0)
|
||||
assertEquals("Should return 5413.7185", 5413.7185, hypot(
|
||||
-5413.7185, Double.MIN_VALUE), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.IEEEremainder(Double, Double)
|
||||
*/
|
||||
@Test fun IEEEremainderDD() {
|
||||
// Test for IEEEremainder(Double, Double): Double
|
||||
assertEquals("Incorrect remainder returned",
|
||||
0.0, 1.0.IEEErem(1.0), 0.0)
|
||||
assertTrue("Incorrect remainder returned",
|
||||
1.32.IEEErem(89.765) >= 1.4705063220631647E-2 || 1.32.IEEErem(89.765) >= 1.4705063220631649E-2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.ln(Double)
|
||||
*/
|
||||
@Test fun lnD() {
|
||||
// Test for log(Double): Double
|
||||
var d = 10.0
|
||||
while (d >= -10) {
|
||||
val answer = ln(exp(d))
|
||||
assertTrue("Answer does not equal expected answer for d = " + d
|
||||
+ " answer = " + answer, abs(answer - d) <= abs(d * 0.00000001))
|
||||
d -= 0.5
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.log10(Double)
|
||||
*/
|
||||
@Test fun log10_D() {
|
||||
// Test for special cases
|
||||
assertTrue(Double.isNaN(log10(Double.NaN)))
|
||||
assertTrue(Double.isNaN(log10(-2541.05745687234187532)))
|
||||
assertTrue(Double.isNaN(log10(-0.1)))
|
||||
assertEquals(Double.POSITIVE_INFINITY, log10(Double.POSITIVE_INFINITY))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, log10(0.0))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, log10(+0.0))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, log10(-0.0))
|
||||
|
||||
assertEquals(3.0, log10(1000.0))
|
||||
assertEquals(14.0, log10(10.0.pow(14.0)))
|
||||
assertEquals(3.7389561269540406, log10(5482.2158))
|
||||
assertEquals(14.661551142893833, log10(458723662312872.125782332587))
|
||||
assertEquals(-0.9083828622192334, log10(0.12348583358871))
|
||||
assertEquals(308.25471555991675, log10(Double.MAX_VALUE))
|
||||
assertEquals(-323.3062153431158, log10(Double.MIN_VALUE))
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.ln1p(Double)
|
||||
*/
|
||||
@Test fun ln1p_D() {
|
||||
// Test for special cases
|
||||
assertTrue("Should return NaN", Double.isNaN(ln1p(Double.NaN)))
|
||||
assertTrue("Should return NaN", Double.isNaN(ln1p(-32.0482175)))
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, ln1p(Double.POSITIVE_INFINITY), 0.0)
|
||||
assertEquals(0.0.toBits(), ln1p(0.0).toBits())
|
||||
assertEquals(+0.0.toBits(), ln1p(+0.0).toBits())
|
||||
assertEquals((-0.0).toBits(), ln1p(-0.0).toBits())
|
||||
|
||||
assertEquals("Should return -0.2941782295312541", -0.2941782295312541,
|
||||
ln1p(-0.254856327), 0.0)
|
||||
assertEquals("Should return 7.368050685564151", 7.368050685564151, ln1p(1583.542), 0.0)
|
||||
assertEquals("Should return 0.4633708685409921", 0.4633708685409921,
|
||||
ln1p(0.5894227), 0.0)
|
||||
assertEquals("Should return 709.782712893384", 709.782712893384, ln1p(Double.MAX_VALUE), 0.0)
|
||||
assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE, ln1p(Double.MIN_VALUE), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.max(Double, Double)
|
||||
*/
|
||||
@Test fun maxDD() {
|
||||
// Test for max(Double, Double): Double
|
||||
assertEquals("Incorrect Double max value", 1908897.6000089, max(-1908897.6000089,
|
||||
1908897.6000089), 0.0)
|
||||
assertEquals("Incorrect Double max value",
|
||||
1908897.6000089, max(2.0, 1908897.6000089), 0.0)
|
||||
assertEquals("Incorrect Double max value", -2.0, max(-2.0,
|
||||
-1908897.6000089), 0.0)
|
||||
|
||||
// Compare toString representations here since -0.0 = +0.0, and
|
||||
// NaN != NaN and we need to distinguish
|
||||
assertEquals((Double.NaN).toString(), max(Double.NaN, 42.0).toString(), "Max failed for NaN")
|
||||
assertEquals((Double.NaN).toString(), max(42.0, Double.NaN).toString(), "Max failed for NaN")
|
||||
assertEquals((+0.0).toString(), max(+0.0, -0.0).toString(), "Max failed for 0.0")
|
||||
assertEquals((+0.0).toString(), max(-0.0, +0.0).toString(), "Max failed for 0.0")
|
||||
assertEquals((-0.0).toString(), max(-0.0, -0.0).toString(), "Max failed for -0.0d")
|
||||
assertEquals((+0.0).toString(), max(+0.0, +0.0).toString(), "Max failed for 0.0")
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.max(float, float)
|
||||
*/
|
||||
@Test fun maxFF() {
|
||||
// Test for max(float, float): float
|
||||
assertTrue("Incorrect float max value", max(-1908897.600f,
|
||||
1908897.600f) == 1908897.600f)
|
||||
assertTrue("Incorrect float max value",
|
||||
max(2.0f, 1908897.600f) == 1908897.600f)
|
||||
assertTrue("Incorrect float max value",
|
||||
max(-2.0f, -1908897.600f) == -2.0f)
|
||||
|
||||
// Compare toString representations here since -0.0 = +0.0, and
|
||||
// NaN != NaN and we need to distinguish
|
||||
assertEquals(Float.NaN.toString(), max(Float.NaN, 42.0f).toString(), "Max failed for NaN")
|
||||
assertEquals(Float.NaN.toString(), max(42.0f, Float.NaN).toString(), "Max failed for NaN")
|
||||
assertEquals((+0.0f).toString(), max(+0.0f, -0.0f).toString(), "Max failed for 0.0")
|
||||
assertEquals((+0.0f).toString(), max(-0.0f, +0.0f).toString(), "Max failed for 0.0")
|
||||
assertEquals((-0.0f).toString(), max(-0.0f, -0.0f).toString(), "Max failed for -0.0f")
|
||||
assertEquals((+0.0f).toString(), max(+0.0f, +0.0f).toString(), "Max failed for 0.0")
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.max(int, int)
|
||||
*/
|
||||
@Test fun maxII() {
|
||||
// Test for max(int, int): int
|
||||
assertEquals("Incorrect int max value",
|
||||
19088976, max(-19088976, 19088976))
|
||||
assertEquals("Incorrect int max value",
|
||||
19088976, max(20, 19088976))
|
||||
assertEquals("Incorrect int max value", -20, max(-20, -19088976))
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.max(long, long)
|
||||
*/
|
||||
@Test fun maxJJ() {
|
||||
// Test for max(long, long): long
|
||||
assertEquals("Incorrect long max value", 19088976000089L, max(-19088976000089L,
|
||||
19088976000089L))
|
||||
assertEquals("Incorrect long max value",
|
||||
19088976000089L, max(20, 19088976000089L))
|
||||
assertEquals("Incorrect long max value",
|
||||
-20, max(-20, -19088976000089L))
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.min(Double, Double)
|
||||
*/
|
||||
@Test fun minDD() {
|
||||
// Test for min(Double, Double): Double
|
||||
assertEquals("Incorrect Double min value", -1908897.6000089, min(-1908897.6000089,
|
||||
1908897.6000089), 0.0)
|
||||
assertEquals("Incorrect Double min value",
|
||||
2.0, min(2.0, 1908897.6000089), 0.0)
|
||||
assertEquals("Incorrect Double min value", -1908897.6000089, min(-2.0,
|
||||
-1908897.6000089), 0.0)
|
||||
assertEquals("Incorrect Double min value", 1.0, min(1.0, 1.0))
|
||||
|
||||
// Compare toString representations here since -0.0 = +0.0, and
|
||||
// NaN != NaN and we need to distinguish
|
||||
assertEquals(Double.NaN.toString(), min(Double.NaN, 42.0).toString(), "Min failed for NaN")
|
||||
assertEquals(Double.NaN.toString(), min(42.0, Double.NaN).toString(), "Min failed for NaN")
|
||||
assertEquals((-0.0).toString(), min(+0.0, -0.0).toString(), "Min failed for -0.0")
|
||||
assertEquals((-0.0).toString(), min(-0.0, +0.0).toString(), "Min failed for -0.0")
|
||||
assertEquals((-0.0).toString(), min(-0.0, -0.0).toString(), "Min failed for -0.0d")
|
||||
assertEquals((+0.0).toString(), min(+0.0, +0.0).toString(), "Min failed for 0.0")
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.min(float, float)
|
||||
*/
|
||||
@Test fun minFF() {
|
||||
// Test for min(float, float): float
|
||||
assertTrue("Incorrect float min value", min(-1908897.600f,
|
||||
1908897.600f) == -1908897.600f)
|
||||
assertTrue("Incorrect float min value",
|
||||
min(2.0f, 1908897.600f) == 2.0f)
|
||||
assertTrue("Incorrect float min value",
|
||||
min(-2.0f, -1908897.600f) == -1908897.600f)
|
||||
assertEquals("Incorrect float min value", 1.0f, min(1.0f, 1.0f))
|
||||
|
||||
// Compare toString representations here since -0.0 = +0.0, and
|
||||
// NaN != NaN and we need to distinguish
|
||||
assertEquals(Float.NaN.toString(), min(Float.NaN, 42.0f).toString(), "Min failed for NaN")
|
||||
assertEquals(Float.NaN.toString(), min(42.0f, Float.NaN).toString(), "Min failed for NaN")
|
||||
assertEquals((-0.0f).toString(), min(+0.0f, -0.0f).toString(), "Min failed for -0.0")
|
||||
assertEquals((-0.0f).toString(), min(-0.0f, +0.0f).toString(), "Min failed for -0.0")
|
||||
assertEquals((-0.0f).toString(), min(-0.0f, -0.0f).toString(), "Min failed for -0.0f")
|
||||
assertEquals((+0.0f).toString(), min(+0.0f, +0.0f).toString(), "Min failed for 0.0")
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.min(int, int)
|
||||
*/
|
||||
@Test fun minII() {
|
||||
// Test for min(int, int): int
|
||||
assertEquals("Incorrect int min value",
|
||||
-19088976, min(-19088976, 19088976))
|
||||
assertEquals("Incorrect int min value", 20, min(20, 19088976))
|
||||
assertEquals("Incorrect int min value",
|
||||
-19088976, min(-20, -19088976))
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @tests java.lang.Math#pow(double, double)
|
||||
*/
|
||||
fun test_powDD() {
|
||||
// Test for method double java.lang.Math.pow(double, double)
|
||||
assertTrue("pow returned incorrect value",
|
||||
2.0.pow(8.0).toLong() == 256L)
|
||||
assertTrue("pow returned incorrect value",
|
||||
2.0.pow(-8.0) == 0.00390625)
|
||||
assertEquals("Incorrect root returned1",
|
||||
2.0, sqrt(sqrt(2.0).pow(4.0)), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.round(Double)
|
||||
*/
|
||||
@Test fun roundD() {
|
||||
// Test for round(Double): Double
|
||||
assertEquals("Failed to round properly - up to odd",
|
||||
3.0, round(2.9), 0.0)
|
||||
assertTrue("Failed to round properly - NaN", Double.isNaN(round(Double.NaN)))
|
||||
assertEquals("Failed to round properly down to even",
|
||||
2.0, round(2.1), 0.0)
|
||||
assertTrue("Failed to round properly " + 2.5 + " to even", round(2.5) == 2.0)
|
||||
assertTrue("Failed to round properly " + +0.0,
|
||||
round(+0.0) == +0.0)
|
||||
assertTrue("Failed to round properly " + -0.0,
|
||||
round(-0.0) == -0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.sign(Double)
|
||||
*/
|
||||
@Test fun sign_D() {
|
||||
assertTrue(Double.isNaN(sign(Double.NaN)))
|
||||
assertTrue(Double.isNaN(sign(Double.NaN)))
|
||||
assertEquals(0.0.toBits(), sign(0.0).toBits())
|
||||
assertEquals(+0.0.toBits(), sign(+0.0).toBits())
|
||||
assertEquals((-0.0).toBits(), sign(-0.0).toBits())
|
||||
|
||||
assertEquals(1.0, sign(253681.2187962), 0.0)
|
||||
assertEquals(-1.0, sign(-125874693.56), 0.0)
|
||||
assertEquals(1.0, sign(1.2587E-308), 0.0)
|
||||
assertEquals(-1.0, sign(-1.2587E-308), 0.0)
|
||||
|
||||
assertEquals(1.0, sign(Double.MAX_VALUE), 0.0)
|
||||
assertEquals(1.0, sign(Double.MIN_VALUE), 0.0)
|
||||
assertEquals(-1.0, sign(-Double.MAX_VALUE), 0.0)
|
||||
assertEquals(-1.0, sign(-Double.MIN_VALUE), 0.0)
|
||||
assertEquals(1.0, sign(Double.POSITIVE_INFINITY), 0.0)
|
||||
assertEquals(-1.0, sign(Double.NEGATIVE_INFINITY), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.sign(float)
|
||||
*/
|
||||
@Test fun sign_F() {
|
||||
assertTrue(Float.isNaN(sign(Float.NaN)))
|
||||
assertEquals(0.0f.toBits(), sign(0.0f).toBits())
|
||||
assertEquals(+0.0f.toBits(), sign(+0.0f).toBits())
|
||||
assertEquals((-0.0f).toBits(), sign(-0.0f).toBits())
|
||||
|
||||
assertEquals(1.0f, sign(253681.2187962f), 0f)
|
||||
assertEquals(-1.0f, sign(-125874693.56f), 0f)
|
||||
assertEquals(1.0f, sign(1.2587E-11f), 0f)
|
||||
assertEquals(-1.0f, sign(-1.2587E-11f), 0f)
|
||||
|
||||
assertEquals(1.0f, sign(Float.MAX_VALUE), 0f)
|
||||
assertEquals(1.0f, sign(Float.MIN_VALUE), 0f)
|
||||
assertEquals(-1.0f, sign(-Float.MAX_VALUE), 0f)
|
||||
assertEquals(-1.0f, sign(-Float.MIN_VALUE), 0f)
|
||||
assertEquals(1.0f, sign(Float.POSITIVE_INFINITY), 0f)
|
||||
assertEquals(-1.0f, sign(Float.NEGATIVE_INFINITY), 0f)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.sin(Double)
|
||||
*/
|
||||
@Test fun sinD() {
|
||||
// Test for sin(Double): Double
|
||||
assertEquals("Incorrect answer", 0.0, sin(0.0), 0.0)
|
||||
assertEquals("Incorrect answer", 0.8414709848078965, sin(1.0), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.sinh(Double)
|
||||
*/
|
||||
@Test fun sinh_D() {
|
||||
// Test for special situations
|
||||
assertTrue("Should return NaN", Double.isNaN(sinh(Double.NaN)))
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, sinh(Double.POSITIVE_INFINITY), 0.0)
|
||||
assertEquals("Should return NEGATIVE_INFINITY",
|
||||
Double.NEGATIVE_INFINITY, sinh(Double.NEGATIVE_INFINITY), 0.0)
|
||||
assertEquals(0.0.toBits(), sinh(0.0).toBits())
|
||||
assertEquals(+0.0.toBits(), sinh(+0.0).toBits())
|
||||
assertEquals((-0.0).toBits(), sinh(-0.0).toBits())
|
||||
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, sinh(1234.56), 0.0)
|
||||
assertEquals("Should return NEGATIVE_INFINITY",
|
||||
Double.NEGATIVE_INFINITY, sinh(-1234.56), 0.0)
|
||||
assertEquals("Should return 1.0000000000001666E-6",
|
||||
1.0000000000001666E-6, sinh(0.000001), 0.0)
|
||||
assertEquals("Should return -1.0000000000001666E-6",
|
||||
-1.0000000000001666E-6, sinh(-0.000001), 0.0)
|
||||
assertEquals("Should return 5.115386441963859", 5.115386441963859, sinh(2.33482))
|
||||
assertEquals("Should return POSITIVE_INFINITY",
|
||||
Double.POSITIVE_INFINITY, sinh(Double.MAX_VALUE), 0.0)
|
||||
assertEquals("Should return 4.9E-324", 4.9E-324, sinh(Double.MIN_VALUE), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.sqrt(Double)
|
||||
*/
|
||||
@Test fun sqrt_D() {
|
||||
// Test for sqrt(Double): Double
|
||||
assertEquals("Incorrect root returned2", 7.0, sqrt(49.0), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.tan(Double)
|
||||
*/
|
||||
@Test fun tan_D() {
|
||||
// Test for tan(Double): Double
|
||||
assertEquals("Incorrect answer", 0.0, tan(0.0), 0.0)
|
||||
assertEquals("Incorrect answer", 1.5574077246549023, tan(1.0))
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.math.tanh(Double)
|
||||
*/
|
||||
@Test fun tanh_D() {
|
||||
// Test for special situations
|
||||
assertTrue("Should return NaN", Double.isNaN(tanh(Double.NaN)))
|
||||
assertEquals("Should return +1.0", +1.0, tanh(Double.POSITIVE_INFINITY), 0.0)
|
||||
assertEquals("Should return -1.0", -1.0, tanh(Double.NEGATIVE_INFINITY), 0.0)
|
||||
assertEquals(0.0.toBits(), tanh(0.0).toBits())
|
||||
assertEquals(+0.0.toBits(), tanh(+0.0).toBits())
|
||||
assertEquals((-0.0).toBits(), tanh(-0.0).toBits())
|
||||
|
||||
assertEquals("Should return 1.0", 1.0, tanh(1234.56), 0.0)
|
||||
assertEquals("Should return -1.0", -1.0, tanh(-1234.56), 0.0)
|
||||
assertEquals("Should return 9.999999999996666E-7",
|
||||
9.999999999996666E-7, tanh(0.000001), 0.0)
|
||||
assertEquals("Should return 0.981422884124941", 0.981422884124941, tanh(2.33482), 0.0)
|
||||
assertEquals("Should return 1.0", 1.0, tanh(Double.MAX_VALUE), 0.0)
|
||||
assertEquals("Should return 4.9E-324", 4.9E-324, tanh(Double.MIN_VALUE), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.Double.ulp
|
||||
*/
|
||||
fun test_ulp_D() {
|
||||
// Test for special cases
|
||||
assertTrue("Should return NaN", Double.isNaN(ulp(Double.NaN)))
|
||||
assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, ulp(Double.POSITIVE_INFINITY), 0.0)
|
||||
assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, ulp(Double.NEGATIVE_INFINITY), 0.0)
|
||||
assertEquals("Returned incorrect value", Double.MIN_VALUE, ulp(0.0), 0.0)
|
||||
assertEquals("Returned incorrect value", Double.MIN_VALUE, ulp(+0.0), 0.0)
|
||||
assertEquals("Returned incorrect value", Double.MIN_VALUE, ulp(-0.0), 0.0)
|
||||
assertEquals("Returned incorrect value", pow(2.0, 971.0), ulp(Double.MAX_VALUE), 0.0)
|
||||
assertEquals("Returned incorrect value", pow(2.0, 971.0), ulp(-Double.MAX_VALUE), 0.0)
|
||||
|
||||
assertEquals("Returned incorrect value", Double.MIN_VALUE, ulp(Double.MIN_VALUE), 0.0)
|
||||
assertEquals("Returned incorrect value", Double.MIN_VALUE, ulp(-Double.MIN_VALUE), 0.0)
|
||||
|
||||
assertEquals("Returned incorrect value", 2.220446049250313E-16, ulp(1.0), 0.0)
|
||||
assertEquals("Returned incorrect value", 2.220446049250313E-16, ulp(-1.0), 0.0)
|
||||
assertEquals("Returned incorrect value", 2.2737367544323206E-13, ulp(1153.0), 0.0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests kotlin.Float.ulp
|
||||
*/
|
||||
fun test_ulp_f() {
|
||||
// Test for special cases
|
||||
assertTrue("Should return NaN", Float.isNaN(ulp(Float.NaN)))
|
||||
assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, ulp(Float.POSITIVE_INFINITY), 0f)
|
||||
assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, ulp(Float.NEGATIVE_INFINITY), 0f)
|
||||
assertEquals("Returned incorrect value", Float.MIN_VALUE, ulp(0.0f), 0f)
|
||||
assertEquals("Returned incorrect value", Float.MIN_VALUE, ulp(+0.0f), 0f)
|
||||
assertEquals("Returned incorrect value", Float.MIN_VALUE, ulp(-0.0f), 0f)
|
||||
assertEquals("Returned incorrect value", 2.028241E31f, ulp(Float.MAX_VALUE), 0f)
|
||||
assertEquals("Returned incorrect value", 2.028241E31f, ulp(-Float.MAX_VALUE), 0f)
|
||||
|
||||
assertEquals("Returned incorrect value", 1.4E-45f, ulp(Float.MIN_VALUE), 0f)
|
||||
assertEquals("Returned incorrect value", 1.4E-45f, ulp(-Float.MIN_VALUE), 0f)
|
||||
|
||||
assertEquals("Returned incorrect value", 1.1920929E-7f, ulp(1.0f),
|
||||
0f)
|
||||
assertEquals("Returned incorrect value", 1.1920929E-7f,
|
||||
ulp(-1.0f), 0f)
|
||||
assertEquals("Returned incorrect value", 1.2207031E-4f, ulp(1153.0f), 0f)
|
||||
assertEquals("Returned incorrect value", 5.6E-45f, ulp(9.403954E-38f), 0f)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val MIN_NORMAL_D: Double = 2.2250738585072014E-308
|
||||
const val MIN_NORMAL_F: Float = 1.1754943508222875E-38f
|
||||
|
||||
/**
|
||||
* cases for test_copySign_DD in est/Strictest
|
||||
*/
|
||||
internal val COPYSIGN_DD_CASES = doubleArrayOf(Double.POSITIVE_INFINITY, Double.MAX_VALUE, 3.4E302, 2.3,
|
||||
MIN_NORMAL_D, MIN_NORMAL_D / 2, Double.MIN_VALUE, +0.0, 0.0, -0.0, -Double.MIN_VALUE,
|
||||
-MIN_NORMAL_D / 2, -MIN_NORMAL_D, -4.5, -3.4E102, -Double.MAX_VALUE, Double.NEGATIVE_INFINITY)
|
||||
|
||||
/**
|
||||
* cases for test_copySign_FF in est/Strictest
|
||||
*/
|
||||
internal val COPYSIGN_FF_CASES = floatArrayOf(Float.POSITIVE_INFINITY, Float.MAX_VALUE, 3.4E12f, 2.3f,
|
||||
MIN_NORMAL_F, MIN_NORMAL_F / 2, Float.MIN_VALUE, +0.0f, 0.0f, -0.0f, -Float.MIN_VALUE,
|
||||
-MIN_NORMAL_F / 2, -MIN_NORMAL_F, -4.5f, -5.6442E21f, -Float.MAX_VALUE, Float.NEGATIVE_INFINITY)
|
||||
|
||||
/**
|
||||
* start number cases for test_nextTowards_DD in est/Strictest
|
||||
* NEXTAFTER_DD_START_CASES[i][0] is the start number
|
||||
* NEXTAFTER_DD_START_CASES[i][1] is the nextUp of start number
|
||||
* NEXTAFTER_DD_START_CASES[i][2] is the nextDown of start number
|
||||
*/
|
||||
internal val NEXTAFTER_DD_START_CASES = arrayOf(
|
||||
doubleArrayOf(3.4, 3.4000000000000004, 3.3999999999999995),
|
||||
doubleArrayOf(-3.4, -3.3999999999999995, -3.4000000000000004),
|
||||
doubleArrayOf(3.4233E109, 3.4233000000000005E109, 3.4232999999999996E109),
|
||||
doubleArrayOf(-3.4233E109, -3.4232999999999996E109, -3.4233000000000005E109),
|
||||
doubleArrayOf(+0.0, Double.MIN_VALUE, -Double.MIN_VALUE),
|
||||
doubleArrayOf(0.0, Double.MIN_VALUE, -Double.MIN_VALUE),
|
||||
doubleArrayOf(-0.0, Double.MIN_VALUE, -Double.MIN_VALUE),
|
||||
doubleArrayOf(Double.MIN_VALUE, 1.0E-323, +0.0),
|
||||
doubleArrayOf(-Double.MIN_VALUE, -0.0, -1.0E-323),
|
||||
doubleArrayOf(MIN_NORMAL_D, 2.225073858507202E-308, 2.225073858507201E-308),
|
||||
doubleArrayOf(-MIN_NORMAL_D, -2.225073858507201E-308, -2.225073858507202E-308),
|
||||
doubleArrayOf(Double.MAX_VALUE, Double.POSITIVE_INFINITY, 1.7976931348623155E308),
|
||||
doubleArrayOf(-Double.MAX_VALUE, -1.7976931348623155E308, Double.NEGATIVE_INFINITY),
|
||||
doubleArrayOf(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.MAX_VALUE),
|
||||
doubleArrayOf(Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, Double.NEGATIVE_INFINITY)
|
||||
)
|
||||
|
||||
/**
|
||||
* direction number cases for test_nextTowards_DD/test_nextTowards_FD in
|
||||
* est/Strictest
|
||||
*/
|
||||
internal val NEXTAFTER_DD_FD_DIRECTION_CASES = doubleArrayOf(Double.POSITIVE_INFINITY,
|
||||
Double.MAX_VALUE, 8.8, 3.4, 1.4, MIN_NORMAL_D, MIN_NORMAL_D / 2,
|
||||
Double.MIN_VALUE, +0.0, 0.0, -0.0, -Double.MIN_VALUE, -MIN_NORMAL_D / 2,
|
||||
-MIN_NORMAL_D, -1.4, -3.4, -8.8, -Double.MAX_VALUE, Double.NEGATIVE_INFINITY)
|
||||
|
||||
/**
|
||||
* start number cases for test_nextTowards_FD in est/Strictest
|
||||
* NEXTAFTER_FD_START_CASES[i][0] is the start number
|
||||
* NEXTAFTER_FD_START_CASES[i][1] is the nextUp of start number
|
||||
* NEXTAFTER_FD_START_CASES[i][2] is the nextDown of start number
|
||||
*/
|
||||
internal val NEXTAFTER_FD_START_CASES = arrayOf(floatArrayOf(3.4f, 3.4000003f, 3.3999999f),
|
||||
floatArrayOf(-3.4f, -3.3999999f, -3.4000003f),
|
||||
floatArrayOf(3.4233E19f, 3.4233002E19f, 3.4232998E19f),
|
||||
floatArrayOf(-3.4233E19f, -3.4232998E19f, -3.4233002E19f),
|
||||
floatArrayOf(+0.0f, Float.MIN_VALUE, -Float.MIN_VALUE),
|
||||
floatArrayOf(0.0f, Float.MIN_VALUE, -Float.MIN_VALUE),
|
||||
floatArrayOf(-0.0f, Float.MIN_VALUE, -Float.MIN_VALUE),
|
||||
floatArrayOf(Float.MIN_VALUE, 2.8E-45f, +0.0f),
|
||||
floatArrayOf(-Float.MIN_VALUE, -0.0f, -2.8E-45f),
|
||||
floatArrayOf(MIN_NORMAL_F, 1.1754945E-38f, 1.1754942E-38f),
|
||||
floatArrayOf(-MIN_NORMAL_F, -1.1754942E-38f, -1.1754945E-38f),
|
||||
floatArrayOf(Float.MAX_VALUE, Float.POSITIVE_INFINITY, 3.4028233E38f),
|
||||
floatArrayOf(-Float.MAX_VALUE, -3.4028233E38f, Float.NEGATIVE_INFINITY),
|
||||
floatArrayOf(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.MAX_VALUE),
|
||||
floatArrayOf(Float.NEGATIVE_INFINITY, -Float.MAX_VALUE, Float.NEGATIVE_INFINITY))
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package test.numbers
|
||||
|
||||
import kotlin.math.*
|
||||
import kotlin.test.*
|
||||
|
||||
class MathExceptionTest {
|
||||
|
||||
@Test fun exceptions() {
|
||||
assertFails { Double.NaN.roundToLong() }
|
||||
assertFails { Double.NaN.roundToInt() }
|
||||
|
||||
assertFails { Float.NaN.roundToLong() }
|
||||
assertFails { Float.NaN.roundToInt() }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,800 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package test.numbers
|
||||
|
||||
import kotlin.math.*
|
||||
import kotlin.test.*
|
||||
|
||||
fun assertAlmostEquals(expected: Double, actual: Double, tolerance: Double? = null) {
|
||||
val tolerance_ = tolerance?.let { abs(it) } ?: 0.000000000001
|
||||
if (abs(expected - actual) > tolerance_) {
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
fun assertAlmostEquals(expected: Float, actual: Float, tolerance: Double? = null) {
|
||||
val tolerance_ = tolerance?.let { abs(it) } ?: 0.0000001
|
||||
if (abs(expected - actual) > tolerance_) {
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
class DoubleMathTest {
|
||||
|
||||
@Test fun trigonometric() {
|
||||
assertEquals(0.0, sin(0.0))
|
||||
assertAlmostEquals(0.0, sin(PI))
|
||||
|
||||
assertEquals(0.0, asin(0.0))
|
||||
assertAlmostEquals(PI / 2, asin(1.0))
|
||||
|
||||
assertEquals(1.0, cos(0.0))
|
||||
assertAlmostEquals(-1.0, cos(PI))
|
||||
|
||||
assertEquals(0.0, acos(1.0))
|
||||
assertAlmostEquals(PI / 2, acos(0.0))
|
||||
|
||||
assertEquals(0.0, tan(0.0))
|
||||
assertAlmostEquals(1.0, tan(PI / 4))
|
||||
|
||||
assertAlmostEquals(0.0, atan(0.0))
|
||||
assertAlmostEquals(PI / 4, atan(1.0))
|
||||
|
||||
assertAlmostEquals(PI / 4, atan2(10.0, 10.0))
|
||||
assertAlmostEquals(-PI / 4, atan2(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY))
|
||||
assertAlmostEquals(0.0, atan2(0.0, 0.0))
|
||||
assertAlmostEquals(0.0, atan2(0.0, 10.0))
|
||||
assertAlmostEquals(PI / 2, atan2(2.0, 0.0))
|
||||
|
||||
for (angle in listOf(Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY)) {
|
||||
assertTrue(sin(angle).isNaN(), "sin($angle)")
|
||||
assertTrue(cos(angle).isNaN(), "cos($angle)")
|
||||
assertTrue(tan(angle).isNaN(), "tan($angle)")
|
||||
}
|
||||
|
||||
for (value in listOf(Double.NaN, 1.2, -1.1)) {
|
||||
assertTrue(asin(value).isNaN())
|
||||
assertTrue(acos(value).isNaN())
|
||||
}
|
||||
assertTrue(atan(Double.NaN).isNaN())
|
||||
assertTrue(atan2(Double.NaN, 0.0).isNaN())
|
||||
assertTrue(atan2(0.0, Double.NaN).isNaN())
|
||||
}
|
||||
|
||||
@Test fun hyperbolic() {
|
||||
assertEquals(Double.POSITIVE_INFINITY, sinh(Double.POSITIVE_INFINITY))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, sinh(Double.NEGATIVE_INFINITY))
|
||||
assertTrue(sinh(Double.MIN_VALUE) != 0.0)
|
||||
assertTrue(sinh(710.0).isFinite())
|
||||
assertTrue(sinh(-710.0).isFinite())
|
||||
assertTrue(sinh(Double.NaN).isNaN())
|
||||
|
||||
assertEquals(Double.POSITIVE_INFINITY, cosh(Double.POSITIVE_INFINITY))
|
||||
assertEquals(Double.POSITIVE_INFINITY, cosh(Double.NEGATIVE_INFINITY))
|
||||
assertTrue(cosh(710.0).isFinite())
|
||||
assertTrue(cosh(-710.0).isFinite())
|
||||
assertTrue(cosh(Double.NaN).isNaN())
|
||||
|
||||
assertAlmostEquals(1.0, tanh(Double.POSITIVE_INFINITY))
|
||||
assertAlmostEquals(-1.0, tanh(Double.NEGATIVE_INFINITY))
|
||||
assertTrue(tanh(Double.MIN_VALUE) != 0.0)
|
||||
assertTrue(tanh(Double.NaN).isNaN())
|
||||
}
|
||||
|
||||
@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 powers() {
|
||||
assertEquals(5.0, hypot(3.0, 4.0))
|
||||
assertEquals(Double.POSITIVE_INFINITY, hypot(Double.NEGATIVE_INFINITY, Double.NaN))
|
||||
assertEquals(Double.POSITIVE_INFINITY, hypot(Double.NaN, Double.POSITIVE_INFINITY))
|
||||
assertTrue(hypot(Double.NaN, 0.0).isNaN())
|
||||
|
||||
assertEquals(1.0, Double.NaN.pow(0.0))
|
||||
assertEquals(1.0, Double.POSITIVE_INFINITY.pow(0))
|
||||
assertEquals(49.0, 7.0.pow(2))
|
||||
assertEquals(0.25, 2.0.pow(-2))
|
||||
assertTrue(0.0.pow(Double.NaN).isNaN())
|
||||
assertTrue(Double.NaN.pow(-1).isNaN())
|
||||
assertTrue((-7.0).pow(1/3.0).isNaN())
|
||||
assertTrue(1.0.pow(Double.POSITIVE_INFINITY).isNaN())
|
||||
assertTrue((-1.0).pow(Double.NEGATIVE_INFINITY).isNaN())
|
||||
|
||||
assertEquals(5.0, sqrt(9.0 + 16.0))
|
||||
assertTrue(sqrt(-1.0).isNaN())
|
||||
assertTrue(sqrt(Double.NaN).isNaN())
|
||||
|
||||
assertTrue(exp(Double.NaN).isNaN())
|
||||
assertAlmostEquals(E, exp(1.0))
|
||||
assertEquals(1.0, exp(0.0))
|
||||
assertEquals(0.0, exp(Double.NEGATIVE_INFINITY))
|
||||
assertEquals(Double.POSITIVE_INFINITY, exp(Double.POSITIVE_INFINITY))
|
||||
|
||||
assertEquals(0.0, expm1(0.0))
|
||||
assertEquals(Double.MIN_VALUE, expm1(Double.MIN_VALUE))
|
||||
assertEquals(0.00010000500016667084, expm1(1e-4))
|
||||
assertEquals(-1.0, expm1(Double.NEGATIVE_INFINITY))
|
||||
assertEquals(Double.POSITIVE_INFINITY, expm1(Double.POSITIVE_INFINITY))
|
||||
}
|
||||
|
||||
@Test fun logarithms() {
|
||||
assertTrue(log(1.0, Double.NaN).isNaN())
|
||||
assertTrue(log(Double.NaN, 1.0).isNaN())
|
||||
assertTrue(log(-1.0, 2.0).isNaN())
|
||||
assertTrue(log(2.0, -1.0).isNaN())
|
||||
assertTrue(log(2.0, 0.0).isNaN())
|
||||
assertTrue(log(2.0, 1.0).isNaN())
|
||||
assertTrue(log(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY).isNaN())
|
||||
assertEquals(-2.0, log(0.25, 2.0))
|
||||
assertEquals(-0.5, log(2.0, 0.25))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, log(Double.POSITIVE_INFINITY, 0.25))
|
||||
assertEquals(Double.POSITIVE_INFINITY, log(Double.POSITIVE_INFINITY, 2.0))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, log(0.0, 2.0))
|
||||
assertEquals(Double.POSITIVE_INFINITY, log(0.0, 0.25))
|
||||
|
||||
assertTrue(ln(Double.NaN).isNaN())
|
||||
assertTrue(ln(-1.0).isNaN())
|
||||
assertEquals(1.0, ln(E))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, ln(0.0))
|
||||
assertEquals(Double.POSITIVE_INFINITY, ln(Double.POSITIVE_INFINITY))
|
||||
|
||||
assertEquals(1.0, log10(10.0))
|
||||
assertAlmostEquals(-1.0, log10(0.1))
|
||||
|
||||
assertAlmostEquals(3.0, log2(8.0))
|
||||
assertEquals(-1.0, log2(0.5))
|
||||
|
||||
assertTrue(ln1p(Double.NaN).isNaN())
|
||||
assertTrue(ln1p(-1.1).isNaN())
|
||||
assertEquals(0.0, ln1p(0.0))
|
||||
assertEquals(9.999995000003334e-7, ln1p(1e-6))
|
||||
assertEquals(Double.MIN_VALUE, ln1p(Double.MIN_VALUE))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, ln1p(-1.0))
|
||||
}
|
||||
|
||||
@Test fun rounding() {
|
||||
for (value in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0, 1.0, -10.0)) {
|
||||
assertEquals(value, ceil(value))
|
||||
assertEquals(value, floor(value))
|
||||
assertEquals(value, truncate(value))
|
||||
assertEquals(value, round(value))
|
||||
}
|
||||
assertTrue(ceil(Double.NaN).isNaN())
|
||||
assertTrue(floor(Double.NaN).isNaN())
|
||||
assertTrue(truncate(Double.NaN).isNaN())
|
||||
assertTrue(round(Double.NaN).isNaN())
|
||||
val data = arrayOf( // v floor trunc round ceil
|
||||
doubleArrayOf( 1.3, 1.0, 1.0, 1.0, 2.0),
|
||||
doubleArrayOf(-1.3, -2.0, -1.0, -1.0, -1.0),
|
||||
doubleArrayOf( 1.5, 1.0, 1.0, 2.0, 2.0),
|
||||
doubleArrayOf(-1.5, -2.0, -1.0, -2.0, -1.0),
|
||||
doubleArrayOf( 1.8, 1.0, 1.0, 2.0, 2.0),
|
||||
doubleArrayOf(-1.8, -2.0, -1.0, -2.0, -1.0),
|
||||
|
||||
doubleArrayOf( 2.3, 2.0, 2.0, 2.0, 3.0),
|
||||
doubleArrayOf(-2.3, -3.0, -2.0, -2.0, -2.0),
|
||||
doubleArrayOf( 2.5, 2.0, 2.0, 2.0, 3.0),
|
||||
doubleArrayOf(-2.5, -3.0, -2.0, -2.0, -2.0),
|
||||
doubleArrayOf( 2.8, 2.0, 2.0, 3.0, 3.0),
|
||||
doubleArrayOf(-2.8, -3.0, -2.0, -3.0, -2.0)
|
||||
)
|
||||
for ((v, f, t, r, c) in data) {
|
||||
assertEquals(f, floor(v), "floor($v)")
|
||||
assertEquals(t, truncate(v), "truncate($v)")
|
||||
assertEquals(r, round(v), "round($v)")
|
||||
assertEquals(c, ceil(v), "ceil($v)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun roundingConversion() {
|
||||
assertEquals(1L, 1.0.roundToLong())
|
||||
assertEquals(1L, 1.1.roundToLong())
|
||||
assertEquals(2L, 1.5.roundToLong())
|
||||
assertEquals(3L, 2.5.roundToLong())
|
||||
assertEquals(-2L, (-2.5).roundToLong())
|
||||
assertEquals(-3L, (-2.6).roundToLong())
|
||||
assertEquals(9223372036854774784, (9223372036854774800.0).roundToLong())
|
||||
assertEquals(Long.MAX_VALUE, Double.MAX_VALUE.roundToLong())
|
||||
assertEquals(Long.MIN_VALUE, (-Double.MAX_VALUE).roundToLong())
|
||||
assertEquals(Long.MAX_VALUE, Double.POSITIVE_INFINITY.roundToLong())
|
||||
assertEquals(Long.MIN_VALUE, Double.NEGATIVE_INFINITY.roundToLong())
|
||||
|
||||
assertEquals(1, 1.0.roundToInt())
|
||||
assertEquals(1, 1.1.roundToInt())
|
||||
assertEquals(2, 1.5.roundToInt())
|
||||
assertEquals(3, 2.5.roundToInt())
|
||||
assertEquals(-2, (-2.5).roundToInt())
|
||||
assertEquals(-3, (-2.6).roundToInt())
|
||||
assertEquals(2123456789, (2123456789.0).roundToInt())
|
||||
assertEquals(Int.MAX_VALUE, Double.MAX_VALUE.roundToInt())
|
||||
assertEquals(Int.MIN_VALUE, (-Double.MAX_VALUE).roundToInt())
|
||||
assertEquals(Int.MAX_VALUE, Double.POSITIVE_INFINITY.roundToInt())
|
||||
assertEquals(Int.MIN_VALUE, Double.NEGATIVE_INFINITY.roundToInt())
|
||||
}
|
||||
|
||||
@Test fun absoluteValue() {
|
||||
assertTrue(abs(Double.NaN).isNaN())
|
||||
assertTrue(Double.NaN.absoluteValue.isNaN())
|
||||
|
||||
for (value in listOf(0.0, Double.MIN_VALUE, 0.1, 1.0, 1000.0, Double.MAX_VALUE, Double.POSITIVE_INFINITY)) {
|
||||
assertEquals(value, value.absoluteValue)
|
||||
assertEquals(value, (-value).absoluteValue)
|
||||
assertEquals(value, abs(value))
|
||||
assertEquals(value, abs(-value))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun signs() {
|
||||
assertTrue(sign(Double.NaN).isNaN())
|
||||
assertTrue(Double.NaN.sign.isNaN())
|
||||
|
||||
val negatives = listOf(Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, -1.0, -Double.MIN_VALUE)
|
||||
for (value in negatives) {
|
||||
assertEquals(-1.0, sign(value))
|
||||
assertEquals(-1.0, value.sign)
|
||||
}
|
||||
|
||||
val zeroes = listOf(0.0, -0.0)
|
||||
for (value in zeroes) {
|
||||
assertEquals(value, sign(value))
|
||||
assertEquals(value, value.sign)
|
||||
}
|
||||
|
||||
|
||||
val positives = listOf(Double.POSITIVE_INFINITY, Double.MAX_VALUE, 1.0, Double.MIN_VALUE)
|
||||
for (value in positives) {
|
||||
assertEquals(1.0, sign(value))
|
||||
assertEquals(1.0, value.sign)
|
||||
}
|
||||
|
||||
val allValues = negatives + positives
|
||||
for (a in allValues) {
|
||||
for (b in allValues) {
|
||||
val r = a.withSign(b)
|
||||
assertEquals(a.absoluteValue, r.absoluteValue)
|
||||
assertEquals(b.sign, r.sign, "expected $a with sign bit of $b to have sign ${b.sign}")
|
||||
}
|
||||
|
||||
val rp0 = a.withSign(0.0)
|
||||
assertEquals(1.0, rp0.sign)
|
||||
assertEquals(a.absoluteValue, rp0.absoluteValue)
|
||||
|
||||
val rm0 = a.withSign(-0.0)
|
||||
assertEquals(-1.0, rm0.sign)
|
||||
assertEquals(a.absoluteValue, rm0.absoluteValue)
|
||||
|
||||
val ri = a.withSign(-1)
|
||||
assertEquals(-1.0, ri.sign)
|
||||
assertEquals(a.absoluteValue, ri.absoluteValue)
|
||||
|
||||
val rn = a.withSign(Double.NaN)
|
||||
assertEquals(a.absoluteValue, rn.absoluteValue)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun nextAndPrev() {
|
||||
for (value in listOf(0.0, -0.0, Double.MIN_VALUE, -1.0, 2.0.pow(10))) {
|
||||
val next = value.nextUp()
|
||||
if (next > 0) {
|
||||
assertEquals(next, value + value.ulp)
|
||||
} else {
|
||||
assertEquals(value, next - next.ulp)
|
||||
}
|
||||
|
||||
val prev = value.nextDown()
|
||||
if (prev > 0) {
|
||||
assertEquals(value, prev + prev.ulp)
|
||||
}
|
||||
else {
|
||||
assertEquals(prev, value - value.ulp)
|
||||
}
|
||||
|
||||
val toZero = value.nextTowards(0.0)
|
||||
if (toZero != 0.0) {
|
||||
assertEquals(value, toZero + toZero.ulp.withSign(toZero))
|
||||
}
|
||||
|
||||
assertEquals(Double.POSITIVE_INFINITY, Double.MAX_VALUE.nextUp())
|
||||
assertEquals(Double.MAX_VALUE, Double.POSITIVE_INFINITY.nextDown())
|
||||
|
||||
assertEquals(Double.NEGATIVE_INFINITY, (-Double.MAX_VALUE).nextDown())
|
||||
assertEquals((-Double.MAX_VALUE), Double.NEGATIVE_INFINITY.nextUp())
|
||||
|
||||
assertTrue(Double.NaN.ulp.isNaN())
|
||||
assertTrue(Double.NaN.nextDown().isNaN())
|
||||
assertTrue(Double.NaN.nextUp().isNaN())
|
||||
assertTrue(Double.NaN.nextTowards(0.0).isNaN())
|
||||
|
||||
assertEquals(Double.MIN_VALUE, (0.0).ulp)
|
||||
assertEquals(Double.MIN_VALUE, (-0.0).ulp)
|
||||
assertEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY.ulp)
|
||||
assertEquals(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY.ulp)
|
||||
|
||||
val maxUlp = 2.0.pow(971)
|
||||
assertEquals(maxUlp, Double.MAX_VALUE.ulp)
|
||||
assertEquals(maxUlp, (-Double.MAX_VALUE).ulp)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun IEEEremainder() {
|
||||
val data = arrayOf( // a a IEEErem 2.5
|
||||
doubleArrayOf(-2.0, 0.5),
|
||||
doubleArrayOf(-1.25, -1.25),
|
||||
doubleArrayOf( 0.0, 0.0),
|
||||
doubleArrayOf( 1.0, 1.0),
|
||||
doubleArrayOf( 1.25, 1.25),
|
||||
doubleArrayOf( 1.5, -1.0),
|
||||
doubleArrayOf( 2.0, -0.5),
|
||||
doubleArrayOf( 2.5, 0.0),
|
||||
doubleArrayOf( 3.5, 1.0),
|
||||
doubleArrayOf( 3.75, -1.25),
|
||||
doubleArrayOf( 4.0, -1.0)
|
||||
)
|
||||
for ((a, r) in data) {
|
||||
assertEquals(r, a.IEEErem(2.5), "($a).IEEErem(2.5)")
|
||||
}
|
||||
|
||||
assertTrue(Double.NaN.IEEErem(2.5).isNaN())
|
||||
assertTrue(2.0.IEEErem(Double.NaN).isNaN())
|
||||
assertTrue(Double.POSITIVE_INFINITY.IEEErem(2.0).isNaN())
|
||||
assertTrue(2.0.IEEErem(0.0).isNaN())
|
||||
assertEquals(PI, PI.IEEErem(Double.NEGATIVE_INFINITY))
|
||||
}
|
||||
|
||||
/*
|
||||
* Special cases:
|
||||
* - `atan2(0.0, 0.0)` is `0.0`
|
||||
* - `atan2(0.0, x)` is `0.0` for `x > 0` and `PI` for `x < 0`
|
||||
* - `atan2(-0.0, x)` is `-0.0` for 'x > 0` and `-PI` for `x < 0`
|
||||
* - `atan2(y, +Inf)` is `0.0` for `0 < y < +Inf` and `-0.0` for '-Inf < y < 0`
|
||||
* - `atan2(y, -Inf)` is `PI` for `0 < y < +Inf` and `-PI` for `-Inf < y < 0`
|
||||
* - `atan2(y, 0.0)` is `PI/2` for `y > 0` and `-PI/2` for `y < 0`
|
||||
* - `atan2(+Inf, x)` is `PI/2` for finite `x`y
|
||||
* - `atan2(-Inf, x)` is `-PI/2` for finite `x`
|
||||
* - `atan2(NaN, x)` and `atan2(y, NaN)` is `NaN`
|
||||
*/
|
||||
@Test fun atan2SpecialCases() {
|
||||
|
||||
assertEquals(atan2(0.0, 0.0), 0.0)
|
||||
assertEquals(atan2(0.0, 1.0), 0.0)
|
||||
assertEquals(atan2(0.0, -1.0), PI)
|
||||
assertEquals(atan2(-0.0, 1.0), -0.0)
|
||||
assertEquals(atan2(-0.0, -1.0), -PI)
|
||||
assertEquals(atan2(1.0, Double.POSITIVE_INFINITY), 0.0)
|
||||
assertEquals(atan2(-1.0, Double.POSITIVE_INFINITY), -0.0)
|
||||
assertEquals(atan2(1.0, Double.NEGATIVE_INFINITY), PI)
|
||||
assertEquals(atan2(-1.0, Double.NEGATIVE_INFINITY), -PI)
|
||||
assertEquals(atan2(1.0, 0.0), PI/2)
|
||||
assertEquals(atan2(-1.0, 0.0), -PI/2)
|
||||
assertEquals(atan2(Double.POSITIVE_INFINITY, 1.0), PI/2)
|
||||
assertEquals(atan2(Double.NEGATIVE_INFINITY, 1.0), -PI/2)
|
||||
|
||||
assertTrue(atan2(Double.NaN, 1.0).isNaN())
|
||||
assertTrue(atan2(1.0, Double.NaN).isNaN())
|
||||
}
|
||||
}
|
||||
|
||||
class FloatMathTest {
|
||||
|
||||
companion object {
|
||||
const val PI = kotlin.math.PI.toFloat()
|
||||
const val E = kotlin.math.E.toFloat()
|
||||
}
|
||||
|
||||
@Test fun trigonometric() {
|
||||
assertEquals(0.0F, sin(0.0F))
|
||||
assertAlmostEquals(0.0F, sin(PI))
|
||||
|
||||
assertEquals(0.0F, asin(0.0F))
|
||||
assertAlmostEquals(PI / 2, asin(1.0F), 0.0000002)
|
||||
|
||||
assertEquals(1.0F, cos(0.0F))
|
||||
assertAlmostEquals(-1.0F, cos(PI))
|
||||
|
||||
assertEquals(0.0F, acos(1.0F))
|
||||
assertAlmostEquals(PI / 2, acos(0.0F))
|
||||
|
||||
assertEquals(0.0F, tan(0.0F))
|
||||
assertAlmostEquals(1.0F, tan(PI / 4))
|
||||
|
||||
assertAlmostEquals(0.0F, atan(0.0F))
|
||||
assertAlmostEquals(PI / 4, atan(1.0F))
|
||||
|
||||
assertAlmostEquals(PI / 4, atan2(10.0F, 10.0F))
|
||||
assertAlmostEquals(-PI / 4, atan2(Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY))
|
||||
assertAlmostEquals(0.0F, atan2(0.0F, 0.0F))
|
||||
assertAlmostEquals(0.0F, atan2(0.0F, 10.0F))
|
||||
assertAlmostEquals(PI / 2, atan2(2.0F, 0.0F))
|
||||
|
||||
for (angle in listOf(Float.NaN, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY)) {
|
||||
assertTrue(sin(angle).isNaN(), "sin($angle)")
|
||||
assertTrue(cos(angle).isNaN(), "cos($angle)")
|
||||
assertTrue(tan(angle).isNaN(), "tan($angle)")
|
||||
}
|
||||
|
||||
for (value in listOf(Float.NaN, 1.2F, -1.1F)) {
|
||||
assertTrue(asin(value).isNaN())
|
||||
assertTrue(acos(value).isNaN())
|
||||
}
|
||||
assertTrue(atan(Float.NaN).isNaN())
|
||||
assertTrue(atan2(Float.NaN, 0.0F).isNaN())
|
||||
assertTrue(atan2(0.0F, Float.NaN).isNaN())
|
||||
}
|
||||
|
||||
@Test fun hyperbolic() {
|
||||
assertEquals(Float.POSITIVE_INFINITY, sinh(Float.POSITIVE_INFINITY))
|
||||
assertEquals(Float.NEGATIVE_INFINITY, sinh(Float.NEGATIVE_INFINITY))
|
||||
assertTrue(sinh(Float.MIN_VALUE) != 0.0F)
|
||||
assertTrue(sinh(89.0F).isFinite())
|
||||
assertTrue(sinh(-89.0F).isFinite())
|
||||
assertTrue(sinh(Float.NaN).isNaN())
|
||||
|
||||
assertEquals(Float.POSITIVE_INFINITY, cosh(Float.POSITIVE_INFINITY))
|
||||
assertEquals(Float.POSITIVE_INFINITY, cosh(Float.NEGATIVE_INFINITY))
|
||||
assertTrue(cosh(89.0F).isFinite())
|
||||
assertTrue(cosh(-89.0F).isFinite())
|
||||
assertTrue(cosh(Float.NaN).isNaN())
|
||||
|
||||
assertAlmostEquals(1.0F, tanh(Float.POSITIVE_INFINITY))
|
||||
assertAlmostEquals(-1.0F, tanh(Float.NEGATIVE_INFINITY))
|
||||
assertTrue(tanh(Float.MIN_VALUE) != 0.0F)
|
||||
assertTrue(tanh(Float.NaN).isNaN())
|
||||
}
|
||||
|
||||
@Test fun inverseHyperbolicSin() {
|
||||
for (exact in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 0.0F, Float.MIN_VALUE, -Float.MIN_VALUE, 0.00001F)) {
|
||||
assertEquals(exact, asinh(sinh(exact)))
|
||||
}
|
||||
for (approx in listOf(Float.MIN_VALUE, 0.1F, 1.0F, 89.0F)) {
|
||||
assertAlmostEquals(approx, asinh(sinh(approx)))
|
||||
assertAlmostEquals(-approx, asinh(sinh(-approx)))
|
||||
}
|
||||
assertTrue(asinh(Float.NaN).isNaN())
|
||||
}
|
||||
|
||||
@Test fun inverseHyperbolicCos() {
|
||||
for (exact in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 0.0F)) {
|
||||
assertEquals(abs(exact), acosh(cosh(exact)))
|
||||
}
|
||||
for (approx in listOf(Float.MIN_VALUE, 0.1F, 1.0F, 89.0F)) {
|
||||
assertAlmostEquals(approx, acosh(cosh(approx)))
|
||||
assertAlmostEquals(approx, acosh(cosh(-approx)))
|
||||
}
|
||||
for (invalid in listOf(-1.0F, 0.0F, 0.99999F, Float.NaN)) {
|
||||
assertTrue(acosh(invalid).isNaN())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun inverseHyperbolicTan() {
|
||||
for (exact in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 0.0F, Float.MIN_VALUE, -Float.MIN_VALUE)) {
|
||||
assertEquals(exact, atanh(tanh(exact)))
|
||||
}
|
||||
|
||||
for (approx in listOf(0.00001F)) {
|
||||
assertAlmostEquals(approx, atanh(tanh(approx)))
|
||||
}
|
||||
|
||||
for (invalid in listOf(-1.00001F, 1.00001F, Float.NaN, Float.MAX_VALUE, -Float.MAX_VALUE, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY)) {
|
||||
assertTrue(atanh(invalid).isNaN())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun powers() {
|
||||
assertEquals(5.0F, hypot(3.0F, 4.0F))
|
||||
assertEquals(Float.POSITIVE_INFINITY, hypot(Float.NEGATIVE_INFINITY, Float.NaN))
|
||||
assertEquals(Float.POSITIVE_INFINITY, hypot(Float.NaN, Float.POSITIVE_INFINITY))
|
||||
assertTrue(hypot(Float.NaN, 0.0F).isNaN())
|
||||
|
||||
assertEquals(1.0F, Float.NaN.pow(0.0F))
|
||||
assertEquals(1.0F, Float.POSITIVE_INFINITY.pow(0))
|
||||
assertEquals(49.0F, 7.0F.pow(2))
|
||||
assertEquals(0.25F, 2.0F.pow(-2))
|
||||
assertTrue(0.0F.pow(Float.NaN).isNaN())
|
||||
assertTrue(Float.NaN.pow(-1).isNaN())
|
||||
assertTrue((-7.0F).pow(1/3.0F).isNaN())
|
||||
assertTrue(1.0F.pow(Float.POSITIVE_INFINITY).isNaN())
|
||||
assertTrue((-1.0F).pow(Float.NEGATIVE_INFINITY).isNaN())
|
||||
|
||||
assertEquals(5.0F, sqrt(9.0F + 16.0F))
|
||||
assertTrue(sqrt(-1.0F).isNaN())
|
||||
assertTrue(sqrt(Float.NaN).isNaN())
|
||||
|
||||
assertTrue(exp(Float.NaN).isNaN())
|
||||
assertAlmostEquals(E, exp(1.0F))
|
||||
assertEquals(1.0F, exp(0.0F))
|
||||
assertEquals(0.0F, exp(Float.NEGATIVE_INFINITY))
|
||||
assertEquals(Float.POSITIVE_INFINITY, exp(Float.POSITIVE_INFINITY))
|
||||
|
||||
assertEquals(0.0F, expm1(0.0F))
|
||||
assertEquals(-1.0F, expm1(Float.NEGATIVE_INFINITY))
|
||||
assertEquals(Float.POSITIVE_INFINITY, expm1(Float.POSITIVE_INFINITY))
|
||||
}
|
||||
|
||||
@Test fun logarithms() {
|
||||
assertTrue(log(1.0F, Float.NaN).isNaN())
|
||||
assertTrue(log(Float.NaN, 1.0F).isNaN())
|
||||
assertTrue(log(-1.0F, 2.0F).isNaN())
|
||||
assertTrue(log(2.0F, -1.0F).isNaN())
|
||||
assertTrue(log(2.0F, 0.0F).isNaN())
|
||||
assertTrue(log(2.0F, 1.0F).isNaN())
|
||||
assertTrue(log(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY).isNaN())
|
||||
assertEquals(-2.0F, log(0.25F, 2.0F))
|
||||
assertEquals(-0.5F, log(2.0F, 0.25F))
|
||||
assertEquals(Float.NEGATIVE_INFINITY, log(Float.POSITIVE_INFINITY, 0.25F))
|
||||
assertEquals(Float.POSITIVE_INFINITY, log(Float.POSITIVE_INFINITY, 2.0F))
|
||||
assertEquals(Float.NEGATIVE_INFINITY, log(0.0F, 2.0F))
|
||||
assertEquals(Float.POSITIVE_INFINITY, log(0.0F, 0.25F))
|
||||
|
||||
assertTrue(ln(Float.NaN).isNaN())
|
||||
assertTrue(ln(-1.0F).isNaN())
|
||||
assertAlmostEquals(1.0F, ln(E))
|
||||
assertEquals(Float.NEGATIVE_INFINITY, ln(0.0F))
|
||||
assertEquals(Float.POSITIVE_INFINITY, ln(Float.POSITIVE_INFINITY))
|
||||
|
||||
assertEquals(1.0F, log10(10.0F))
|
||||
assertAlmostEquals(-1.0F, log10(0.1F))
|
||||
|
||||
assertAlmostEquals(3.0F, log2(8.0F))
|
||||
assertEquals(-1.0F, log2(0.5F))
|
||||
|
||||
assertTrue(ln1p(Float.NaN).isNaN())
|
||||
assertTrue(ln1p(-1.1F).isNaN())
|
||||
assertEquals(0.0F, ln1p(0.0F))
|
||||
assertEquals(Float.NEGATIVE_INFINITY, ln1p(-1.0F))
|
||||
}
|
||||
|
||||
@Test fun rounding() {
|
||||
for (value in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 0.0F, 1.0F, -10.0F)) {
|
||||
assertEquals(value, ceil(value))
|
||||
assertEquals(value, floor(value))
|
||||
assertEquals(value, truncate(value))
|
||||
assertEquals(value, round(value))
|
||||
}
|
||||
assertTrue(ceil(Float.NaN).isNaN())
|
||||
assertTrue(floor(Float.NaN).isNaN())
|
||||
assertTrue(truncate(Float.NaN).isNaN())
|
||||
assertTrue(round(Float.NaN).isNaN())
|
||||
val data = arrayOf( // v floor trunc round ceil
|
||||
floatArrayOf( 1.3F, 1.0F, 1.0F, 1.0F, 2.0F),
|
||||
floatArrayOf(-1.3F, -2.0F, -1.0F, -1.0F, -1.0F),
|
||||
floatArrayOf( 1.5F, 1.0F, 1.0F, 2.0F, 2.0F),
|
||||
floatArrayOf(-1.5F, -2.0F, -1.0F, -2.0F, -1.0F),
|
||||
floatArrayOf( 1.8F, 1.0F, 1.0F, 2.0F, 2.0F),
|
||||
floatArrayOf(-1.8F, -2.0F, -1.0F, -2.0F, -1.0F),
|
||||
|
||||
floatArrayOf( 2.3F, 2.0F, 2.0F, 2.0F, 3.0F),
|
||||
floatArrayOf(-2.3F, -3.0F, -2.0F, -2.0F, -2.0F),
|
||||
floatArrayOf( 2.5F, 2.0F, 2.0F, 2.0F, 3.0F),
|
||||
floatArrayOf(-2.5F, -3.0F, -2.0F, -2.0F, -2.0F),
|
||||
floatArrayOf( 2.8F, 2.0F, 2.0F, 3.0F, 3.0F),
|
||||
floatArrayOf(-2.8F, -3.0F, -2.0F, -3.0F, -2.0F)
|
||||
)
|
||||
for ((v, f, t, r, c) in data) {
|
||||
assertEquals(f, floor(v), "floor($v)")
|
||||
assertEquals(t, truncate(v), "truncate($v)")
|
||||
assertEquals(r, round(v), "round($v)")
|
||||
assertEquals(c, ceil(v), "ceil($v)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun roundingConversion() {
|
||||
assertEquals(1L, 1.0F.roundToLong())
|
||||
assertEquals(1L, 1.1F.roundToLong())
|
||||
assertEquals(2L, 1.5F.roundToLong())
|
||||
assertEquals(3L, 2.5F.roundToLong())
|
||||
assertEquals(-2L, (-2.5F).roundToLong())
|
||||
assertEquals(-3L, (-2.6F).roundToLong())
|
||||
// assertEquals(9223372036854774784, (9223372036854774800.0F).roundToLong()) // platform-specific
|
||||
assertEquals(Long.MAX_VALUE, Float.MAX_VALUE.roundToLong())
|
||||
assertEquals(Long.MIN_VALUE, (-Float.MAX_VALUE).roundToLong())
|
||||
assertEquals(Long.MAX_VALUE, Float.POSITIVE_INFINITY.roundToLong())
|
||||
assertEquals(Long.MIN_VALUE, Float.NEGATIVE_INFINITY.roundToLong())
|
||||
|
||||
assertEquals(1, 1.0F.roundToInt())
|
||||
assertEquals(1, 1.1F.roundToInt())
|
||||
assertEquals(2, 1.5F.roundToInt())
|
||||
assertEquals(3, 2.5F.roundToInt())
|
||||
assertEquals(-2, (-2.5F).roundToInt())
|
||||
assertEquals(-3, (-2.6F).roundToInt())
|
||||
assertEquals(16777218, (16777218F).roundToInt())
|
||||
assertEquals(Int.MAX_VALUE, Float.MAX_VALUE.roundToInt())
|
||||
assertEquals(Int.MIN_VALUE, (-Float.MAX_VALUE).roundToInt())
|
||||
assertEquals(Int.MAX_VALUE, Float.POSITIVE_INFINITY.roundToInt())
|
||||
assertEquals(Int.MIN_VALUE, Float.NEGATIVE_INFINITY.roundToInt())
|
||||
}
|
||||
|
||||
@Test fun absoluteValue() {
|
||||
assertTrue(abs(Float.NaN).isNaN())
|
||||
assertTrue(Float.NaN.absoluteValue.isNaN())
|
||||
|
||||
for (value in listOf(0.0F, Float.MIN_VALUE, 0.1F, 1.0F, 1000.0F, Float.MAX_VALUE, Float.POSITIVE_INFINITY)) {
|
||||
assertEquals(value, value.absoluteValue)
|
||||
assertEquals(value, (-value).absoluteValue)
|
||||
assertEquals(value, abs(value))
|
||||
assertEquals(value, abs(-value))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun signs() {
|
||||
assertTrue(sign(Float.NaN).isNaN())
|
||||
assertTrue(Float.NaN.sign.isNaN())
|
||||
|
||||
val negatives = listOf(Float.NEGATIVE_INFINITY, -Float.MAX_VALUE, -1.0F, -Float.MIN_VALUE)
|
||||
for (value in negatives) {
|
||||
assertEquals(-1.0F, sign(value))
|
||||
assertEquals(-1.0F, value.sign)
|
||||
}
|
||||
|
||||
val zeroes = listOf(0.0F, -0.0F)
|
||||
for (value in zeroes) {
|
||||
assertEquals(value, sign(value))
|
||||
assertEquals(value, value.sign)
|
||||
}
|
||||
|
||||
|
||||
val positives = listOf(Float.POSITIVE_INFINITY, Float.MAX_VALUE, 1.0F, Float.MIN_VALUE)
|
||||
for (value in positives) {
|
||||
assertEquals(1.0F, sign(value))
|
||||
assertEquals(1.0F, value.sign)
|
||||
}
|
||||
|
||||
val allValues = negatives + positives
|
||||
for (a in allValues) {
|
||||
for (b in allValues) {
|
||||
val r = a.withSign(b)
|
||||
assertEquals(a.absoluteValue, r.absoluteValue)
|
||||
assertEquals(b.sign, r.sign)
|
||||
}
|
||||
|
||||
val rp0 = a.withSign(0.0F)
|
||||
assertEquals(1.0F, rp0.sign)
|
||||
assertEquals(a.absoluteValue, rp0.absoluteValue)
|
||||
|
||||
val rm0 = a.withSign(-0.0F)
|
||||
assertEquals(-1.0F, rm0.sign)
|
||||
assertEquals(a.absoluteValue, rm0.absoluteValue)
|
||||
|
||||
val ri = a.withSign(-1)
|
||||
assertEquals(-1.0F, ri.sign)
|
||||
assertEquals(a.absoluteValue, ri.absoluteValue)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun nextAndPrev() {
|
||||
for (value in listOf(0.0f, -0.0f, Float.MIN_VALUE, -1.0f, 2.0f.pow(10))) {
|
||||
val next = value.nextUp()
|
||||
if (next > 0) {
|
||||
assertEquals(next, value + value.ulp)
|
||||
} else {
|
||||
assertEquals(value, next - next.ulp)
|
||||
}
|
||||
|
||||
val prev = value.nextDown()
|
||||
if (prev > 0) {
|
||||
assertEquals(value, prev + prev.ulp)
|
||||
}
|
||||
else {
|
||||
assertEquals(prev, value - value.ulp)
|
||||
}
|
||||
|
||||
val toZero = value.nextTowards(0.0f)
|
||||
if (toZero != 0.0f) {
|
||||
assertEquals(value, toZero + toZero.ulp.withSign(toZero))
|
||||
}
|
||||
|
||||
assertEquals(Float.POSITIVE_INFINITY, Float.MAX_VALUE.nextUp())
|
||||
assertEquals(Float.MAX_VALUE, Float.POSITIVE_INFINITY.nextDown())
|
||||
|
||||
assertEquals(Float.NEGATIVE_INFINITY, (-Float.MAX_VALUE).nextDown())
|
||||
assertEquals((-Float.MAX_VALUE), Float.NEGATIVE_INFINITY.nextUp())
|
||||
|
||||
assertTrue(Float.NaN.ulp.isNaN())
|
||||
assertTrue(Float.NaN.nextDown().isNaN())
|
||||
assertTrue(Float.NaN.nextUp().isNaN())
|
||||
assertTrue(Float.NaN.nextTowards(0.0f).isNaN())
|
||||
|
||||
assertEquals(Float.MIN_VALUE, (0.0f).ulp)
|
||||
assertEquals(Float.MIN_VALUE, (-0.0f).ulp)
|
||||
assertEquals(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY.ulp)
|
||||
assertEquals(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY.ulp)
|
||||
|
||||
val maxUlp = 2.0f.pow(104)
|
||||
assertEquals(maxUlp, Float.MAX_VALUE.ulp)
|
||||
assertEquals(maxUlp, (-Float.MAX_VALUE).ulp)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun IEEEremainder() {
|
||||
val data = arrayOf( // a a IEEErem 2.5
|
||||
floatArrayOf(-2.0f, 0.5f),
|
||||
floatArrayOf(-1.25f, -1.25f),
|
||||
floatArrayOf( 0.0f, 0.0f),
|
||||
floatArrayOf( 1.0f, 1.0f),
|
||||
floatArrayOf( 1.25f, 1.25f),
|
||||
floatArrayOf( 1.5f, -1.0f),
|
||||
floatArrayOf( 2.0f, -0.5f),
|
||||
floatArrayOf( 2.5f, 0.0f),
|
||||
floatArrayOf( 3.5f, 1.0f),
|
||||
floatArrayOf( 3.75f, -1.25f),
|
||||
floatArrayOf( 4.0f, -1.0f)
|
||||
)
|
||||
for ((a, r) in data) {
|
||||
assertEquals(r, a.IEEErem(2.5f), "($a).IEEErem(2.5f)")
|
||||
}
|
||||
|
||||
assertTrue(Float.NaN.IEEErem(2.5f).isNaN())
|
||||
assertTrue(2.0f.IEEErem(Float.NaN).isNaN())
|
||||
assertTrue(Float.POSITIVE_INFINITY.IEEErem(2.0f).isNaN())
|
||||
assertTrue(2.0f.IEEErem(0.0f).isNaN())
|
||||
assertEquals(PI.toFloat(), PI.toFloat().IEEErem(Float.NEGATIVE_INFINITY))
|
||||
}
|
||||
}
|
||||
|
||||
class IntegerMathTest {
|
||||
|
||||
@Test
|
||||
fun intSigns() {
|
||||
val negatives = listOf(Int.MIN_VALUE, -65536, -1)
|
||||
val positives = listOf(1, 100, 256, Int.MAX_VALUE)
|
||||
negatives.forEach { assertEquals(-1, it.sign) }
|
||||
positives.forEach { assertEquals(1, it.sign) }
|
||||
assertEquals(0, 0.sign)
|
||||
|
||||
(negatives - Int.MIN_VALUE).forEach { assertEquals(-it, it.absoluteValue) }
|
||||
assertEquals(Int.MIN_VALUE, Int.MIN_VALUE.absoluteValue)
|
||||
|
||||
positives.forEach { assertEquals(it, it.absoluteValue) }
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun longSigns() {
|
||||
val negatives = listOf(Long.MIN_VALUE, -65536L, -1L)
|
||||
val positives = listOf(1L, 100L, 256L, Long.MAX_VALUE)
|
||||
negatives.forEach { assertEquals(-1, it.sign) }
|
||||
positives.forEach { assertEquals(1, it.sign) }
|
||||
assertEquals(0, 0L.sign)
|
||||
|
||||
(negatives - Long.MIN_VALUE).forEach { assertEquals(-it, it.absoluteValue) }
|
||||
assertEquals(Long.MIN_VALUE, Long.MIN_VALUE.absoluteValue)
|
||||
|
||||
positives.forEach { assertEquals(it, it.absoluteValue) }
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
|
||||
package test.text
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class CharNativeTest {
|
||||
|
||||
@Test
|
||||
fun lowercaseChar() {
|
||||
// large mapping
|
||||
assertEquals('\u0239', '\u0239'.lowercaseChar())
|
||||
assertEquals('\u2C65', '\u023A'.lowercaseChar())
|
||||
assertEquals('\u023C', '\u023B'.lowercaseChar())
|
||||
|
||||
// large negative mapping
|
||||
assertEquals('\u2C7D', '\u2C7D'.lowercaseChar())
|
||||
assertEquals('\u023F', '\u2C7E'.lowercaseChar())
|
||||
assertEquals('\u0240', '\u2C7F'.lowercaseChar())
|
||||
|
||||
// <Lu, Ll>
|
||||
assertEquals('\u2C81', '\u2C80'.lowercaseChar())
|
||||
assertEquals('\u2C81', '\u2C81'.lowercaseChar())
|
||||
assertEquals('\u2C83', '\u2C82'.lowercaseChar())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uppercaseChar() {
|
||||
// large mapping
|
||||
assertEquals('\u029C', '\u029C'.uppercaseChar())
|
||||
assertEquals('\uA7B2', '\u029D'.uppercaseChar())
|
||||
assertEquals('\uA7B0', '\u029E'.uppercaseChar())
|
||||
assertEquals('\u029F', '\u029F'.uppercaseChar())
|
||||
|
||||
// large negative mapping
|
||||
assertEquals('\uAB6F', '\uAB6F'.uppercaseChar())
|
||||
assertEquals('\u13A0', '\uAB70'.uppercaseChar())
|
||||
assertEquals('\u13EF', '\uABBF'.uppercaseChar())
|
||||
assertEquals('\uABC0', '\uABC0'.uppercaseChar())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun titlecaseChar() {
|
||||
// titlecaseChar == char && uppercaseChar != char
|
||||
assertEquals('\u10CF'.uppercaseChar(), '\u10CF'.titlecaseChar())
|
||||
for (char in '\u10D0'..'\u10FA') {
|
||||
assertEquals(char, char.titlecaseChar())
|
||||
assertNotEquals(char, char.uppercaseChar())
|
||||
}
|
||||
for (char in '\u10FB'..'\u10FC') {
|
||||
assertEquals(char, char.titlecaseChar())
|
||||
assertEquals(char, char.uppercaseChar())
|
||||
}
|
||||
for (char in '\u10FD'..'\u10FF') {
|
||||
assertEquals(char, char.titlecaseChar())
|
||||
assertNotEquals(char, char.uppercaseChar())
|
||||
}
|
||||
assertEquals('\u1100'.uppercaseChar(), '\u1100'.titlecaseChar())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lowercase() {
|
||||
// LATIN CAPITAL LETTER I WITH DOT ABOVE
|
||||
assertEquals("\u0069\u0307", '\u0130'.lowercase())
|
||||
}
|
||||
|
||||
fun titlecase() {
|
||||
// titlecase = titlecaseChar = char != uppercaseChar
|
||||
assertEquals('\u10F0'.titlecaseChar().toString(), '\u10F0'.titlecase())
|
||||
assertEquals('\u10F0', '\u10F0'.titlecaseChar())
|
||||
assertNotEquals('\u10F0', '\u10F0'.uppercaseChar())
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
@file:OptIn(FreezingIsDeprecated::class)
|
||||
|
||||
package test.text
|
||||
|
||||
|
||||
internal actual val surrogateCodePointDecoding: String = "\uFFFD".repeat(3)
|
||||
|
||||
internal actual val surrogateCharEncoding: ByteArray = byteArrayOf(0xEF.toByte(), 0xBF.toByte(), 0xBD.toByte())
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package test.text
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class StringNativeTest {
|
||||
|
||||
@Test
|
||||
fun lowercase() {
|
||||
// Non-ASCII
|
||||
assertEquals("\u214E\uA7B5\u2CEF", "\u2132\uA7B4\u2CEF".lowercase())
|
||||
|
||||
// Surrogate pairs
|
||||
assertEquals("\uD801\uDC4F\uD806\uDCD0\uD81B\uDE7F", "\uD801\uDC27\uD806\uDCB0\uD81B\uDE5F".lowercase())
|
||||
|
||||
// Special Casing
|
||||
// LATIN CAPITAL LETTER I WITH DOT ABOVE
|
||||
assertEquals("\u0069\u0307", "\u0130".lowercase())
|
||||
assertEquals("a\u0069\u0307z", "a\u0130Z".lowercase())
|
||||
|
||||
// Final_Sigma
|
||||
run {
|
||||
fun caseIgnorable(length: Int): String {
|
||||
return listOf(
|
||||
"\u0483", // COMBINING CYRILLIC TITLO; Mn
|
||||
"\u20DF", // COMBINING ENCLOSING DIAMOND; Me
|
||||
"\uD804\uDCBD", // 110BD; KAITHI NUMBER SIGN; Cf
|
||||
"\u2C7D", // MODIFIER LETTER CAPITAL V; Lm
|
||||
"\uD83C\uDFFD", // 1F3FD; EMOJI MODIFIER FITZPATRICK TYPE-4; Sk
|
||||
"\u003A", // COLON; Po; Word_Break=MidLetter
|
||||
"\uFF0E", // FULLWIDTH FULL STOP; Po; Word_Break=MidNumLet
|
||||
"\u0027" // APOSTROPHE; Po; Word_Break=Single_Quote
|
||||
).shuffled().take(length).joinToString(separator = "")
|
||||
}
|
||||
|
||||
fun cased(): String {
|
||||
return listOf(
|
||||
"\u0041", // LATIN CAPITAL LETTER A; Lu
|
||||
"\uD81B\uDE63", // 16E63; MEDEFAIDRIN SMALL LETTER W; Ll
|
||||
"\u01CB", // LATIN CAPITAL LETTER N WITH SMALL LETTER J; Lt
|
||||
"\u217A", // SMALL ROMAN NUMERAL ELEVEN; Nl; Other_Lowercase
|
||||
"\uD83C\uDD50" // 1F150; NEGATIVE CIRCLED LATIN CAPITAL LETTER A; So; Other_Uppercase
|
||||
).random()
|
||||
}
|
||||
|
||||
fun other(): String {
|
||||
return listOf(
|
||||
"\u0000", // <control>; Cc
|
||||
"\u0030", // DIGIT ZERO; Nd
|
||||
"\uD838\uDEC6" // 1E2C6; WANCHO LETTER YA; Lo
|
||||
).random()
|
||||
}
|
||||
|
||||
fun Char.hex(): String {
|
||||
return code.toString(16).padStart(4, '0')
|
||||
}
|
||||
|
||||
val sigma = '\u03A3'
|
||||
val lowerSigma = '\u03C3'
|
||||
val specialLowerSigma = '\u03C2'
|
||||
|
||||
// Build a string of the form: [cased][other](caseIgnorable*)(sigma)(caseIgnorable*)[other][cased]
|
||||
for (precedingCaseIgnorable in 0..5) {
|
||||
for (succeedingCaseIgnorable in 0..5) {
|
||||
val caseIgnorableBefore = caseIgnorable(precedingCaseIgnorable)
|
||||
val caseIgnorableAfter = caseIgnorable(succeedingCaseIgnorable)
|
||||
val sigmaNearby = caseIgnorableBefore + sigma + caseIgnorableAfter
|
||||
val lowerSigmaNearby = caseIgnorableBefore + lowerSigma + caseIgnorableAfter
|
||||
val specialSigmaNearby = caseIgnorableBefore + specialLowerSigma + caseIgnorableAfter
|
||||
|
||||
for (mask in 0 until (1 shl 4)) {
|
||||
val casedBefore = cased().repeat((mask shr 0) and 1)
|
||||
val casedAfter = cased().repeat((mask shr 1) and 1)
|
||||
val otherBefore = other().repeat((mask shr 2) and 1)
|
||||
val otherAfter = other().repeat((mask shr 3) and 1)
|
||||
|
||||
val resultSigmaNearby =
|
||||
if (otherBefore.isEmpty() && casedBefore.isNotEmpty() && (otherAfter.isNotEmpty() || casedAfter.isEmpty()))
|
||||
specialSigmaNearby
|
||||
else
|
||||
lowerSigmaNearby
|
||||
|
||||
val actual = (casedBefore + otherBefore + sigmaNearby + otherAfter + casedAfter).lowercase()
|
||||
val expected = casedBefore.lowercase() + otherBefore + resultSigmaNearby + otherAfter + casedAfter.lowercase()
|
||||
|
||||
assertEquals(
|
||||
expected,
|
||||
actual,
|
||||
"Expected <$expected>${expected.map { it.hex() }}, Actual <$actual>${actual.map { it.hex() }}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uppercase() {
|
||||
// Non-ASCII
|
||||
assertEquals("\u00DE\u03A9\u0403\uA779", "\u00FE\u03A9\u0453\uA77A".uppercase())
|
||||
}
|
||||
}
|
||||
@@ -1,495 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package test.text
|
||||
|
||||
//
|
||||
// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
private val caseIgnorableRanges = arrayOf<IntRange>(
|
||||
0x0027..0x0027,
|
||||
0x002e..0x002e,
|
||||
0x003a..0x003a,
|
||||
0x005e..0x005e,
|
||||
0x0060..0x0060,
|
||||
0x00a8..0x00a8,
|
||||
0x00ad..0x00ad,
|
||||
0x00af..0x00af,
|
||||
0x00b4..0x00b4,
|
||||
0x00b7..0x00b7,
|
||||
0x00b8..0x00b8,
|
||||
0x02b0..0x02c1,
|
||||
0x02c2..0x02c5,
|
||||
0x02c6..0x02d1,
|
||||
0x02d2..0x02df,
|
||||
0x02e0..0x02e4,
|
||||
0x02e5..0x02eb,
|
||||
0x02ec..0x02ec,
|
||||
0x02ed..0x02ed,
|
||||
0x02ee..0x02ee,
|
||||
0x02ef..0x02ff,
|
||||
0x0300..0x036f,
|
||||
0x0374..0x0374,
|
||||
0x0375..0x0375,
|
||||
0x037a..0x037a,
|
||||
0x0384..0x0385,
|
||||
0x0387..0x0387,
|
||||
0x0483..0x0487,
|
||||
0x0488..0x0489,
|
||||
0x0559..0x0559,
|
||||
0x055f..0x055f,
|
||||
0x0591..0x05bd,
|
||||
0x05bf..0x05bf,
|
||||
0x05c1..0x05c2,
|
||||
0x05c4..0x05c5,
|
||||
0x05c7..0x05c7,
|
||||
0x05f4..0x05f4,
|
||||
0x0600..0x0605,
|
||||
0x0610..0x061a,
|
||||
0x061c..0x061c,
|
||||
0x0640..0x0640,
|
||||
0x064b..0x065f,
|
||||
0x0670..0x0670,
|
||||
0x06d6..0x06dc,
|
||||
0x06dd..0x06dd,
|
||||
0x06df..0x06e4,
|
||||
0x06e5..0x06e6,
|
||||
0x06e7..0x06e8,
|
||||
0x06ea..0x06ed,
|
||||
0x070f..0x070f,
|
||||
0x0711..0x0711,
|
||||
0x0730..0x074a,
|
||||
0x07a6..0x07b0,
|
||||
0x07eb..0x07f3,
|
||||
0x07f4..0x07f5,
|
||||
0x07fa..0x07fa,
|
||||
0x07fd..0x07fd,
|
||||
0x0816..0x0819,
|
||||
0x081a..0x081a,
|
||||
0x081b..0x0823,
|
||||
0x0824..0x0824,
|
||||
0x0825..0x0827,
|
||||
0x0828..0x0828,
|
||||
0x0829..0x082d,
|
||||
0x0859..0x085b,
|
||||
0x08d3..0x08e1,
|
||||
0x08e2..0x08e2,
|
||||
0x08e3..0x0902,
|
||||
0x093a..0x093a,
|
||||
0x093c..0x093c,
|
||||
0x0941..0x0948,
|
||||
0x094d..0x094d,
|
||||
0x0951..0x0957,
|
||||
0x0962..0x0963,
|
||||
0x0971..0x0971,
|
||||
0x0981..0x0981,
|
||||
0x09bc..0x09bc,
|
||||
0x09c1..0x09c4,
|
||||
0x09cd..0x09cd,
|
||||
0x09e2..0x09e3,
|
||||
0x09fe..0x09fe,
|
||||
0x0a01..0x0a02,
|
||||
0x0a3c..0x0a3c,
|
||||
0x0a41..0x0a42,
|
||||
0x0a47..0x0a48,
|
||||
0x0a4b..0x0a4d,
|
||||
0x0a51..0x0a51,
|
||||
0x0a70..0x0a71,
|
||||
0x0a75..0x0a75,
|
||||
0x0a81..0x0a82,
|
||||
0x0abc..0x0abc,
|
||||
0x0ac1..0x0ac5,
|
||||
0x0ac7..0x0ac8,
|
||||
0x0acd..0x0acd,
|
||||
0x0ae2..0x0ae3,
|
||||
0x0afa..0x0aff,
|
||||
0x0b01..0x0b01,
|
||||
0x0b3c..0x0b3c,
|
||||
0x0b3f..0x0b3f,
|
||||
0x0b41..0x0b44,
|
||||
0x0b4d..0x0b4d,
|
||||
0x0b55..0x0b56,
|
||||
0x0b62..0x0b63,
|
||||
0x0b82..0x0b82,
|
||||
0x0bc0..0x0bc0,
|
||||
0x0bcd..0x0bcd,
|
||||
0x0c00..0x0c00,
|
||||
0x0c04..0x0c04,
|
||||
0x0c3e..0x0c40,
|
||||
0x0c46..0x0c48,
|
||||
0x0c4a..0x0c4d,
|
||||
0x0c55..0x0c56,
|
||||
0x0c62..0x0c63,
|
||||
0x0c81..0x0c81,
|
||||
0x0cbc..0x0cbc,
|
||||
0x0cbf..0x0cbf,
|
||||
0x0cc6..0x0cc6,
|
||||
0x0ccc..0x0ccd,
|
||||
0x0ce2..0x0ce3,
|
||||
0x0d00..0x0d01,
|
||||
0x0d3b..0x0d3c,
|
||||
0x0d41..0x0d44,
|
||||
0x0d4d..0x0d4d,
|
||||
0x0d62..0x0d63,
|
||||
0x0d81..0x0d81,
|
||||
0x0dca..0x0dca,
|
||||
0x0dd2..0x0dd4,
|
||||
0x0dd6..0x0dd6,
|
||||
0x0e31..0x0e31,
|
||||
0x0e34..0x0e3a,
|
||||
0x0e46..0x0e46,
|
||||
0x0e47..0x0e4e,
|
||||
0x0eb1..0x0eb1,
|
||||
0x0eb4..0x0ebc,
|
||||
0x0ec6..0x0ec6,
|
||||
0x0ec8..0x0ecd,
|
||||
0x0f18..0x0f19,
|
||||
0x0f35..0x0f35,
|
||||
0x0f37..0x0f37,
|
||||
0x0f39..0x0f39,
|
||||
0x0f71..0x0f7e,
|
||||
0x0f80..0x0f84,
|
||||
0x0f86..0x0f87,
|
||||
0x0f8d..0x0f97,
|
||||
0x0f99..0x0fbc,
|
||||
0x0fc6..0x0fc6,
|
||||
0x102d..0x1030,
|
||||
0x1032..0x1037,
|
||||
0x1039..0x103a,
|
||||
0x103d..0x103e,
|
||||
0x1058..0x1059,
|
||||
0x105e..0x1060,
|
||||
0x1071..0x1074,
|
||||
0x1082..0x1082,
|
||||
0x1085..0x1086,
|
||||
0x108d..0x108d,
|
||||
0x109d..0x109d,
|
||||
0x10fc..0x10fc,
|
||||
0x135d..0x135f,
|
||||
0x1712..0x1714,
|
||||
0x1732..0x1734,
|
||||
0x1752..0x1753,
|
||||
0x1772..0x1773,
|
||||
0x17b4..0x17b5,
|
||||
0x17b7..0x17bd,
|
||||
0x17c6..0x17c6,
|
||||
0x17c9..0x17d3,
|
||||
0x17d7..0x17d7,
|
||||
0x17dd..0x17dd,
|
||||
0x180b..0x180d,
|
||||
0x180e..0x180e,
|
||||
0x1843..0x1843,
|
||||
0x1885..0x1886,
|
||||
0x18a9..0x18a9,
|
||||
0x1920..0x1922,
|
||||
0x1927..0x1928,
|
||||
0x1932..0x1932,
|
||||
0x1939..0x193b,
|
||||
0x1a17..0x1a18,
|
||||
0x1a1b..0x1a1b,
|
||||
0x1a56..0x1a56,
|
||||
0x1a58..0x1a5e,
|
||||
0x1a60..0x1a60,
|
||||
0x1a62..0x1a62,
|
||||
0x1a65..0x1a6c,
|
||||
0x1a73..0x1a7c,
|
||||
0x1a7f..0x1a7f,
|
||||
0x1aa7..0x1aa7,
|
||||
0x1ab0..0x1abd,
|
||||
0x1abe..0x1abe,
|
||||
0x1abf..0x1ac0,
|
||||
0x1b00..0x1b03,
|
||||
0x1b34..0x1b34,
|
||||
0x1b36..0x1b3a,
|
||||
0x1b3c..0x1b3c,
|
||||
0x1b42..0x1b42,
|
||||
0x1b6b..0x1b73,
|
||||
0x1b80..0x1b81,
|
||||
0x1ba2..0x1ba5,
|
||||
0x1ba8..0x1ba9,
|
||||
0x1bab..0x1bad,
|
||||
0x1be6..0x1be6,
|
||||
0x1be8..0x1be9,
|
||||
0x1bed..0x1bed,
|
||||
0x1bef..0x1bf1,
|
||||
0x1c2c..0x1c33,
|
||||
0x1c36..0x1c37,
|
||||
0x1c78..0x1c7d,
|
||||
0x1cd0..0x1cd2,
|
||||
0x1cd4..0x1ce0,
|
||||
0x1ce2..0x1ce8,
|
||||
0x1ced..0x1ced,
|
||||
0x1cf4..0x1cf4,
|
||||
0x1cf8..0x1cf9,
|
||||
0x1d2c..0x1d6a,
|
||||
0x1d78..0x1d78,
|
||||
0x1d9b..0x1dbf,
|
||||
0x1dc0..0x1df9,
|
||||
0x1dfb..0x1dff,
|
||||
0x1fbd..0x1fbd,
|
||||
0x1fbf..0x1fc1,
|
||||
0x1fcd..0x1fcf,
|
||||
0x1fdd..0x1fdf,
|
||||
0x1fed..0x1fef,
|
||||
0x1ffd..0x1ffe,
|
||||
0x200b..0x200f,
|
||||
0x2018..0x2018,
|
||||
0x2019..0x2019,
|
||||
0x2024..0x2024,
|
||||
0x2027..0x2027,
|
||||
0x202a..0x202e,
|
||||
0x2060..0x2064,
|
||||
0x2066..0x206f,
|
||||
0x2071..0x2071,
|
||||
0x207f..0x207f,
|
||||
0x2090..0x209c,
|
||||
0x20d0..0x20dc,
|
||||
0x20dd..0x20e0,
|
||||
0x20e1..0x20e1,
|
||||
0x20e2..0x20e4,
|
||||
0x20e5..0x20f0,
|
||||
0x2c7c..0x2c7d,
|
||||
0x2cef..0x2cf1,
|
||||
0x2d6f..0x2d6f,
|
||||
0x2d7f..0x2d7f,
|
||||
0x2de0..0x2dff,
|
||||
0x2e2f..0x2e2f,
|
||||
0x3005..0x3005,
|
||||
0x302a..0x302d,
|
||||
0x3031..0x3035,
|
||||
0x303b..0x303b,
|
||||
0x3099..0x309a,
|
||||
0x309b..0x309c,
|
||||
0x309d..0x309e,
|
||||
0x30fc..0x30fe,
|
||||
0xa015..0xa015,
|
||||
0xa4f8..0xa4fd,
|
||||
0xa60c..0xa60c,
|
||||
0xa66f..0xa66f,
|
||||
0xa670..0xa672,
|
||||
0xa674..0xa67d,
|
||||
0xa67f..0xa67f,
|
||||
0xa69c..0xa69d,
|
||||
0xa69e..0xa69f,
|
||||
0xa6f0..0xa6f1,
|
||||
0xa700..0xa716,
|
||||
0xa717..0xa71f,
|
||||
0xa720..0xa721,
|
||||
0xa770..0xa770,
|
||||
0xa788..0xa788,
|
||||
0xa789..0xa78a,
|
||||
0xa7f8..0xa7f9,
|
||||
0xa802..0xa802,
|
||||
0xa806..0xa806,
|
||||
0xa80b..0xa80b,
|
||||
0xa825..0xa826,
|
||||
0xa82c..0xa82c,
|
||||
0xa8c4..0xa8c5,
|
||||
0xa8e0..0xa8f1,
|
||||
0xa8ff..0xa8ff,
|
||||
0xa926..0xa92d,
|
||||
0xa947..0xa951,
|
||||
0xa980..0xa982,
|
||||
0xa9b3..0xa9b3,
|
||||
0xa9b6..0xa9b9,
|
||||
0xa9bc..0xa9bd,
|
||||
0xa9cf..0xa9cf,
|
||||
0xa9e5..0xa9e5,
|
||||
0xa9e6..0xa9e6,
|
||||
0xaa29..0xaa2e,
|
||||
0xaa31..0xaa32,
|
||||
0xaa35..0xaa36,
|
||||
0xaa43..0xaa43,
|
||||
0xaa4c..0xaa4c,
|
||||
0xaa70..0xaa70,
|
||||
0xaa7c..0xaa7c,
|
||||
0xaab0..0xaab0,
|
||||
0xaab2..0xaab4,
|
||||
0xaab7..0xaab8,
|
||||
0xaabe..0xaabf,
|
||||
0xaac1..0xaac1,
|
||||
0xaadd..0xaadd,
|
||||
0xaaec..0xaaed,
|
||||
0xaaf3..0xaaf4,
|
||||
0xaaf6..0xaaf6,
|
||||
0xab5b..0xab5b,
|
||||
0xab5c..0xab5f,
|
||||
0xab69..0xab69,
|
||||
0xab6a..0xab6b,
|
||||
0xabe5..0xabe5,
|
||||
0xabe8..0xabe8,
|
||||
0xabed..0xabed,
|
||||
0xfb1e..0xfb1e,
|
||||
0xfbb2..0xfbc1,
|
||||
0xfe00..0xfe0f,
|
||||
0xfe13..0xfe13,
|
||||
0xfe20..0xfe2f,
|
||||
0xfe52..0xfe52,
|
||||
0xfe55..0xfe55,
|
||||
0xfeff..0xfeff,
|
||||
0xff07..0xff07,
|
||||
0xff0e..0xff0e,
|
||||
0xff1a..0xff1a,
|
||||
0xff3e..0xff3e,
|
||||
0xff40..0xff40,
|
||||
0xff70..0xff70,
|
||||
0xff9e..0xff9f,
|
||||
0xffe3..0xffe3,
|
||||
0xfff9..0xfffb,
|
||||
0x101fd..0x101fd,
|
||||
0x102e0..0x102e0,
|
||||
0x10376..0x1037a,
|
||||
0x10a01..0x10a03,
|
||||
0x10a05..0x10a06,
|
||||
0x10a0c..0x10a0f,
|
||||
0x10a38..0x10a3a,
|
||||
0x10a3f..0x10a3f,
|
||||
0x10ae5..0x10ae6,
|
||||
0x10d24..0x10d27,
|
||||
0x10eab..0x10eac,
|
||||
0x10f46..0x10f50,
|
||||
0x11001..0x11001,
|
||||
0x11038..0x11046,
|
||||
0x1107f..0x11081,
|
||||
0x110b3..0x110b6,
|
||||
0x110b9..0x110ba,
|
||||
0x110bd..0x110bd,
|
||||
0x110cd..0x110cd,
|
||||
0x11100..0x11102,
|
||||
0x11127..0x1112b,
|
||||
0x1112d..0x11134,
|
||||
0x11173..0x11173,
|
||||
0x11180..0x11181,
|
||||
0x111b6..0x111be,
|
||||
0x111c9..0x111cc,
|
||||
0x111cf..0x111cf,
|
||||
0x1122f..0x11231,
|
||||
0x11234..0x11234,
|
||||
0x11236..0x11237,
|
||||
0x1123e..0x1123e,
|
||||
0x112df..0x112df,
|
||||
0x112e3..0x112ea,
|
||||
0x11300..0x11301,
|
||||
0x1133b..0x1133c,
|
||||
0x11340..0x11340,
|
||||
0x11366..0x1136c,
|
||||
0x11370..0x11374,
|
||||
0x11438..0x1143f,
|
||||
0x11442..0x11444,
|
||||
0x11446..0x11446,
|
||||
0x1145e..0x1145e,
|
||||
0x114b3..0x114b8,
|
||||
0x114ba..0x114ba,
|
||||
0x114bf..0x114c0,
|
||||
0x114c2..0x114c3,
|
||||
0x115b2..0x115b5,
|
||||
0x115bc..0x115bd,
|
||||
0x115bf..0x115c0,
|
||||
0x115dc..0x115dd,
|
||||
0x11633..0x1163a,
|
||||
0x1163d..0x1163d,
|
||||
0x1163f..0x11640,
|
||||
0x116ab..0x116ab,
|
||||
0x116ad..0x116ad,
|
||||
0x116b0..0x116b5,
|
||||
0x116b7..0x116b7,
|
||||
0x1171d..0x1171f,
|
||||
0x11722..0x11725,
|
||||
0x11727..0x1172b,
|
||||
0x1182f..0x11837,
|
||||
0x11839..0x1183a,
|
||||
0x1193b..0x1193c,
|
||||
0x1193e..0x1193e,
|
||||
0x11943..0x11943,
|
||||
0x119d4..0x119d7,
|
||||
0x119da..0x119db,
|
||||
0x119e0..0x119e0,
|
||||
0x11a01..0x11a0a,
|
||||
0x11a33..0x11a38,
|
||||
0x11a3b..0x11a3e,
|
||||
0x11a47..0x11a47,
|
||||
0x11a51..0x11a56,
|
||||
0x11a59..0x11a5b,
|
||||
0x11a8a..0x11a96,
|
||||
0x11a98..0x11a99,
|
||||
0x11c30..0x11c36,
|
||||
0x11c38..0x11c3d,
|
||||
0x11c3f..0x11c3f,
|
||||
0x11c92..0x11ca7,
|
||||
0x11caa..0x11cb0,
|
||||
0x11cb2..0x11cb3,
|
||||
0x11cb5..0x11cb6,
|
||||
0x11d31..0x11d36,
|
||||
0x11d3a..0x11d3a,
|
||||
0x11d3c..0x11d3d,
|
||||
0x11d3f..0x11d45,
|
||||
0x11d47..0x11d47,
|
||||
0x11d90..0x11d91,
|
||||
0x11d95..0x11d95,
|
||||
0x11d97..0x11d97,
|
||||
0x11ef3..0x11ef4,
|
||||
0x13430..0x13438,
|
||||
0x16af0..0x16af4,
|
||||
0x16b30..0x16b36,
|
||||
0x16b40..0x16b43,
|
||||
0x16f4f..0x16f4f,
|
||||
0x16f8f..0x16f92,
|
||||
0x16f93..0x16f9f,
|
||||
0x16fe0..0x16fe1,
|
||||
0x16fe3..0x16fe3,
|
||||
0x16fe4..0x16fe4,
|
||||
0x1bc9d..0x1bc9e,
|
||||
0x1bca0..0x1bca3,
|
||||
0x1d167..0x1d169,
|
||||
0x1d173..0x1d17a,
|
||||
0x1d17b..0x1d182,
|
||||
0x1d185..0x1d18b,
|
||||
0x1d1aa..0x1d1ad,
|
||||
0x1d242..0x1d244,
|
||||
0x1da00..0x1da36,
|
||||
0x1da3b..0x1da6c,
|
||||
0x1da75..0x1da75,
|
||||
0x1da84..0x1da84,
|
||||
0x1da9b..0x1da9f,
|
||||
0x1daa1..0x1daaf,
|
||||
0x1e000..0x1e006,
|
||||
0x1e008..0x1e018,
|
||||
0x1e01b..0x1e021,
|
||||
0x1e023..0x1e024,
|
||||
0x1e026..0x1e02a,
|
||||
0x1e130..0x1e136,
|
||||
0x1e137..0x1e13d,
|
||||
0x1e2ec..0x1e2ef,
|
||||
0x1e8d0..0x1e8d6,
|
||||
0x1e944..0x1e94a,
|
||||
0x1e94b..0x1e94b,
|
||||
0x1f3fb..0x1f3ff,
|
||||
0xe0001..0xe0001,
|
||||
0xe0020..0xe007f,
|
||||
0xe0100..0xe01ef,
|
||||
)
|
||||
|
||||
class IsCaseIgnorableTest {
|
||||
@Test
|
||||
fun isCaseIgnorable() {
|
||||
var lastChecked = -1
|
||||
for (range in caseIgnorableRanges) {
|
||||
for (codePoint in lastChecked + 1 until range.first) {
|
||||
assertFalse(codePoint.isCaseIgnorable())
|
||||
}
|
||||
for (codePoint in range.first..range.last) {
|
||||
assertTrue(codePoint.isCaseIgnorable())
|
||||
}
|
||||
lastChecked = range.last
|
||||
}
|
||||
for (codePoint in lastChecked + 1..0x10FFFF) {
|
||||
assertFalse(codePoint.isCaseIgnorable())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package test.text
|
||||
|
||||
//
|
||||
// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
private val casedRanges = arrayOf<IntRange>(
|
||||
0x0041..0x005a,
|
||||
0x0061..0x007a,
|
||||
0x00aa..0x00aa,
|
||||
0x00b5..0x00b5,
|
||||
0x00ba..0x00ba,
|
||||
0x00c0..0x00d6,
|
||||
0x00d8..0x00f6,
|
||||
0x00f8..0x01ba,
|
||||
0x01bc..0x01bf,
|
||||
0x01c4..0x0293,
|
||||
0x0295..0x02af,
|
||||
0x02b0..0x02b8,
|
||||
0x02c0..0x02c1,
|
||||
0x02e0..0x02e4,
|
||||
0x0345..0x0345,
|
||||
0x0370..0x0373,
|
||||
0x0376..0x0377,
|
||||
0x037a..0x037a,
|
||||
0x037b..0x037d,
|
||||
0x037f..0x037f,
|
||||
0x0386..0x0386,
|
||||
0x0388..0x038a,
|
||||
0x038c..0x038c,
|
||||
0x038e..0x03a1,
|
||||
0x03a3..0x03f5,
|
||||
0x03f7..0x0481,
|
||||
0x048a..0x052f,
|
||||
0x0531..0x0556,
|
||||
0x0560..0x0588,
|
||||
0x10a0..0x10c5,
|
||||
0x10c7..0x10c7,
|
||||
0x10cd..0x10cd,
|
||||
0x10d0..0x10fa,
|
||||
0x10fd..0x10ff,
|
||||
0x13a0..0x13f5,
|
||||
0x13f8..0x13fd,
|
||||
0x1c80..0x1c88,
|
||||
0x1c90..0x1cba,
|
||||
0x1cbd..0x1cbf,
|
||||
0x1d00..0x1d2b,
|
||||
0x1d2c..0x1d6a,
|
||||
0x1d6b..0x1d77,
|
||||
0x1d78..0x1d78,
|
||||
0x1d79..0x1d9a,
|
||||
0x1d9b..0x1dbf,
|
||||
0x1e00..0x1f15,
|
||||
0x1f18..0x1f1d,
|
||||
0x1f20..0x1f45,
|
||||
0x1f48..0x1f4d,
|
||||
0x1f50..0x1f57,
|
||||
0x1f59..0x1f59,
|
||||
0x1f5b..0x1f5b,
|
||||
0x1f5d..0x1f5d,
|
||||
0x1f5f..0x1f7d,
|
||||
0x1f80..0x1fb4,
|
||||
0x1fb6..0x1fbc,
|
||||
0x1fbe..0x1fbe,
|
||||
0x1fc2..0x1fc4,
|
||||
0x1fc6..0x1fcc,
|
||||
0x1fd0..0x1fd3,
|
||||
0x1fd6..0x1fdb,
|
||||
0x1fe0..0x1fec,
|
||||
0x1ff2..0x1ff4,
|
||||
0x1ff6..0x1ffc,
|
||||
0x2071..0x2071,
|
||||
0x207f..0x207f,
|
||||
0x2090..0x209c,
|
||||
0x2102..0x2102,
|
||||
0x2107..0x2107,
|
||||
0x210a..0x2113,
|
||||
0x2115..0x2115,
|
||||
0x2119..0x211d,
|
||||
0x2124..0x2124,
|
||||
0x2126..0x2126,
|
||||
0x2128..0x2128,
|
||||
0x212a..0x212d,
|
||||
0x212f..0x2134,
|
||||
0x2139..0x2139,
|
||||
0x213c..0x213f,
|
||||
0x2145..0x2149,
|
||||
0x214e..0x214e,
|
||||
0x2160..0x217f,
|
||||
0x2183..0x2184,
|
||||
0x24b6..0x24e9,
|
||||
0x2c00..0x2c2e,
|
||||
0x2c30..0x2c5e,
|
||||
0x2c60..0x2c7b,
|
||||
0x2c7c..0x2c7d,
|
||||
0x2c7e..0x2ce4,
|
||||
0x2ceb..0x2cee,
|
||||
0x2cf2..0x2cf3,
|
||||
0x2d00..0x2d25,
|
||||
0x2d27..0x2d27,
|
||||
0x2d2d..0x2d2d,
|
||||
0xa640..0xa66d,
|
||||
0xa680..0xa69b,
|
||||
0xa69c..0xa69d,
|
||||
0xa722..0xa76f,
|
||||
0xa770..0xa770,
|
||||
0xa771..0xa787,
|
||||
0xa78b..0xa78e,
|
||||
0xa790..0xa7bf,
|
||||
0xa7c2..0xa7ca,
|
||||
0xa7f5..0xa7f6,
|
||||
0xa7f8..0xa7f9,
|
||||
0xa7fa..0xa7fa,
|
||||
0xab30..0xab5a,
|
||||
0xab5c..0xab5f,
|
||||
0xab60..0xab68,
|
||||
0xab70..0xabbf,
|
||||
0xfb00..0xfb06,
|
||||
0xfb13..0xfb17,
|
||||
0xff21..0xff3a,
|
||||
0xff41..0xff5a,
|
||||
0x10400..0x1044f,
|
||||
0x104b0..0x104d3,
|
||||
0x104d8..0x104fb,
|
||||
0x10c80..0x10cb2,
|
||||
0x10cc0..0x10cf2,
|
||||
0x118a0..0x118df,
|
||||
0x16e40..0x16e7f,
|
||||
0x1d400..0x1d454,
|
||||
0x1d456..0x1d49c,
|
||||
0x1d49e..0x1d49f,
|
||||
0x1d4a2..0x1d4a2,
|
||||
0x1d4a5..0x1d4a6,
|
||||
0x1d4a9..0x1d4ac,
|
||||
0x1d4ae..0x1d4b9,
|
||||
0x1d4bb..0x1d4bb,
|
||||
0x1d4bd..0x1d4c3,
|
||||
0x1d4c5..0x1d505,
|
||||
0x1d507..0x1d50a,
|
||||
0x1d50d..0x1d514,
|
||||
0x1d516..0x1d51c,
|
||||
0x1d51e..0x1d539,
|
||||
0x1d53b..0x1d53e,
|
||||
0x1d540..0x1d544,
|
||||
0x1d546..0x1d546,
|
||||
0x1d54a..0x1d550,
|
||||
0x1d552..0x1d6a5,
|
||||
0x1d6a8..0x1d6c0,
|
||||
0x1d6c2..0x1d6da,
|
||||
0x1d6dc..0x1d6fa,
|
||||
0x1d6fc..0x1d714,
|
||||
0x1d716..0x1d734,
|
||||
0x1d736..0x1d74e,
|
||||
0x1d750..0x1d76e,
|
||||
0x1d770..0x1d788,
|
||||
0x1d78a..0x1d7a8,
|
||||
0x1d7aa..0x1d7c2,
|
||||
0x1d7c4..0x1d7cb,
|
||||
0x1e900..0x1e943,
|
||||
0x1f130..0x1f149,
|
||||
0x1f150..0x1f169,
|
||||
0x1f170..0x1f189,
|
||||
)
|
||||
|
||||
class IsCasedTest {
|
||||
@Test
|
||||
fun isCased() {
|
||||
var lastChecked = -1
|
||||
for (range in casedRanges) {
|
||||
for (codePoint in lastChecked + 1 until range.first) {
|
||||
assertFalse(codePoint.isCased())
|
||||
}
|
||||
for (codePoint in range.first..range.last) {
|
||||
assertTrue(codePoint.isCased())
|
||||
}
|
||||
lastChecked = range.last
|
||||
}
|
||||
for (codePoint in lastChecked + 1..0x10FFFF) {
|
||||
assertFalse(codePoint.isCased())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
public actual fun assertTypeEquals(expected: Any?, actual: Any?) {
|
||||
if (expected != null && actual != null) {
|
||||
assertTrue(expected::class.isInstance(actual) || actual::class.isInstance(expected),
|
||||
"Expected: $expected, Actual: $actual")
|
||||
} else {
|
||||
assertTrue(expected == null && actual == null)
|
||||
}
|
||||
}
|
||||
|
||||
public actual val TestPlatform.Companion.current: TestPlatform get() = TestPlatform.Native
|
||||
|
||||
public actual val isFloat32RangeEnforced: Boolean get() = true
|
||||
|
||||
public actual val supportsOctalLiteralInRegex: Boolean get() = true
|
||||
|
||||
public actual val supportsEscapeAnyCharInRegex: Boolean get() = true
|
||||
|
||||
public actual val regexSplitUnicodeCodePointHandling: Boolean get() = false
|
||||
|
||||
public actual object BackReferenceHandling {
|
||||
actual val captureLargestValidIndex: Boolean get() = true
|
||||
|
||||
actual val notYetDefinedGroup: HandlingOption = HandlingOption.THROW
|
||||
actual val notYetDefinedNamedGroup: HandlingOption = HandlingOption.THROW
|
||||
actual val enclosingGroup: HandlingOption = HandlingOption.MATCH_NOTHING
|
||||
actual val nonExistentGroup: HandlingOption = HandlingOption.THROW
|
||||
actual val nonExistentNamedGroup: HandlingOption = HandlingOption.THROW
|
||||
actual val groupZero: HandlingOption = HandlingOption.THROW
|
||||
}
|
||||
Reference in New Issue
Block a user