Add missing unsigned array constructors (from size)
#KT-25961 Fixed
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package test.collections
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class UnsignedArraysTest {
|
||||
|
||||
@Test
|
||||
fun ubyteArrayInit() {
|
||||
val zeroArray = UByteArray(42)
|
||||
assertEquals(42, zeroArray.size)
|
||||
for (index in zeroArray.indices) {
|
||||
assertEquals(0u, zeroArray[index])
|
||||
}
|
||||
|
||||
val initArray = UByteArray(42) { it.toUByte() }
|
||||
for (index in initArray.indices) {
|
||||
assertEquals(index.toUByte(), initArray[index])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun ushortArrayInit() {
|
||||
val zeroArray = UShortArray(42)
|
||||
assertEquals(42, zeroArray.size)
|
||||
for (index in zeroArray.indices) {
|
||||
assertEquals(0u, zeroArray[index])
|
||||
}
|
||||
|
||||
val initArray = UShortArray(42) { it.toUShort() }
|
||||
for (index in initArray.indices) {
|
||||
assertEquals(index.toUShort(), initArray[index])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uintArrayInit() {
|
||||
val zeroArray = UIntArray(42)
|
||||
assertEquals(42, zeroArray.size)
|
||||
for (index in zeroArray.indices) {
|
||||
assertEquals(0u, zeroArray[index])
|
||||
}
|
||||
|
||||
val initArray = UIntArray(42) { it.toUInt() }
|
||||
for (index in initArray.indices) {
|
||||
assertEquals(index.toUInt(), initArray[index])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun ulongArrayInit() {
|
||||
val zeroArray = ULongArray(42)
|
||||
assertEquals(42, zeroArray.size)
|
||||
for (index in zeroArray.indices) {
|
||||
assertEquals(0u, zeroArray[index])
|
||||
}
|
||||
|
||||
val initArray = ULongArray(42) { it.toULong() }
|
||||
for (index in initArray.indices) {
|
||||
assertEquals(index.toULong(), initArray[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,9 @@ public inline class UByteArray
|
||||
@PublishedApi
|
||||
internal constructor(private val storage: ByteArray) : Collection<UByte> {
|
||||
|
||||
/** Creates a new array of the specified [size], with all elements initialized to zero. */
|
||||
public constructor(size: Int) : this(ByteArray(size))
|
||||
|
||||
/** Returns the array element at the given [index]. This method can be called using the index operator. */
|
||||
public operator fun get(index: Int): UByte = storage[index].toUByte()
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ public inline class UIntArray
|
||||
@PublishedApi
|
||||
internal constructor(private val storage: IntArray) : Collection<UInt> {
|
||||
|
||||
/** Creates a new array of the specified [size], with all elements initialized to zero. */
|
||||
public constructor(size: Int) : this(IntArray(size))
|
||||
|
||||
/** Returns the array element at the given [index]. This method can be called using the index operator. */
|
||||
public operator fun get(index: Int): UInt = storage[index].toUInt()
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ public inline class ULongArray
|
||||
@PublishedApi
|
||||
internal constructor(private val storage: LongArray) : Collection<ULong> {
|
||||
|
||||
/** Creates a new array of the specified [size], with all elements initialized to zero. */
|
||||
public constructor(size: Int) : this(LongArray(size))
|
||||
|
||||
/** Returns the array element at the given [index]. This method can be called using the index operator. */
|
||||
public operator fun get(index: Int): ULong = storage[index].toULong()
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ public inline class UShortArray
|
||||
@PublishedApi
|
||||
internal constructor(private val storage: ShortArray) : Collection<UShort> {
|
||||
|
||||
/** Creates a new array of the specified [size], with all elements initialized to zero. */
|
||||
public constructor(size: Int) : this(ShortArray(size))
|
||||
|
||||
/** Returns the array element at the given [index]. This method can be called using the index operator. */
|
||||
public operator fun get(index: Int): UShort = storage[index].toUShort()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user