Use Char.MIN_VALUE and MAX_VALUE in tests

This commit is contained in:
Ilya Gorbunov
2018-06-22 21:39:22 +03:00
parent 92e149fa40
commit 5f3a7f0147
8 changed files with 21 additions and 9 deletions
+5 -4
View File
@@ -1,10 +1,11 @@
fun box(): String {
val c1: Char = 0.toChar()
val c1: Char = Char.MIN_VALUE
val c2 = c1 - 1
if (c2 < c1) return "fail: 0.toChar() - 1 should overflow to positive."
if (c2 < c1) return "fail: Char.MIN_VALUE - 1 should overflow to positive."
val c3 = c2 + 1
if (c3 > c2) return "fail: FFFF.toChar() + 1 should overflow to zero."
val c3: Char = Char.MAX_VALUE
val c4 = c3 + 1
if (c4 > c3) return "fail: Char.MAX_VALUE + 1 should overflow to zero."
return "OK"
}
@@ -1,6 +1,6 @@
// WITH_RUNTIME
const val M = 0.toChar()
const val M = Char.MIN_VALUE
fun box(): String {
var count = 0
@@ -1,7 +1,7 @@
// IGNORE_BACKEND: JS_IR
// WITH_RUNTIME
const val M = 0.toChar()
const val M = Char.MIN_VALUE
fun box(): String {
var count = 0
@@ -1,5 +1,5 @@
// IGNORE_BACKEND: JS_IR
const val M = 0xFFFF.toChar()
const val M = Char.MAX_VALUE
fun box(): String {
var count = 0
@@ -1,7 +1,7 @@
// IGNORE_BACKEND: JS_IR
// WITH_RUNTIME
const val M = 0xFFFF.toChar()
const val M = Char.MAX_VALUE
fun box(): String {
var count = 0
@@ -55,6 +55,8 @@ class BuiltinCompanionJVMTest {
@Test fun charTest() {
val ch = Char
assertEquals(java.lang.Character.MIN_VALUE, ch.MIN_VALUE)
assertEquals(java.lang.Character.MAX_VALUE, ch.MAX_VALUE)
assertEquals(java.lang.Character.MIN_SURROGATE, ch.MIN_SURROGATE)
assertEquals(java.lang.Character.MAX_SURROGATE, ch.MAX_SURROGATE)
assertEquals(java.lang.Character.MIN_LOW_SURROGATE, ch.MIN_LOW_SURROGATE)
@@ -94,6 +94,15 @@ class NumbersTest {
expect(Float.NEGATIVE_INFINITY) { -Float.MAX_VALUE * 2 }
expect(0.0F) { Float.MIN_VALUE / 2.0F }
}
@Test fun charMinMaxValues() {
assertTrue(Char.MIN_VALUE.toInt() == 0)
assertTrue(Char.MAX_VALUE.toInt() > 0)
// overflow behavior
expect(Char.MIN_VALUE) { Char.MAX_VALUE + one }
expect(Char.MAX_VALUE) { Char.MIN_VALUE - one }
}
@Test fun doubleProperties() {
for (value in listOf(1.0, 0.0, Double.MIN_VALUE, Double.MAX_VALUE))
+1 -1
View File
@@ -172,7 +172,7 @@ public class RangeTest {
assertTrue('Y' in openRange)
assertFalse('Z' in openRange)
assertTrue(('A' until '\u0000').isEmpty())
assertTrue(('A' until Char.MIN_VALUE).isEmpty())
}
@Test fun doubleRange() {