Skip to content

Commit 0713c9e

Browse files
author
oscar arismendi
committed
KT-20357: Add sample usages for array constructor functions in standard library
Related issue: KT-20357
1 parent 3271b96 commit 0713c9e

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

libraries/stdlib/samples/test/samples/collections/arrays.kt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,4 +534,54 @@ class Arrays {
534534

535535
}
536536

537+
class Constructors {
538+
@Sample
539+
fun doubleArrayOf() {
540+
val doubleArray = doubleArrayOf(1.0, 2.5, 3.14)
541+
assertPrints(doubleArray.contentToString(), "[1.0, 2.5, 3.14]")
542+
}
543+
544+
@Sample
545+
fun floatArrayOf() {
546+
val floatArray = floatArrayOf(1.0f, 2.5f, 3.14f)
547+
assertPrints(floatArray.contentToString(), "[1.0, 2.5, 3.14]")
548+
}
549+
550+
@Sample
551+
fun longArrayOf() {
552+
val longArray = longArrayOf(1L, 2L, 3L)
553+
assertPrints(longArray.contentToString(), "[1, 2, 3]")
554+
}
555+
556+
@Sample
557+
fun intArrayOf() {
558+
val intArray = intArrayOf(1, 2, 3)
559+
assertPrints(intArray.contentToString(), "[1, 2, 3]")
560+
}
561+
562+
@Sample
563+
fun charArrayOf() {
564+
val chars = charArrayOf('a', 'b', 'c')
565+
assertPrints(chars.contentToString(), "[a, b, c]")
566+
}
567+
568+
@Sample
569+
fun shortArrayOf() {
570+
val shortArray = shortArrayOf(1, 2, 3)
571+
assertPrints(shortArray.contentToString(), "[1, 2, 3]")
572+
}
573+
574+
@Sample
575+
fun byteArrayOf() {
576+
val byteArray = byteArrayOf(1, 2, 3)
577+
assertPrints(byteArray.contentToString(), "[1, 2, 3]")
578+
}
579+
580+
@Sample
581+
fun booleanArrayOf() {
582+
val booleanArray = booleanArrayOf(true, false, true)
583+
assertPrints(booleanArray.contentToString(), "[true, false, true]")
584+
}
585+
}
586+
537587
}

libraries/stdlib/src/kotlin/Library.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,41 +33,57 @@ public expect inline fun <reified T> arrayOf(vararg elements: T): Array<T>
3333

3434
/**
3535
* Returns an array containing the specified [Double] numbers.
36+
*
37+
* @sample samples.collections.Arrays.Constructors.doubleArrayOf
3638
*/
3739
public expect fun doubleArrayOf(vararg elements: Double): DoubleArray
3840

3941
/**
4042
* Returns an array containing the specified [Float] numbers.
43+
*
44+
* @sample samples.collections.Arrays.Constructors.floatArrayOf
4145
*/
4246
public expect fun floatArrayOf(vararg elements: Float): FloatArray
4347

4448
/**
4549
* Returns an array containing the specified [Long] numbers.
50+
*
51+
* @sample samples.collections.Arrays.Constructors.longArrayOf
4652
*/
4753
public expect fun longArrayOf(vararg elements: Long): LongArray
4854

4955
/**
5056
* Returns an array containing the specified [Int] numbers.
57+
*
58+
* @sample samples.collections.Arrays.Constructors.intArrayOf
5159
*/
5260
public expect fun intArrayOf(vararg elements: Int): IntArray
5361

5462
/**
5563
* Returns an array containing the specified characters.
64+
*
65+
* @sample samples.collections.Arrays.Constructors.charArrayOf
5666
*/
5767
public expect fun charArrayOf(vararg elements: Char): CharArray
5868

5969
/**
6070
* Returns an array containing the specified [Short] numbers.
71+
*
72+
* @sample samples.collections.Arrays.Constructors.shortArrayOf
6173
*/
6274
public expect fun shortArrayOf(vararg elements: Short): ShortArray
6375

6476
/**
6577
* Returns an array containing the specified [Byte] numbers.
78+
*
79+
* @sample samples.collections.Arrays.Constructors.byteArrayOf
6680
*/
6781
public expect fun byteArrayOf(vararg elements: Byte): ByteArray
6882

6983
/**
7084
* Returns an array containing the specified boolean values.
85+
*
86+
* @sample samples.collections.Arrays.Constructors.booleanArrayOf
7187
*/
7288
public expect fun booleanArrayOf(vararg elements: Boolean): BooleanArray
7389

0 commit comments

Comments
 (0)