BAEL-2648
This commit is contained in:
parent
ad3fe3d536
commit
bad8753fd1
@ -13,4 +13,66 @@
|
|||||||
<relativePath>../parent-kotlin</relativePath>
|
<relativePath>../parent-kotlin</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
<artifactId>junit-platform-runner</artifactId>
|
||||||
|
<version>${junit.platform.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>${assertj.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-test</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>test-compile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>test-compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<jvmTarget>1.8</jvmTarget>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<kotlin.version>1.2.71</kotlin.version>
|
||||||
|
<junit.platform.version>1.1.1</junit.platform.version>
|
||||||
|
<junit.vintage.version>5.2.0</junit.vintage.version>
|
||||||
|
<assertj.version>3.10.0</assertj.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.baeldung.range
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class CharRangeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testCharRange() {
|
||||||
|
assertEquals(listOf('a', 'b', 'c'), ('a'..'c').toList())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testCharDownRange() {
|
||||||
|
assertEquals(listOf('c', 'b', 'a'), ('c'.downTo('a')).toList())
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.baeldung.range
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class FilterTest {
|
||||||
|
|
||||||
|
val r = 1..10
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun filterTest() {
|
||||||
|
assertEquals(listOf(2, 4, 6, 8, 10), r.filter { it -> it % 2 == 0 }.toList())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun mapTest() {
|
||||||
|
assertEquals(listOf(1, 4, 9, 16, 25, 36, 49, 64, 81, 100), r.map { it -> it * it }.toList())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun reduceTest() {
|
||||||
|
assertEquals(55, r.reduce { a, b -> a + b })
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.baeldung.range
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class FirstLastTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testFirst() {
|
||||||
|
assertEquals(1, (1..9).first)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testLast() {
|
||||||
|
assertEquals(9, (1..9).last)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStep() {
|
||||||
|
assertEquals(2, (1..9 step 2).step)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.baeldung.range
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class OtherRangeFunctionsTest {
|
||||||
|
|
||||||
|
val r = 1..20
|
||||||
|
val repeated = listOf(1, 1, 2, 4, 4, 6, 10)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testMin() {
|
||||||
|
assertEquals(1, r.min())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testMax() {
|
||||||
|
assertEquals(20, r.max())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSum() {
|
||||||
|
assertEquals(210, r.sum())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testAverage() {
|
||||||
|
assertEquals(10.5, r.average())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testCount() {
|
||||||
|
assertEquals(20, r.count())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testDistinct() {
|
||||||
|
assertEquals(listOf(1, 2, 4, 6, 10), repeated.distinct())
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.baeldung.range
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class RangeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testRange() {
|
||||||
|
assertEquals(listOf(1,2,3), (1.rangeTo(3).toList()))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testDownTo(){
|
||||||
|
assertEquals(listOf(3,2,1), (3.downTo(1).toList()))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testUntil(){
|
||||||
|
assertEquals(listOf(1,2), (1.until(3).toList()))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.baeldung.range
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class ReverseRangeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun reversedTest() {
|
||||||
|
assertEquals(listOf(9, 6, 3), (1..9).reversed().step(3).toList())
|
||||||
|
}
|
||||||
|
}
|
17
core-kotlin-2/src/test/kotlin/com/baeldung/range/StepTest.kt
Normal file
17
core-kotlin-2/src/test/kotlin/com/baeldung/range/StepTest.kt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.baeldung.range
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class StepTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStep() {
|
||||||
|
assertEquals(listOf(1, 3, 5, 7, 9), (1..9 step 2).toList())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStepDown() {
|
||||||
|
assertEquals(listOf(9, 7, 5, 3, 1), (9 downTo 1 step 2).toList())
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.baeldung.range
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class UntilRangeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testUntil() {
|
||||||
|
assertEquals(listOf(1, 2, 3, 4), (1 until 5).toList())
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user