Merge pull request #9695 from kwoyke/JAVA-2140-kotlin
JAVA-2140: Remove Initializing Arrays in Kotlin from the core-kotlin-…
This commit is contained in:
commit
f04855d0c8
|
@ -7,7 +7,6 @@ This module contains articles about core features in the Kotlin language.
|
||||||
- [Infix Functions in Kotlin](https://www.baeldung.com/kotlin-infix-functions)
|
- [Infix Functions in Kotlin](https://www.baeldung.com/kotlin-infix-functions)
|
||||||
- [Lambda Expressions in Kotlin](https://www.baeldung.com/kotlin-lambda-expressions)
|
- [Lambda Expressions in Kotlin](https://www.baeldung.com/kotlin-lambda-expressions)
|
||||||
- [Creating Java static final Equivalents in Kotlin](https://www.baeldung.com/kotlin-java-static-final)
|
- [Creating Java static final Equivalents in Kotlin](https://www.baeldung.com/kotlin-java-static-final)
|
||||||
- [Initializing Arrays in Kotlin](https://www.baeldung.com/kotlin-initialize-array)
|
|
||||||
- [Lazy Initialization in Kotlin](https://www.baeldung.com/kotlin-lazy-initialization)
|
- [Lazy Initialization in Kotlin](https://www.baeldung.com/kotlin-lazy-initialization)
|
||||||
- [Comprehensive Guide to Null Safety in Kotlin](https://www.baeldung.com/kotlin-null-safety)
|
- [Comprehensive Guide to Null Safety in Kotlin](https://www.baeldung.com/kotlin-null-safety)
|
||||||
- [Kotlin Scope Functions](https://www.baeldung.com/kotlin-scope-functions)
|
- [Kotlin Scope Functions](https://www.baeldung.com/kotlin-scope-functions)
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
package com.baeldung.arrayinitialization
|
|
||||||
|
|
||||||
import org.junit.Test
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
class ArrayInitializationTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun givenArrayOfStrings_thenValuesPopulated() {
|
|
||||||
val strings = arrayOf("January", "February", "March")
|
|
||||||
|
|
||||||
assertEquals(3, strings.size)
|
|
||||||
assertEquals("March", strings[2])
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun givenArrayOfIntegers_thenValuesPopulated() {
|
|
||||||
val integers = intArrayOf(1, 2, 3, 4)
|
|
||||||
|
|
||||||
assertEquals(4, integers.size)
|
|
||||||
assertEquals(1, integers[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun givenArrayOfNulls_whenPopulated_thenValuesPresent() {
|
|
||||||
val array = arrayOfNulls<Number>(5)
|
|
||||||
|
|
||||||
for (i in array.indices) {
|
|
||||||
array[i] = i * i
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(16, array[4])
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun whenGeneratorUsed_thenValuesPresent() {
|
|
||||||
val generatedArray = IntArray(10) { i -> i * i }
|
|
||||||
|
|
||||||
assertEquals(81, generatedArray[9])
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun whenStringGenerated_thenValuesPresent() {
|
|
||||||
val generatedStringArray = Array(10) { i -> "Number of index: $i" }
|
|
||||||
|
|
||||||
assertEquals("Number of index: 0", generatedStringArray[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue