JS: Provide MIN_VALUE and MAX_VALUE member constants for Double and Float companion objects.

JVM: Make MIN_VALUE and MAX_VALUE not an extension but member constant properties of Double and Float companion objects.
This commit is contained in:
Ilya Gorbunov
2015-05-22 19:54:04 +03:00
parent bd934bc3c4
commit 1cf4a407d1
6 changed files with 58 additions and 44 deletions
+28 -9
View File
@@ -12,35 +12,54 @@ class NumbersTest {
// overflow behavior
// doesn't hold for JS Number
// assertEquals(Int.MIN_VALUE, Int.MAX_VALUE + 1)
// expect(Int.MIN_VALUE) { Int.MAX_VALUE + 1 }
// expect(Int.MAX_VALUE) { Int.MIN_VALUE - 1 }
}
test fun longMinMaxValues() {
assertTrue(Long.MIN_VALUE < 0)
assertTrue(Long.MAX_VALUE > 0)
// overflow behavior
assertEquals(Long.MIN_VALUE, Long.MAX_VALUE + 1)
assertEquals(Long.MAX_VALUE, Long.MIN_VALUE - 1)
expect(Long.MIN_VALUE) { Long.MAX_VALUE + 1 }
expect(Long.MAX_VALUE) { Long.MIN_VALUE - 1 }
}
test fun shortMinMaxValues() {
assertTrue(Short.MIN_VALUE < 0)
assertTrue(Short.MAX_VALUE > 0)
// overflow behavior
assertEquals(Short.MIN_VALUE, (Short.MAX_VALUE + 1).toShort())
assertEquals(Short.MAX_VALUE, (Short.MIN_VALUE - 1).toShort())
expect(Short.MIN_VALUE) { (Short.MAX_VALUE + 1).toShort() }
expect(Short.MAX_VALUE) { (Short.MIN_VALUE - 1).toShort() }
}
test fun byteMinMaxValues() {
assertTrue(Byte.MIN_VALUE < 0)
assertTrue(Byte.MAX_VALUE > 0)
// overflow behavior
assertEquals(Byte.MIN_VALUE, (Byte.MAX_VALUE + 1).toByte())
assertEquals(Byte.MAX_VALUE, (Byte.MIN_VALUE - 1).toByte())
expect(Byte.MIN_VALUE) { (Byte.MAX_VALUE + 1).toByte() }
expect(Byte.MAX_VALUE) { (Byte.MIN_VALUE - 1).toByte() }
}
test fun doubleMinMaxValues() {
assertTrue(Double.MIN_VALUE > 0)
assertTrue(Double.MAX_VALUE > 0)
// overflow behavior
expect(Double.POSITIVE_INFINITY) { Double.MAX_VALUE * 2 }
expect(Double.NEGATIVE_INFINITY) {-Double.MAX_VALUE * 2 }
expect(0.0) { Double.MIN_VALUE / 2 }
}
test fun floatMinMaxValues() {
assertTrue(Float.MIN_VALUE > 0)
assertTrue(Float.MAX_VALUE > 0)
// overflow behavior
expect(Float.POSITIVE_INFINITY) { Float.MAX_VALUE * 2 }
expect(Float.NEGATIVE_INFINITY) { -Float.MAX_VALUE * 2 }
expect(0.0F) { Float.MIN_VALUE / 2.0F }
}
test fun doubleProperties() {
for (value in listOf(1.0, 0.0))
for (value in listOf(1.0, 0.0, Double.MIN_VALUE, Double.MAX_VALUE))
doTestNumber(value)
for (value in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY))
doTestNumber(value, isInfinite = true)
@@ -48,7 +67,7 @@ class NumbersTest {
}
test fun floatProperties() {
for (value in listOf(1.0F, 0.0F))
for (value in listOf(1.0F, 0.0F, Float.MAX_VALUE, Float.MIN_VALUE))
doTestNumber(value)
for (value in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY))
doTestNumber(value, isInfinite = true)