diff --git a/js/js.libraries/src/core/kotlin.kt b/js/js.libraries/src/core/kotlin.kt index 9f74e504776..7c79a5ddcfa 100644 --- a/js/js.libraries/src/core/kotlin.kt +++ b/js/js.libraries/src/core/kotlin.kt @@ -3,33 +3,33 @@ package kotlin import java.util.* library -public fun array(vararg value : T): Array = noImpl +public fun arrayOf(vararg value : T): Array = noImpl // "constructors" for primitive types array library -public fun doubleArray(vararg content : Double): DoubleArray = noImpl +public fun doubleArrayOf(vararg content : Double): DoubleArray = noImpl library -public fun floatArray(vararg content : Float): FloatArray = noImpl +public fun floatArrayOf(vararg content : Float): FloatArray = noImpl library -public fun longArray(vararg content : Long): LongArray = noImpl +public fun longArrayOf(vararg content : Long): LongArray = noImpl library -public fun intArray(vararg content : Int): IntArray = noImpl +public fun intArrayOf(vararg content : Int): IntArray = noImpl library -public fun charArray(vararg content : Char): CharArray = noImpl +public fun charArrayOf(vararg content : Char): CharArray = noImpl library -public fun shortArray(vararg content : Short): ShortArray = noImpl +public fun shortArrayOf(vararg content : Short): ShortArray = noImpl library -public fun byteArray(vararg content : Byte): ByteArray = noImpl +public fun byteArrayOf(vararg content : Byte): ByteArray = noImpl library -public fun booleanArray(vararg content : Boolean): BooleanArray = noImpl +public fun booleanArrayOf(vararg content : Boolean): BooleanArray = noImpl library("copyToArray") public fun Collection.copyToArray(): Array = noImpl diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.java index 06fbe9ae2ad..61203eced5e 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.java @@ -45,13 +45,13 @@ public final class ArrayFIF extends CompositeFIF { static { List arrayTypeNames = Lists.newArrayList(); - List arrayFactoryMethodNames = Lists.newArrayList(Name.identifier("array")); + List arrayFactoryMethodNames = Lists.newArrayList(Name.identifier("arrayOf")); for (PrimitiveType type : PrimitiveType.values()) { Name arrayTypeName = type.getArrayTypeName(); if (type != PrimitiveType.CHAR && type != PrimitiveType.BOOLEAN && type != PrimitiveType.LONG) { arrayTypeNames.add(arrayTypeName); } - arrayFactoryMethodNames.add(Name.identifier(decapitalize(arrayTypeName.asString()))); + arrayFactoryMethodNames.add(Name.identifier(decapitalize(arrayTypeName.asString() + "Of"))); } Name arrayName = Name.identifier("Array"); diff --git a/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt b/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt index 538aef7e98b..f441fe47362 100644 --- a/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt +++ b/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt @@ -9,48 +9,49 @@ import kotlin.jvm.internal.Intrinsic /** * Returns an array containing the specified elements. */ -[Intrinsic("kotlin.arrays.array")] public fun array(vararg t : T) : Array = t as Array +[Intrinsic("kotlin.arrays.array")] public fun arrayOf(vararg t : T) : Array = t as Array // "constructors" for primitive types array /** * Returns an array containing the specified [Double] numbers. */ -[Intrinsic("kotlin.arrays.array")] public fun doubleArray(vararg content : Double) : DoubleArray = content +[Intrinsic("kotlin.arrays.array")] public fun doubleArrayOf(vararg content : Double) : DoubleArray = content /** * Returns an array containing the specified [Float] numbers. */ -[Intrinsic("kotlin.arrays.array")] public fun floatArray(vararg content : Float) : FloatArray = content +[Intrinsic("kotlin.arrays.array")] public fun floatArrayOf(vararg content : Float) : FloatArray = content /** * Returns an array containing the specified [Long] numbers. */ -[Intrinsic("kotlin.arrays.array")] public fun longArray(vararg content : Long) : LongArray = content +[Intrinsic("kotlin.arrays.array")] public fun longArrayOf(vararg content : Long) : LongArray = content /** * Returns an array containing the specified [Int] numbers. */ -[Intrinsic("kotlin.arrays.array")] public fun intArray(vararg content : Int) : IntArray = content +[Intrinsic("kotlin.arrays.array")] public fun intArrayOf(vararg content : Int) : IntArray = content /** * Returns an array containing the specified characters. */ -[Intrinsic("kotlin.arrays.array")] public fun charArray(vararg content : Char) : CharArray = content +[Intrinsic("kotlin.arrays.array")] public fun charArrayOf(vararg content : Char) : CharArray = content /** * Returns an array containing the specified [Short] numbers. */ -[Intrinsic("kotlin.arrays.array")] public fun shortArray(vararg content : Short) : ShortArray = content +[Intrinsic("kotlin.arrays.array")] public fun shortArrayOf(vararg content : Short) : ShortArray = content /** * Returns an array containing the specified [Byte] numbers. */ -[Intrinsic("kotlin.arrays.array")] public fun byteArray(vararg content : Byte) : ByteArray = content +[Intrinsic("kotlin.arrays.array")] public fun byteArrayOf(vararg content : Byte) : ByteArray = content /** * Returns an array containing the specified boolean values. */ -[Intrinsic("kotlin.arrays.array")] public fun booleanArray(vararg content : Boolean) : BooleanArray = content +[Intrinsic("kotlin.arrays.array")] public fun booleanArrayOf(vararg content : Boolean) : BooleanArray = content + /** * Creates an input stream for reading data from this byte array. @@ -82,5 +83,5 @@ public fun ByteArray.toString(charset: Charset): String = String(this, charset) throw UnsupportedOperationException() /** Returns the array if it's not null, or an empty array otherwise. */ -public inline fun Array?.orEmpty(): Array = this ?: array() +public inline fun Array?.orEmpty(): Array = this ?: arrayOf() diff --git a/libraries/stdlib/src/kotlin/deprecated/Arrays.kt b/libraries/stdlib/src/kotlin/deprecated/Arrays.kt new file mode 100644 index 00000000000..cc198451aaa --- /dev/null +++ b/libraries/stdlib/src/kotlin/deprecated/Arrays.kt @@ -0,0 +1,38 @@ +package kotlin + +// deprecated to be removed after M12 + +deprecated("Use arrayOf() instead.") +inline public fun array(vararg t : T) : Array = arrayOf(*t) + +suppress("NOTHING_TO_INLINE") +deprecated("Use doubleArrayOf() instead.") +inline public fun doubleArray(vararg content : Double) : DoubleArray = doubleArrayOf(*content) + +suppress("NOTHING_TO_INLINE") +deprecated("Use floatArrayOf() instead.") +inline public fun floatArray(vararg content : Float) : FloatArray = floatArrayOf(*content) + +suppress("NOTHING_TO_INLINE") +deprecated("Use longArrayOf() instead.") +inline public fun longArray(vararg content : Long) : LongArray = longArrayOf(*content) + +suppress("NOTHING_TO_INLINE") +deprecated("Use intArrayOf() instead.") +inline public fun intArray(vararg content : Int) : IntArray = intArrayOf(*content) + +suppress("NOTHING_TO_INLINE") +deprecated("Use charArrayOf() instead.") +inline public fun charArray(vararg content : Char) : CharArray = charArrayOf(*content) + +suppress("NOTHING_TO_INLINE") +deprecated("Use shortArrayOf() instead.") +inline public fun shortArray(vararg content : Short) : ShortArray = shortArrayOf(*content) + +suppress("NOTHING_TO_INLINE") +deprecated("Use byteArrayOf() instead.") +inline public fun byteArray(vararg content : Byte) : ByteArray = byteArrayOf(*content) + +suppress("NOTHING_TO_INLINE") +deprecated("Use booleanArrayOf() instead.") +inline public fun booleanArray(vararg content : Boolean) : BooleanArray = booleanArrayOf(*content) diff --git a/libraries/stdlib/test/collections/ArraysJVMTest.kt b/libraries/stdlib/test/collections/ArraysJVMTest.kt index 1189c774003..79c8203c4d4 100644 --- a/libraries/stdlib/test/collections/ArraysJVMTest.kt +++ b/libraries/stdlib/test/collections/ArraysJVMTest.kt @@ -6,196 +6,196 @@ import org.junit.Test as test class ArraysJVMTest { test fun sort() { - var a = intArray(5, 2, 1, 4, 3) - var b = intArray(1, 2, 3, 4, 5) + var a = intArrayOf(5, 2, 1, 4, 3) + var b = intArrayOf(1, 2, 3, 4, 5) a.sort() for (i in a.indices) expect(b[i]) { a[i] } } test fun copyOf() { - checkContent(booleanArray(true, false, true, false, true, false).copyOf().iterator(), 6) { it % 2 == 0 } - checkContent(byteArray(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it.toByte() } - checkContent(shortArray(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it.toShort() } - checkContent(intArray(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it } - checkContent(longArray(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it.toLong() } - checkContent(floatArray(0.toFloat(), 1.toFloat(), 2.toFloat(), 3.toFloat()).copyOf().iterator(), 4) { it.toFloat() } - checkContent(doubleArray(0.0, 1.0, 2.0, 3.0, 4.0, 5.0).copyOf().iterator(), 6) { it.toDouble() } - checkContent(charArray('0', '1', '2', '3', '4', '5').copyOf().iterator(), 6) { (it + '0').toChar() } + checkContent(booleanArrayOf(true, false, true, false, true, false).copyOf().iterator(), 6) { it % 2 == 0 } + checkContent(byteArrayOf(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it.toByte() } + checkContent(shortArrayOf(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it.toShort() } + checkContent(intArrayOf(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it } + checkContent(longArrayOf(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it.toLong() } + checkContent(floatArrayOf(0.toFloat(), 1.toFloat(), 2.toFloat(), 3.toFloat()).copyOf().iterator(), 4) { it.toFloat() } + checkContent(doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0).copyOf().iterator(), 6) { it.toDouble() } + checkContent(charArrayOf('0', '1', '2', '3', '4', '5').copyOf().iterator(), 6) { (it + '0').toChar() } } test fun copyOfRange() { - checkContent(booleanArray(true, false, true, false, true, false).copyOfRange(0, 3).iterator(), 3) { it % 2 == 0 } - checkContent(byteArray(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it.toByte() } - checkContent(shortArray(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it.toShort() } - checkContent(intArray(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it } - checkContent(longArray(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it.toLong() } - checkContent(floatArray(0.toFloat(), 1.toFloat(), 2.toFloat(), 3.toFloat()).copyOfRange(0, 3).iterator(), 3) { it.toFloat() } - checkContent(doubleArray(0.0, 1.0, 2.0, 3.0, 4.0, 5.0).copyOfRange(0, 3).iterator(), 3) { it.toDouble() } - checkContent(charArray('0', '1', '2', '3', '4', '5').copyOfRange(0, 3).iterator(), 3) { (it + '0').toChar() } + checkContent(booleanArrayOf(true, false, true, false, true, false).copyOfRange(0, 3).iterator(), 3) { it % 2 == 0 } + checkContent(byteArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it.toByte() } + checkContent(shortArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it.toShort() } + checkContent(intArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it } + checkContent(longArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it.toLong() } + checkContent(floatArrayOf(0.toFloat(), 1.toFloat(), 2.toFloat(), 3.toFloat()).copyOfRange(0, 3).iterator(), 3) { it.toFloat() } + checkContent(doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0).copyOfRange(0, 3).iterator(), 3) { it.toDouble() } + checkContent(charArrayOf('0', '1', '2', '3', '4', '5').copyOfRange(0, 3).iterator(), 3) { (it + '0').toChar() } } test fun reduce() { - expect(-4) { intArray(1, 2, 3) reduce { a, b -> a - b } } - expect(-4.toLong()) { longArray(1, 2, 3) reduce { a, b -> a - b } } - expect(-4.toFloat()) { floatArray(1.toFloat(), 2.toFloat(), 3.toFloat()) reduce { a, b -> a - b } } - expect(-4.0) { doubleArray(1.0, 2.0, 3.0) reduce { a, b -> a - b } } - expect('3') { charArray('1', '3', '2') reduce { a, b -> if (a > b) a else b } } - expect(false) { booleanArray(true, true, false) reduce { a, b -> a && b } } - expect(true) { booleanArray(true, true) reduce { a, b -> a && b } } - expect(0.toByte()) { byteArray(3, 2, 1) reduce { a, b -> (a - b).toByte() } } - expect(0.toShort()) { shortArray(3, 2, 1) reduce { a, b -> (a - b).toShort() } } + expect(-4) { intArrayOf(1, 2, 3) reduce { a, b -> a - b } } + expect(-4.toLong()) { longArrayOf(1, 2, 3) reduce { a, b -> a - b } } + expect(-4.toFloat()) { floatArrayOf(1.toFloat(), 2.toFloat(), 3.toFloat()) reduce { a, b -> a - b } } + expect(-4.0) { doubleArrayOf(1.0, 2.0, 3.0) reduce { a, b -> a - b } } + expect('3') { charArrayOf('1', '3', '2') reduce { a, b -> if (a > b) a else b } } + expect(false) { booleanArrayOf(true, true, false) reduce { a, b -> a && b } } + expect(true) { booleanArrayOf(true, true) reduce { a, b -> a && b } } + expect(0.toByte()) { byteArrayOf(3, 2, 1) reduce { a, b -> (a - b).toByte() } } + expect(0.toShort()) { shortArrayOf(3, 2, 1) reduce { a, b -> (a - b).toShort() } } failsWith (javaClass()) { - intArray().reduce { a, b -> a + b } + intArrayOf().reduce { a, b -> a + b } } } test fun reduceRight() { - expect(2) { intArray(1, 2, 3) reduceRight { a, b -> a - b } } - expect(2.toLong()) { longArray(1, 2, 3) reduceRight { a, b -> a - b } } - expect(2.toFloat()) { floatArray(1.toFloat(), 2.toFloat(), 3.toFloat()) reduceRight { a, b -> a - b } } - expect(2.0) { doubleArray(1.0, 2.0, 3.0) reduceRight { a, b -> a - b } } - expect('3') { charArray('1', '3', '2') reduceRight { a, b -> if (a > b) a else b } } - expect(false) { booleanArray(true, true, false) reduceRight { a, b -> a && b } } - expect(true) { booleanArray(true, true) reduceRight { a, b -> a && b } } - expect(2.toByte()) { byteArray(1, 2, 3) reduceRight { a, b -> (a - b).toByte() } } - expect(2.toShort()) { shortArray(1, 2, 3) reduceRight { a, b -> (a - b).toShort() } } + expect(2) { intArrayOf(1, 2, 3) reduceRight { a, b -> a - b } } + expect(2.toLong()) { longArrayOf(1, 2, 3) reduceRight { a, b -> a - b } } + expect(2.toFloat()) { floatArrayOf(1.toFloat(), 2.toFloat(), 3.toFloat()) reduceRight { a, b -> a - b } } + expect(2.0) { doubleArrayOf(1.0, 2.0, 3.0) reduceRight { a, b -> a - b } } + expect('3') { charArrayOf('1', '3', '2') reduceRight { a, b -> if (a > b) a else b } } + expect(false) { booleanArrayOf(true, true, false) reduceRight { a, b -> a && b } } + expect(true) { booleanArrayOf(true, true) reduceRight { a, b -> a && b } } + expect(2.toByte()) { byteArrayOf(1, 2, 3) reduceRight { a, b -> (a - b).toByte() } } + expect(2.toShort()) { shortArrayOf(1, 2, 3) reduceRight { a, b -> (a - b).toShort() } } failsWith (javaClass()) { - intArray().reduceRight { a, b -> a + b } + intArrayOf().reduceRight { a, b -> a + b } } } test fun indexOf() { - expect(-1) { byteArray(1, 2, 3) indexOf 0 } - expect(0) { byteArray(1, 2, 3) indexOf 1 } - expect(1) { byteArray(1, 2, 3) indexOf 2 } - expect(2) { byteArray(1, 2, 3) indexOf 3 } + expect(-1) { byteArrayOf(1, 2, 3) indexOf 0 } + expect(0) { byteArrayOf(1, 2, 3) indexOf 1 } + expect(1) { byteArrayOf(1, 2, 3) indexOf 2 } + expect(2) { byteArrayOf(1, 2, 3) indexOf 3 } - expect(-1) { shortArray(1, 2, 3) indexOf 0 } - expect(0) { shortArray(1, 2, 3) indexOf 1 } - expect(1) { shortArray(1, 2, 3) indexOf 2 } - expect(2) { shortArray(1, 2, 3) indexOf 3 } + expect(-1) { shortArrayOf(1, 2, 3) indexOf 0 } + expect(0) { shortArrayOf(1, 2, 3) indexOf 1 } + expect(1) { shortArrayOf(1, 2, 3) indexOf 2 } + expect(2) { shortArrayOf(1, 2, 3) indexOf 3 } - expect(-1) { intArray(1, 2, 3) indexOf 0 } - expect(0) { intArray(1, 2, 3) indexOf 1 } - expect(1) { intArray(1, 2, 3) indexOf 2 } - expect(2) { intArray(1, 2, 3) indexOf 3 } + expect(-1) { intArrayOf(1, 2, 3) indexOf 0 } + expect(0) { intArrayOf(1, 2, 3) indexOf 1 } + expect(1) { intArrayOf(1, 2, 3) indexOf 2 } + expect(2) { intArrayOf(1, 2, 3) indexOf 3 } - expect(-1) { longArray(1, 2, 3) indexOf 0 } - expect(0) { longArray(1, 2, 3) indexOf 1 } - expect(1) { longArray(1, 2, 3) indexOf 2 } - expect(2) { longArray(1, 2, 3) indexOf 3 } + expect(-1) { longArrayOf(1, 2, 3) indexOf 0 } + expect(0) { longArrayOf(1, 2, 3) indexOf 1 } + expect(1) { longArrayOf(1, 2, 3) indexOf 2 } + expect(2) { longArrayOf(1, 2, 3) indexOf 3 } - expect(-1) { floatArray(1.0f, 2.0f, 3.0f) indexOf 0f } - expect(0) { floatArray(1.0f, 2.0f, 3.0f) indexOf 1.0f } - expect(1) { floatArray(1.0f, 2.0f, 3.0f) indexOf 2.0f } - expect(2) { floatArray(1.0f, 2.0f, 3.0f) indexOf 3.0f } + expect(-1) { floatArrayOf(1.0f, 2.0f, 3.0f) indexOf 0f } + expect(0) { floatArrayOf(1.0f, 2.0f, 3.0f) indexOf 1.0f } + expect(1) { floatArrayOf(1.0f, 2.0f, 3.0f) indexOf 2.0f } + expect(2) { floatArrayOf(1.0f, 2.0f, 3.0f) indexOf 3.0f } - expect(-1) { doubleArray(1.0, 2.0, 3.0) indexOf 0.0 } - expect(0) { doubleArray(1.0, 2.0, 3.0) indexOf 1.0 } - expect(1) { doubleArray(1.0, 2.0, 3.0) indexOf 2.0 } - expect(2) { doubleArray(1.0, 2.0, 3.0) indexOf 3.0 } + expect(-1) { doubleArrayOf(1.0, 2.0, 3.0) indexOf 0.0 } + expect(0) { doubleArrayOf(1.0, 2.0, 3.0) indexOf 1.0 } + expect(1) { doubleArrayOf(1.0, 2.0, 3.0) indexOf 2.0 } + expect(2) { doubleArrayOf(1.0, 2.0, 3.0) indexOf 3.0 } - expect(-1) { charArray('a', 'b', 'c') indexOf 'z' } - expect(0) { charArray('a', 'b', 'c') indexOf 'a' } - expect(1) { charArray('a', 'b', 'c') indexOf 'b' } - expect(2) { charArray('a', 'b', 'c') indexOf 'c' } + expect(-1) { charArrayOf('a', 'b', 'c') indexOf 'z' } + expect(0) { charArrayOf('a', 'b', 'c') indexOf 'a' } + expect(1) { charArrayOf('a', 'b', 'c') indexOf 'b' } + expect(2) { charArrayOf('a', 'b', 'c') indexOf 'c' } - expect(0) { booleanArray(true, false) indexOf true } - expect(1) { booleanArray(true, false) indexOf false } - expect(-1) { booleanArray(true) indexOf false } + expect(0) { booleanArrayOf(true, false) indexOf true } + expect(1) { booleanArrayOf(true, false) indexOf false } + expect(-1) { booleanArrayOf(true) indexOf false } } test fun isEmpty() { - assertTrue(intArray().isEmpty()) - assertFalse(intArray(1).isEmpty()) - assertTrue(byteArray().isEmpty()) - assertFalse(byteArray(1).isEmpty()) - assertTrue(shortArray().isEmpty()) - assertFalse(shortArray(1).isEmpty()) - assertTrue(longArray().isEmpty()) - assertFalse(longArray(1).isEmpty()) - assertTrue(charArray().isEmpty()) - assertFalse(charArray('a').isEmpty()) - assertTrue(floatArray().isEmpty()) - assertFalse(floatArray(0.1.toFloat()).isEmpty()) - assertTrue(doubleArray().isEmpty()) - assertFalse(doubleArray(0.1).isEmpty()) - assertTrue(booleanArray().isEmpty()) - assertFalse(booleanArray(false).isEmpty()) + assertTrue(intArrayOf().isEmpty()) + assertFalse(intArrayOf(1).isEmpty()) + assertTrue(byteArrayOf().isEmpty()) + assertFalse(byteArrayOf(1).isEmpty()) + assertTrue(shortArrayOf().isEmpty()) + assertFalse(shortArrayOf(1).isEmpty()) + assertTrue(longArrayOf().isEmpty()) + assertFalse(longArrayOf(1).isEmpty()) + assertTrue(charArrayOf().isEmpty()) + assertFalse(charArrayOf('a').isEmpty()) + assertTrue(floatArrayOf().isEmpty()) + assertFalse(floatArrayOf(0.1.toFloat()).isEmpty()) + assertTrue(doubleArrayOf().isEmpty()) + assertFalse(doubleArrayOf(0.1).isEmpty()) + assertTrue(booleanArrayOf().isEmpty()) + assertFalse(booleanArrayOf(false).isEmpty()) } test fun isNotEmpty() { - assertFalse(intArray().isNotEmpty()) - assertTrue(intArray(1).isNotEmpty()) + assertFalse(intArrayOf().isNotEmpty()) + assertTrue(intArrayOf(1).isNotEmpty()) } test fun min() { - expect(null, { intArray().min() }) - expect(1, { intArray(1).min() }) - expect(2, { intArray(2, 3).min() }) - expect(2000000000000, { longArray(3000000000000, 2000000000000).min() }) - expect(1, { byteArray(1, 3, 2).min() }) - expect(2, { shortArray(3, 2).min() }) - expect(2.0.toFloat(), { floatArray(3.0.toFloat(), 2.0.toFloat()).min() }) - expect(2.0, { doubleArray(2.0, 3.0).min() }) - expect('a', { charArray('a', 'b').min() }) + expect(null, { intArrayOf().min() }) + expect(1, { intArrayOf(1).min() }) + expect(2, { intArrayOf(2, 3).min() }) + expect(2000000000000, { longArrayOf(3000000000000, 2000000000000).min() }) + expect(1, { byteArrayOf(1, 3, 2).min() }) + expect(2, { shortArrayOf(3, 2).min() }) + expect(2.0.toFloat(), { floatArrayOf(3.0.toFloat(), 2.0.toFloat()).min() }) + expect(2.0, { doubleArrayOf(2.0, 3.0).min() }) + expect('a', { charArrayOf('a', 'b').min() }) } test fun max() { - expect(null, { intArray().max() }) - expect(1, { intArray(1).max() }) - expect(3, { intArray(2, 3).max() }) - expect(3000000000000, { longArray(3000000000000, 2000000000000).max() }) - expect(3, { byteArray(1, 3, 2).max() }) - expect(3, { shortArray(3, 2).max() }) - expect(3.0.toFloat(), { floatArray(3.0.toFloat(), 2.0.toFloat()).max() }) - expect(3.0, { doubleArray(2.0, 3.0).max() }) - expect('b', { charArray('a', 'b').max() }) + expect(null, { intArrayOf().max() }) + expect(1, { intArrayOf(1).max() }) + expect(3, { intArrayOf(2, 3).max() }) + expect(3000000000000, { longArrayOf(3000000000000, 2000000000000).max() }) + expect(3, { byteArrayOf(1, 3, 2).max() }) + expect(3, { shortArrayOf(3, 2).max() }) + expect(3.0.toFloat(), { floatArrayOf(3.0.toFloat(), 2.0.toFloat()).max() }) + expect(3.0, { doubleArrayOf(2.0, 3.0).max() }) + expect('b', { charArrayOf('a', 'b').max() }) } test fun minBy() { - expect(null, { intArray().minBy { it } }) - expect(1, { intArray(1).minBy { it } }) - expect(3, { intArray(2, 3).minBy { -it } }) - expect(2000000000000, { longArray(3000000000000, 2000000000000).minBy { it + 1 } }) - expect(1, { byteArray(1, 3, 2).minBy { it * it } }) - expect(3, { shortArray(3, 2).minBy { "a" } }) - expect(2.0.toFloat(), { floatArray(3.0.toFloat(), 2.0.toFloat()).minBy { it.toString() } }) - expect(2.0, { doubleArray(2.0, 3.0).minBy { Math.sqrt(it) } }) + expect(null, { intArrayOf().minBy { it } }) + expect(1, { intArrayOf(1).minBy { it } }) + expect(3, { intArrayOf(2, 3).minBy { -it } }) + expect(2000000000000, { longArrayOf(3000000000000, 2000000000000).minBy { it + 1 } }) + expect(1, { byteArrayOf(1, 3, 2).minBy { it * it } }) + expect(3, { shortArrayOf(3, 2).minBy { "a" } }) + expect(2.0.toFloat(), { floatArrayOf(3.0.toFloat(), 2.0.toFloat()).minBy { it.toString() } }) + expect(2.0, { doubleArrayOf(2.0, 3.0).minBy { Math.sqrt(it) } }) } test fun minIndex() { - val a = intArray(1, 7, 9, -42, 54, 93) + val a = intArrayOf(1, 7, 9, -42, 54, 93) expect(3, { a.indices.minBy { a[it] } }) } test fun maxBy() { - expect(null, { intArray().maxBy { it } }) - expect(1, { intArray(1).maxBy { it } }) - expect(2, { intArray(2, 3).maxBy { -it } }) - expect(3000000000000, { longArray(3000000000000, 2000000000000).maxBy { it + 1 } }) - expect(3, { byteArray(1, 3, 2).maxBy { it * it } }) - expect(3, { shortArray(3, 2).maxBy { "a" } }) - expect(3.0.toFloat(), { floatArray(3.0.toFloat(), 2.0.toFloat()).maxBy { it.toString() } }) - expect(3.0, { doubleArray(2.0, 3.0).maxBy { Math.sqrt(it) } }) + expect(null, { intArrayOf().maxBy { it } }) + expect(1, { intArrayOf(1).maxBy { it } }) + expect(2, { intArrayOf(2, 3).maxBy { -it } }) + expect(3000000000000, { longArrayOf(3000000000000, 2000000000000).maxBy { it + 1 } }) + expect(3, { byteArrayOf(1, 3, 2).maxBy { it * it } }) + expect(3, { shortArrayOf(3, 2).maxBy { "a" } }) + expect(3.0.toFloat(), { floatArrayOf(3.0.toFloat(), 2.0.toFloat()).maxBy { it.toString() } }) + expect(3.0, { doubleArrayOf(2.0, 3.0).maxBy { Math.sqrt(it) } }) } test fun maxIndex() { - val a = intArray(1, 7, 9, 239, 54, 93) + val a = intArrayOf(1, 7, 9, 239, 54, 93) expect(3, { a.indices.maxBy { a[it] } }) } test fun sum() { - expect(0) { intArray().sum() } - expect(14) { intArray(2, 3, 9).sum() } - expect(3.0) { doubleArray(1.0, 2.0).sum() } - expect(200) { byteArray(100, 100).sum() } - expect(50000) { shortArray(20000, 30000).sum() } - expect(3000000000000) { longArray(1000000000000, 2000000000000).sum() } - expect(3.0.toFloat()) { floatArray(1.0.toFloat(), 2.0.toFloat()).sum() } + expect(0) { intArrayOf().sum() } + expect(14) { intArrayOf(2, 3, 9).sum() } + expect(3.0) { doubleArrayOf(1.0, 2.0).sum() } + expect(200) { byteArrayOf(100, 100).sum() } + expect(50000) { shortArrayOf(20000, 30000).sum() } + expect(3000000000000) { longArrayOf(1000000000000, 2000000000000).sum() } + expect(3.0.toFloat()) { floatArrayOf(1.0.toFloat(), 2.0.toFloat()).sum() } } test fun orEmptyNull() { @@ -208,7 +208,7 @@ class ArraysJVMTest { } test fun orEmptyNotNull() { - val x: Array? = array("1", "2") + val x: Array? = arrayOf("1", "2") val xArray = x.orEmpty() expect(2) { xArray.size() } expect("1") { xArray[0] } @@ -216,122 +216,122 @@ class ArraysJVMTest { } test fun drop() { - expect(listOf(1), { intArray(1).drop(0) }) - expect(listOf(), { intArray().drop(1) }) - expect(listOf(), { intArray(1).drop(1) }) - expect(listOf(3), { intArray(2, 3).drop(1) }) - expect(listOf(2000000000000), { longArray(3000000000000, 2000000000000).drop(1) }) - expect(listOf(3.toByte()), { byteArray(2, 3).drop(1) }) - expect(listOf(3.toShort()), { shortArray(2, 3).drop(1) }) - expect(listOf(3.0f), { floatArray(2f, 3f).drop(1) }) - expect(listOf(3.0), { doubleArray(2.0, 3.0).drop(1) }) - expect(listOf(false), { booleanArray(true, false).drop(1) }) - expect(listOf('b'), { charArray('a', 'b').drop(1) }) - expect(listOf("b"), { array("a", "b").drop(1) }) + expect(listOf(1), { intArrayOf(1).drop(0) }) + expect(listOf(), { intArrayOf().drop(1) }) + expect(listOf(), { intArrayOf(1).drop(1) }) + expect(listOf(3), { intArrayOf(2, 3).drop(1) }) + expect(listOf(2000000000000), { longArrayOf(3000000000000, 2000000000000).drop(1) }) + expect(listOf(3.toByte()), { byteArrayOf(2, 3).drop(1) }) + expect(listOf(3.toShort()), { shortArrayOf(2, 3).drop(1) }) + expect(listOf(3.0f), { floatArrayOf(2f, 3f).drop(1) }) + expect(listOf(3.0), { doubleArrayOf(2.0, 3.0).drop(1) }) + expect(listOf(false), { booleanArrayOf(true, false).drop(1) }) + expect(listOf('b'), { charArrayOf('a', 'b').drop(1) }) + expect(listOf("b"), { arrayOf("a", "b").drop(1) }) fails { listOf(2).drop(-1) } } test fun dropWhile() { - expect(listOf(), { intArray().dropWhile { it < 3 } }) - expect(listOf(), { intArray(1).dropWhile { it < 3 } }) - expect(listOf(3, 1), { intArray(2, 3, 1).dropWhile { it < 3 } }) - expect(listOf(2000000000000), { longArray(3000000000000, 2000000000000).dropWhile { it > 2000000000000 } }) - expect(listOf(3.toByte(), 1.toByte()), { byteArray(2, 3, 1).dropWhile { it < 3 } }) - expect(listOf(3.toShort(), 1.toShort()), { shortArray(2, 3, 1).dropWhile { it < 3 } }) - expect(listOf(3f, 1f), { floatArray(2f, 3f, 1f).dropWhile { it < 3 } }) - expect(listOf(3.0, 1.0), { doubleArray(2.0, 3.0, 1.0).dropWhile { it < 3 } }) - expect(listOf(false, true), { booleanArray(true, false, true).dropWhile { it } }) - expect(listOf('b', 'a'), { charArray('a', 'b', 'a').dropWhile { it < 'b' } }) - expect(listOf("b", "a"), { array("a", "b", "a").dropWhile { it < "b" } }) + expect(listOf(), { intArrayOf().dropWhile { it < 3 } }) + expect(listOf(), { intArrayOf(1).dropWhile { it < 3 } }) + expect(listOf(3, 1), { intArrayOf(2, 3, 1).dropWhile { it < 3 } }) + expect(listOf(2000000000000), { longArrayOf(3000000000000, 2000000000000).dropWhile { it > 2000000000000 } }) + expect(listOf(3.toByte(), 1.toByte()), { byteArrayOf(2, 3, 1).dropWhile { it < 3 } }) + expect(listOf(3.toShort(), 1.toShort()), { shortArrayOf(2, 3, 1).dropWhile { it < 3 } }) + expect(listOf(3f, 1f), { floatArrayOf(2f, 3f, 1f).dropWhile { it < 3 } }) + expect(listOf(3.0, 1.0), { doubleArrayOf(2.0, 3.0, 1.0).dropWhile { it < 3 } }) + expect(listOf(false, true), { booleanArrayOf(true, false, true).dropWhile { it } }) + expect(listOf('b', 'a'), { charArrayOf('a', 'b', 'a').dropWhile { it < 'b' } }) + expect(listOf("b", "a"), { arrayOf("a", "b", "a").dropWhile { it < "b" } }) } test fun take() { - expect(listOf(), { intArray().take(1) }) - expect(listOf(), { intArray(1).take(0) }) - expect(listOf(1), { intArray(1).take(1) }) - expect(listOf(2), { intArray(2, 3).take(1) }) - expect(listOf(3000000000000), { longArray(3000000000000, 2000000000000).take(1) }) - expect(listOf(2.toByte()), { byteArray(2, 3).take(1) }) - expect(listOf(2.toShort()), { shortArray(2, 3).take(1) }) - expect(listOf(2.0f), { floatArray(2f, 3f).take(1) }) - expect(listOf(2.0), { doubleArray(2.0, 3.0).take(1) }) - expect(listOf(true), { booleanArray(true, false).take(1) }) - expect(listOf('a'), { charArray('a', 'b').take(1) }) - expect(listOf("a"), { array("a", "b").take(1) }) + expect(listOf(), { intArrayOf().take(1) }) + expect(listOf(), { intArrayOf(1).take(0) }) + expect(listOf(1), { intArrayOf(1).take(1) }) + expect(listOf(2), { intArrayOf(2, 3).take(1) }) + expect(listOf(3000000000000), { longArrayOf(3000000000000, 2000000000000).take(1) }) + expect(listOf(2.toByte()), { byteArrayOf(2, 3).take(1) }) + expect(listOf(2.toShort()), { shortArrayOf(2, 3).take(1) }) + expect(listOf(2.0f), { floatArrayOf(2f, 3f).take(1) }) + expect(listOf(2.0), { doubleArrayOf(2.0, 3.0).take(1) }) + expect(listOf(true), { booleanArrayOf(true, false).take(1) }) + expect(listOf('a'), { charArrayOf('a', 'b').take(1) }) + expect(listOf("a"), { arrayOf("a", "b").take(1) }) fails { listOf(1).take(-1) } } test fun takeLast() { - expect(listOf(), { intArray().takeLast(1) }) - expect(listOf(), { intArray(1).takeLast(0) }) - expect(listOf(1), { intArray(1).takeLast(1) }) - expect(listOf(3), { intArray(2, 3).takeLast(1) }) - expect(listOf(2000000000000), { longArray(3000000000000, 2000000000000).takeLast(1) }) - expect(listOf(3.toByte()), { byteArray(2, 3).takeLast(1) }) - expect(listOf(3.toShort()), { shortArray(2, 3).takeLast(1) }) - expect(listOf(3.0f), { floatArray(2f, 3f).takeLast(1) }) - expect(listOf(3.0), { doubleArray(2.0, 3.0).takeLast(1) }) - expect(listOf(false), { booleanArray(true, false).takeLast(1) }) - expect(listOf('b'), { charArray('a', 'b').takeLast(1) }) - expect(listOf("b"), { array("a", "b").takeLast(1) }) + expect(listOf(), { intArrayOf().takeLast(1) }) + expect(listOf(), { intArrayOf(1).takeLast(0) }) + expect(listOf(1), { intArrayOf(1).takeLast(1) }) + expect(listOf(3), { intArrayOf(2, 3).takeLast(1) }) + expect(listOf(2000000000000), { longArrayOf(3000000000000, 2000000000000).takeLast(1) }) + expect(listOf(3.toByte()), { byteArrayOf(2, 3).takeLast(1) }) + expect(listOf(3.toShort()), { shortArrayOf(2, 3).takeLast(1) }) + expect(listOf(3.0f), { floatArrayOf(2f, 3f).takeLast(1) }) + expect(listOf(3.0), { doubleArrayOf(2.0, 3.0).takeLast(1) }) + expect(listOf(false), { booleanArrayOf(true, false).takeLast(1) }) + expect(listOf('b'), { charArrayOf('a', 'b').takeLast(1) }) + expect(listOf("b"), { arrayOf("a", "b").takeLast(1) }) fails { listOf(1).takeLast(-1) } } test fun takeWhile() { - expect(listOf(), { intArray().takeWhile { it < 3 } }) - expect(listOf(1), { intArray(1).takeWhile { it < 3 } }) - expect(listOf(2), { intArray(2, 3, 1).takeWhile { it < 3 } }) - expect(listOf(3000000000000), { longArray(3000000000000, 2000000000000).takeWhile { it > 2000000000000 } }) - expect(listOf(2.toByte()), { byteArray(2, 3, 1).takeWhile { it < 3 } }) - expect(listOf(2.toShort()), { shortArray(2, 3, 1).takeWhile { it < 3 } }) - expect(listOf(2f), { floatArray(2f, 3f, 1f).takeWhile { it < 3 } }) - expect(listOf(2.0), { doubleArray(2.0, 3.0, 1.0).takeWhile { it < 3 } }) - expect(listOf(true), { booleanArray(true, false, true).takeWhile { it } }) - expect(listOf('a'), { charArray('a', 'b', 'a').takeWhile { it < 'b' } }) - expect(listOf("a"), { array("a", "b", "a").takeWhile { it < "b" } }) + expect(listOf(), { intArrayOf().takeWhile { it < 3 } }) + expect(listOf(1), { intArrayOf(1).takeWhile { it < 3 } }) + expect(listOf(2), { intArrayOf(2, 3, 1).takeWhile { it < 3 } }) + expect(listOf(3000000000000), { longArrayOf(3000000000000, 2000000000000).takeWhile { it > 2000000000000 } }) + expect(listOf(2.toByte()), { byteArrayOf(2, 3, 1).takeWhile { it < 3 } }) + expect(listOf(2.toShort()), { shortArrayOf(2, 3, 1).takeWhile { it < 3 } }) + expect(listOf(2f), { floatArrayOf(2f, 3f, 1f).takeWhile { it < 3 } }) + expect(listOf(2.0), { doubleArrayOf(2.0, 3.0, 1.0).takeWhile { it < 3 } }) + expect(listOf(true), { booleanArrayOf(true, false, true).takeWhile { it } }) + expect(listOf('a'), { charArrayOf('a', 'b', 'a').takeWhile { it < 'b' } }) + expect(listOf("a"), { arrayOf("a", "b", "a").takeWhile { it < "b" } }) } test fun filter() { - expect(listOf(), { intArray().filter { it > 2 } }) - expect(listOf(), { intArray(1).filter { it > 2 } }) - expect(listOf(3), { intArray(2, 3).filter { it > 2 } }) - expect(listOf(3000000000000), { longArray(3000000000000, 2000000000000).filter { it > 2000000000000 } }) - expect(listOf(3.toByte()), { byteArray(2, 3).filter { it > 2 } }) - expect(listOf(3.toShort()), { shortArray(2, 3).filter { it > 2 } }) - expect(listOf(3.0f), { floatArray(2f, 3f).filter { it > 2 } }) - expect(listOf(3.0), { doubleArray(2.0, 3.0).filter { it > 2 } }) - expect(listOf(true), { booleanArray(true, false).filter { it } }) - expect(listOf('b'), { charArray('a', 'b').filter { it > 'a' } }) - expect(listOf("b"), { array("a", "b").filter { it > "a" } }) + expect(listOf(), { intArrayOf().filter { it > 2 } }) + expect(listOf(), { intArrayOf(1).filter { it > 2 } }) + expect(listOf(3), { intArrayOf(2, 3).filter { it > 2 } }) + expect(listOf(3000000000000), { longArrayOf(3000000000000, 2000000000000).filter { it > 2000000000000 } }) + expect(listOf(3.toByte()), { byteArrayOf(2, 3).filter { it > 2 } }) + expect(listOf(3.toShort()), { shortArrayOf(2, 3).filter { it > 2 } }) + expect(listOf(3.0f), { floatArrayOf(2f, 3f).filter { it > 2 } }) + expect(listOf(3.0), { doubleArrayOf(2.0, 3.0).filter { it > 2 } }) + expect(listOf(true), { booleanArrayOf(true, false).filter { it } }) + expect(listOf('b'), { charArrayOf('a', 'b').filter { it > 'a' } }) + expect(listOf("b"), { arrayOf("a", "b").filter { it > "a" } }) } test fun filterNot() { - expect(listOf(), { intArray().filterNot { it > 2 } }) - expect(listOf(1), { intArray(1).filterNot { it > 2 } }) - expect(listOf(2), { intArray(2, 3).filterNot { it > 2 } }) - expect(listOf(2000000000000), { longArray(3000000000000, 2000000000000).filterNot { it > 2000000000000 } }) - expect(listOf(2.toByte()), { byteArray(2, 3).filterNot { it > 2 } }) - expect(listOf(2.toShort()), { shortArray(2, 3).filterNot { it > 2 } }) - expect(listOf(2.0f), { floatArray(2f, 3f).filterNot { it > 2 } }) - expect(listOf(2.0), { doubleArray(2.0, 3.0).filterNot { it > 2 } }) - expect(listOf(false), { booleanArray(true, false).filterNot { it } }) - expect(listOf('a'), { charArray('a', 'b').filterNot { it > 'a' } }) - expect(listOf("a"), { array("a", "b").filterNot { it > "a" } }) + expect(listOf(), { intArrayOf().filterNot { it > 2 } }) + expect(listOf(1), { intArrayOf(1).filterNot { it > 2 } }) + expect(listOf(2), { intArrayOf(2, 3).filterNot { it > 2 } }) + expect(listOf(2000000000000), { longArrayOf(3000000000000, 2000000000000).filterNot { it > 2000000000000 } }) + expect(listOf(2.toByte()), { byteArrayOf(2, 3).filterNot { it > 2 } }) + expect(listOf(2.toShort()), { shortArrayOf(2, 3).filterNot { it > 2 } }) + expect(listOf(2.0f), { floatArrayOf(2f, 3f).filterNot { it > 2 } }) + expect(listOf(2.0), { doubleArrayOf(2.0, 3.0).filterNot { it > 2 } }) + expect(listOf(false), { booleanArrayOf(true, false).filterNot { it } }) + expect(listOf('a'), { charArrayOf('a', 'b').filterNot { it > 'a' } }) + expect(listOf("a"), { arrayOf("a", "b").filterNot { it > "a" } }) } test fun filterNotNull() { - expect(listOf("a"), { array("a", null).filterNotNull() }) + expect(listOf("a"), { arrayOf("a", null).filterNotNull() }) } test fun asListPrimitives() { // Array of primitives - val arr = intArray(1, 2, 3, 4, 2, 5) + val arr = intArrayOf(1, 2, 3, 4, 2, 5) val list = arr.asList() assertEquals(list, arr.toList()) @@ -362,7 +362,7 @@ class ArraysJVMTest { } test fun asListObjects() { - val arr = array("a", "b", "c", "d", "b", "e") + val arr = arrayOf("a", "b", "c", "d", "b", "e") val list = arr.asList() assertEquals(list, arr.toList()) diff --git a/libraries/stdlib/test/collections/ArraysTest.kt b/libraries/stdlib/test/collections/ArraysTest.kt index a4164a6a797..f0b6b0ad360 100644 --- a/libraries/stdlib/test/collections/ArraysTest.kt +++ b/libraries/stdlib/test/collections/ArraysTest.kt @@ -27,7 +27,7 @@ class ArraysTest { } test fun arrayLastIndex() { - val arr1 = intArray(0, 1, 2, 3, 4) + val arr1 = intArrayOf(0, 1, 2, 3, 4) assertEquals(4, arr1.lastIndex) assertEquals(4, arr1[arr1.lastIndex]) @@ -105,72 +105,72 @@ class ArraysTest { } test fun min() { - expect(null, { array().min() }) - expect(1, { array(1).min() }) - expect(2, { array(2, 3).min() }) - expect(2000000000000, { array(3000000000000, 2000000000000).min() }) - expect('a', { array('a', 'b').min() }) - expect("a", { array("a", "b").min() }) + expect(null, { arrayOf().min() }) + expect(1, { arrayOf(1).min() }) + expect(2, { arrayOf(2, 3).min() }) + expect(2000000000000, { arrayOf(3000000000000, 2000000000000).min() }) + expect('a', { arrayOf('a', 'b').min() }) + expect("a", { arrayOf("a", "b").min() }) } test fun max() { - expect(null, { array().max() }) - expect(1, { array(1).max() }) - expect(3, { array(2, 3).max() }) - expect(3000000000000, { array(3000000000000, 2000000000000).max() }) - expect('b', { array('a', 'b').max() }) - expect("b", { array("a", "b").max() }) + expect(null, { arrayOf().max() }) + expect(1, { arrayOf(1).max() }) + expect(3, { arrayOf(2, 3).max() }) + expect(3000000000000, { arrayOf(3000000000000, 2000000000000).max() }) + expect('b', { arrayOf('a', 'b').max() }) + expect("b", { arrayOf("a", "b").max() }) } test fun minBy() { - expect(null, { array().minBy { it } }) - expect(1, { array(1).minBy { it } }) - expect(3, { array(2, 3).minBy { -it } }) - expect('a', { array('a', 'b').minBy { "x$it" } }) - expect("b", { array("b", "abc").minBy { it.length() } }) + expect(null, { arrayOf().minBy { it } }) + expect(1, { arrayOf(1).minBy { it } }) + expect(3, { arrayOf(2, 3).minBy { -it } }) + expect('a', { arrayOf('a', 'b').minBy { "x$it" } }) + expect("b", { arrayOf("b", "abc").minBy { it.length() } }) } test fun maxBy() { - expect(null, { array().maxBy { it } }) - expect(1, { array(1).maxBy { it } }) - expect(2, { array(2, 3).maxBy { -it } }) - expect('b', { array('a', 'b').maxBy { "x$it" } }) - expect("abc", { array("b", "abc").maxBy { it.length() } }) + expect(null, { arrayOf().maxBy { it } }) + expect(1, { arrayOf(1).maxBy { it } }) + expect(2, { arrayOf(2, 3).maxBy { -it } }) + expect('b', { arrayOf('a', 'b').maxBy { "x$it" } }) + expect("abc", { arrayOf("b", "abc").maxBy { it.length() } }) } test fun minByEvaluateOnce() { var c = 0 - expect(1, { array(5, 4, 3, 2, 1).minBy { c++; it * it } }) + expect(1, { arrayOf(5, 4, 3, 2, 1).minBy { c++; it * it } }) assertEquals(5, c) } test fun maxByEvaluateOnce() { var c = 0 - expect(5, { array(5, 4, 3, 2, 1).maxBy { c++; it * it } }) + expect(5, { arrayOf(5, 4, 3, 2, 1).maxBy { c++; it * it } }) assertEquals(5, c) } test fun sum() { - expect(0) { array().sum() } - expect(14) { array(2, 3, 9).sum() } - expect(3.0) { array(1.0, 2.0).sum() } - expect(200) { array(100, 100).sum() } - expect(50000) { array(20000, 30000).sum() } - expect(3000000000000) { array(1000000000000, 2000000000000).sum() } - expect(3.0.toFloat()) { array(1.0.toFloat(), 2.0.toFloat()).sum() } + expect(0) { arrayOf().sum() } + expect(14) { arrayOf(2, 3, 9).sum() } + expect(3.0) { arrayOf(1.0, 2.0).sum() } + expect(200) { arrayOf(100, 100).sum() } + expect(50000) { arrayOf(20000, 30000).sum() } + expect(3000000000000) { arrayOf(1000000000000, 2000000000000).sum() } + expect(3.0.toFloat()) { arrayOf(1.0.toFloat(), 2.0.toFloat()).sum() } } test fun indexOf() { - expect(-1) { array("cat", "dog", "bird").indexOf("mouse") } - expect(0) { array("cat", "dog", "bird").indexOf("cat") } - expect(1) { array("cat", "dog", "bird").indexOf("dog") } - expect(2) { array("cat", "dog", "bird").indexOf("bird") } - expect(0) { array(null, "dog", null).indexOf(null : String?)} + expect(-1) { arrayOf("cat", "dog", "bird").indexOf("mouse") } + expect(0) { arrayOf("cat", "dog", "bird").indexOf("cat") } + expect(1) { arrayOf("cat", "dog", "bird").indexOf("dog") } + expect(2) { arrayOf("cat", "dog", "bird").indexOf("bird") } + expect(0) { arrayOf(null, "dog", null).indexOf(null : String?)} - expect(-1) { array("cat", "dog", "bird").indexOfFirst { it.contains("p") } } - expect(0) { array("cat", "dog", "bird").indexOfFirst { it.startsWith('c') } } - expect(1) { array("cat", "dog", "bird").indexOfFirst { it.startsWith('d') } } - expect(2) { array("cat", "dog", "bird").indexOfFirst { it.endsWith('d') } } + expect(-1) { arrayOf("cat", "dog", "bird").indexOfFirst { it.contains("p") } } + expect(0) { arrayOf("cat", "dog", "bird").indexOfFirst { it.startsWith('c') } } + expect(1) { arrayOf("cat", "dog", "bird").indexOfFirst { it.startsWith('d') } } + expect(2) { arrayOf("cat", "dog", "bird").indexOfFirst { it.endsWith('d') } } expect(-1) { sequenceOf("cat", "dog", "bird").indexOfFirst { it.contains("p") } } expect(0) { sequenceOf("cat", "dog", "bird").indexOfFirst { it.startsWith('c') } } @@ -179,17 +179,17 @@ class ArraysTest { } test fun lastIndexOf() { - expect(-1) { array("cat", "dog", "bird").lastIndexOf("mouse") } - expect(0) { array("cat", "dog", "bird").lastIndexOf("cat") } - expect(1) { array("cat", "dog", "bird").lastIndexOf("dog") } - expect(2) { array(null, "dog", null).lastIndexOf(null : String?)} - expect(3) { array("cat", "dog", "bird", "dog").lastIndexOf("dog") } + expect(-1) { arrayOf("cat", "dog", "bird").lastIndexOf("mouse") } + expect(0) { arrayOf("cat", "dog", "bird").lastIndexOf("cat") } + expect(1) { arrayOf("cat", "dog", "bird").lastIndexOf("dog") } + expect(2) { arrayOf(null, "dog", null).lastIndexOf(null : String?)} + expect(3) { arrayOf("cat", "dog", "bird", "dog").lastIndexOf("dog") } - expect(-1) { array("cat", "dog", "bird").indexOfLast { it.contains("p") } } - expect(0) { array("cat", "dog", "bird").indexOfLast { it.startsWith('c') } } - expect(2) { array("cat", "dog", "cap", "bird").indexOfLast { it.startsWith('c') } } - expect(2) { array("cat", "dog", "bird").indexOfLast { it.endsWith('d') } } - expect(3) { array("cat", "dog", "bird", "red").indexOfLast { it.endsWith('d') } } + expect(-1) { arrayOf("cat", "dog", "bird").indexOfLast { it.contains("p") } } + expect(0) { arrayOf("cat", "dog", "bird").indexOfLast { it.startsWith('c') } } + expect(2) { arrayOf("cat", "dog", "cap", "bird").indexOfLast { it.startsWith('c') } } + expect(2) { arrayOf("cat", "dog", "bird").indexOfLast { it.endsWith('d') } } + expect(3) { arrayOf("cat", "dog", "bird", "red").indexOfLast { it.endsWith('d') } } expect(-1) { sequenceOf("cat", "dog", "bird").indexOfLast { it.contains("p") } } expect(0) { sequenceOf("cat", "dog", "bird").indexOfLast { it.startsWith('c') } } @@ -199,62 +199,62 @@ class ArraysTest { } test fun plus() { - assertEquals(listOf("1", "2", "3", "4"), array("1", "2") + array("3", "4")) - assertEquals(listOf("1", "2", "3", "4"), listOf("1", "2") + array("3", "4")) + assertEquals(listOf("1", "2", "3", "4"), arrayOf("1", "2") + arrayOf("3", "4")) + assertEquals(listOf("1", "2", "3", "4"), listOf("1", "2") + arrayOf("3", "4")) } test fun plusVararg() { - fun onePlus(vararg a: String) = array("1") + a + fun onePlus(vararg a: String) = arrayOf("1") + a assertEquals(listOf("1", "2"), onePlus("2")) } test fun first() { - expect(1) { array(1, 2, 3).first() } - expect(2) { array(1, 2, 3).first { it % 2 == 0 } } + expect(1) { arrayOf(1, 2, 3).first() } + expect(2) { arrayOf(1, 2, 3).first { it % 2 == 0 } } } test fun last() { - expect(3) { array(1, 2, 3).last() } - expect(2) { array(1, 2, 3).last { it % 2 == 0 } } + expect(3) { arrayOf(1, 2, 3).last() } + expect(2) { arrayOf(1, 2, 3).last { it % 2 == 0 } } } test fun contains() { - assertTrue(array("1", "2", "3", "4").contains("2")) - assertTrue("3" in array("1", "2", "3", "4")) - assertTrue("0" !in array("1", "2", "3", "4")) + assertTrue(arrayOf("1", "2", "3", "4").contains("2")) + assertTrue("3" in arrayOf("1", "2", "3", "4")) + assertTrue("0" !in arrayOf("1", "2", "3", "4")) } test fun slice() { val iter = listOf(3, 1, 2) - assertEquals(listOf("B"), array("A", "B", "C").slice(1..1)) - assertEquals(listOf('E', 'B', 'C'), array('A', 'B', 'C', 'E').slice(iter)) + assertEquals(listOf("B"), arrayOf("A", "B", "C").slice(1..1)) + assertEquals(listOf('E', 'B', 'C'), arrayOf('A', 'B', 'C', 'E').slice(iter)) - assertEquals(listOf(), array().slice(5..4)) - assertEquals(listOf(), array(1, 2, 3).slice(5..1)) - assertEquals(listOf(2, 3, 9), array(2, 3, 9, 2, 3, 9).slice(iter)) - assertEquals(listOf(2.0, 3.0), array(2.0, 3.0, 9.0).slice(0..1)) - assertEquals(listOf(2f, 3f), array(2f, 3f, 9f).slice(0..1)) - assertEquals(listOf(127, 100), array(50, 100, 127).slice(2 downTo 1)) - assertEquals(listOf(200, 100), array(50, 100, 200).slice(2 downTo 1)) - assertEquals(listOf(100L, 200L, 30L), array(50L, 100L, 200L, 30L).slice(1..3)) - assertEquals(listOf(true, false, true), array(true, false, true, true).slice(iter)) + assertEquals(listOf(), arrayOf().slice(5..4)) + assertEquals(listOf(), arrayOf(1, 2, 3).slice(5..1)) + assertEquals(listOf(2, 3, 9), arrayOf(2, 3, 9, 2, 3, 9).slice(iter)) + assertEquals(listOf(2.0, 3.0), arrayOf(2.0, 3.0, 9.0).slice(0..1)) + assertEquals(listOf(2f, 3f), arrayOf(2f, 3f, 9f).slice(0..1)) + assertEquals(listOf(127, 100), arrayOf(50, 100, 127).slice(2 downTo 1)) + assertEquals(listOf(200, 100), arrayOf(50, 100, 200).slice(2 downTo 1)) + assertEquals(listOf(100L, 200L, 30L), arrayOf(50L, 100L, 200L, 30L).slice(1..3)) + assertEquals(listOf(true, false, true), arrayOf(true, false, true, true).slice(iter)) } test fun toSortedList() { - assertTrue(array().toSortedList().none()) - assertEquals(listOf(1), array(1).toSortedList()) - assertEquals(listOf("aab", "aba", "ac"), array("ac", "aab", "aba").toSortedList()) + assertTrue(arrayOf().toSortedList().none()) + assertEquals(listOf(1), arrayOf(1).toSortedList()) + assertEquals(listOf("aab", "aba", "ac"), arrayOf("ac", "aab", "aba").toSortedList()) } test fun asIterable() { - val arr1 = intArray(1, 2, 3, 4, 5) + val arr1 = intArrayOf(1, 2, 3, 4, 5) val iter1 = arr1.asIterable() assertEquals(arr1.toList(), iter1.toList()) arr1[0] = 0 assertEquals(arr1.toList(), iter1.toList()) - val arr2 = array("one", "two", "three") + val arr2 = arrayOf("one", "two", "three") val iter2 = arr2.asIterable() assertEquals(arr2.toList(), iter2.toList()) arr2[0] = "" @@ -270,14 +270,14 @@ class ArraysTest { } test fun asList() { - assertEquals(listOf(1, 2, 3), intArray(1, 2, 3).asList()) - assertEquals(listOf(1, 2, 3), byteArray(1, 2, 3).asList()) - assertEquals(listOf(true, false), booleanArray(true, false).asList()) + assertEquals(listOf(1, 2, 3), intArrayOf(1, 2, 3).asList()) + assertEquals(listOf(1, 2, 3), byteArrayOf(1, 2, 3).asList()) + assertEquals(listOf(true, false), booleanArrayOf(true, false).asList()) - assertEquals(listOf(1, 2, 3), array(1, 2, 3).asList()) - assertEquals(listOf("abc", "def"), array("abc", "def").asList()) + assertEquals(listOf(1, 2, 3), arrayOf(1, 2, 3).asList()) + assertEquals(listOf("abc", "def"), arrayOf("abc", "def").asList()) - val ints = intArray(1, 5, 7) + val ints = intArrayOf(1, 5, 7) val intsAsList = ints.asList() assertEquals(5, intsAsList[1]) ints[1] = 10 diff --git a/libraries/stdlib/test/collections/CollectionJVMTest.kt b/libraries/stdlib/test/collections/CollectionJVMTest.kt index a80c49fa92a..b06de77e5c0 100644 --- a/libraries/stdlib/test/collections/CollectionJVMTest.kt +++ b/libraries/stdlib/test/collections/CollectionJVMTest.kt @@ -125,7 +125,7 @@ class CollectionJVMTest { } test fun filterIsInstanceArray() { - val src: Array = array(1, 2, 3.toDouble(), "abc", "cde") + val src: Array = arrayOf(1, 2, 3.toDouble(), "abc", "cde") val intValues: List = src.filterIsInstance() assertEquals(listOf(1, 2), intValues) diff --git a/libraries/stdlib/test/collections/CollectionTest.kt b/libraries/stdlib/test/collections/CollectionTest.kt index c52fa776dae..99430078631 100644 --- a/libraries/stdlib/test/collections/CollectionTest.kt +++ b/libraries/stdlib/test/collections/CollectionTest.kt @@ -494,7 +494,7 @@ class CollectionTest { } test fun decomposeArray() { - val (a, b, c, d, e) = array(1, 2, 3, 4, 5) + val (a, b, c, d, e) = arrayOf(1, 2, 3, 4, 5) assertEquals(a, 1) assertEquals(b, 2) assertEquals(c, 3) @@ -503,7 +503,7 @@ class CollectionTest { } test fun decomposeIntArray() { - val (a, b, c, d, e) = intArray(1, 2, 3, 4, 5) + val (a, b, c, d, e) = intArrayOf(1, 2, 3, 4, 5) assertEquals(a, 1) assertEquals(b, 2) assertEquals(c, 3) diff --git a/libraries/stdlib/test/js/javautilCollectionsTest.kt b/libraries/stdlib/test/js/javautilCollectionsTest.kt index b98afdf63d0..81658966d30 100644 --- a/libraries/stdlib/test/js/javautilCollectionsTest.kt +++ b/libraries/stdlib/test/js/javautilCollectionsTest.kt @@ -9,8 +9,8 @@ import org.junit.Test as test fun List.toArrayList() = this.toCollection(ArrayList()) class JavautilCollectionsTest { - val TEST_LIST = array(2, 0, 9, 7, 1).toList() - val SORTED_TEST_LIST = array(0, 1, 2, 7, 9).toList() + val TEST_LIST = arrayOf(2, 0, 9, 7, 1).toList() + val SORTED_TEST_LIST = arrayOf(0, 1, 2, 7, 9).toList() val MAX_ELEMENT = 9 val COMPARATOR = comparator { x: Int, y: Int -> if (x > y) 1 else if (x < y) -1 else 0 }