Add test for comparison used for primitives and Comparable
There's a subtle difference in behavior between comparing primitive Float/Double (comparison follows IEEE standard) and boxed Float/Double (comparison is a total order). Make sure this corner case is preserved.
This commit is contained in:
Vendored
+22
@@ -0,0 +1,22 @@
|
|||||||
|
// IGNORE_BACKEND: JS
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
val DOUBLE_RANGE = 0.0 .. -0.0
|
||||||
|
|
||||||
|
val PZERO = 0.0 as Comparable<Any>
|
||||||
|
val NZERO = -0.0 as Comparable<Any>
|
||||||
|
val COMPARABLE_RANGE = PZERO .. NZERO
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
if (!(0.0 in DOUBLE_RANGE)) return "fail 1 in Double"
|
||||||
|
if (0.0 !in DOUBLE_RANGE) return "fail 1 !in Double"
|
||||||
|
if (!(-0.0 in DOUBLE_RANGE)) return "fail 2 in Double"
|
||||||
|
if (-0.0 !in DOUBLE_RANGE) return "fail 2 !in Double"
|
||||||
|
|
||||||
|
if (PZERO in COMPARABLE_RANGE) return "fail 3 in Comparable"
|
||||||
|
if (!(PZERO !in COMPARABLE_RANGE)) return "fail 3 !in Comparable"
|
||||||
|
if (NZERO in COMPARABLE_RANGE) return "fail 4 in Comparable"
|
||||||
|
if (!(NZERO !in COMPARABLE_RANGE)) return "fail 4a !in Comparable"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+6
@@ -13195,6 +13195,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inDoubleRangeLiteralVsComparableRangeLiteral.kt")
|
||||||
|
public void testInDoubleRangeLiteralVsComparableRangeLiteral() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inDoubleRangeLiteralVsComparableRangeLiteral.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inExtensionRange.kt")
|
@TestMetadata("inExtensionRange.kt")
|
||||||
public void testInExtensionRange() throws Exception {
|
public void testInExtensionRange() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inExtensionRange.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inExtensionRange.kt");
|
||||||
|
|||||||
@@ -13195,6 +13195,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inDoubleRangeLiteralVsComparableRangeLiteral.kt")
|
||||||
|
public void testInDoubleRangeLiteralVsComparableRangeLiteral() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inDoubleRangeLiteralVsComparableRangeLiteral.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inExtensionRange.kt")
|
@TestMetadata("inExtensionRange.kt")
|
||||||
public void testInExtensionRange() throws Exception {
|
public void testInExtensionRange() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inExtensionRange.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inExtensionRange.kt");
|
||||||
|
|||||||
@@ -13195,6 +13195,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inDoubleRangeLiteralVsComparableRangeLiteral.kt")
|
||||||
|
public void testInDoubleRangeLiteralVsComparableRangeLiteral() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inDoubleRangeLiteralVsComparableRangeLiteral.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inExtensionRange.kt")
|
@TestMetadata("inExtensionRange.kt")
|
||||||
public void testInExtensionRange() throws Exception {
|
public void testInExtensionRange() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inExtensionRange.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inExtensionRange.kt");
|
||||||
|
|||||||
+12
@@ -14809,6 +14809,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inDoubleRangeLiteralVsComparableRangeLiteral.kt")
|
||||||
|
public void testInDoubleRangeLiteralVsComparableRangeLiteral() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inDoubleRangeLiteralVsComparableRangeLiteral.kt");
|
||||||
|
try {
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
catch (Throwable ignore) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inExtensionRange.kt")
|
@TestMetadata("inExtensionRange.kt")
|
||||||
public void testInExtensionRange() throws Exception {
|
public void testInExtensionRange() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inExtensionRange.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inExtensionRange.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user