Skip to content

Commit bca98f7

Browse files
committed
test: 💍 Adds integration and more unit tests
Integration tests partially copy the examples, adding assertions there. Unit tests check correctness of #37 and #38 issues.
1 parent 56bc82f commit bca98f7

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

kotlin-spark-api/pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,24 @@
5656
<version>${kotest.version}</version>
5757
<scope>test</scope>
5858
</dependency>
59+
<dependency>
60+
<groupId>io.kotest</groupId>
61+
<artifactId>kotest-runner-console-jvm</artifactId>
62+
<version>${kotest.version}</version>
63+
<scope>test</scope>
64+
</dependency>
5965
<dependency>
6066
<groupId>com.beust</groupId>
6167
<artifactId>klaxon</artifactId>
6268
<version>5.3</version>
6369
<scope>test</scope>
6470
</dependency>
71+
<dependency>
72+
<groupId>ch.tutteli.atrium</groupId>
73+
<artifactId>atrium-fluent-en_GB</artifactId>
74+
<version>0.12.0</version>
75+
<scope>test</scope>
76+
</dependency>
6577
</dependencies>
6678

6779
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*-
2+
* =LICENSE=
3+
* Kotlin Spark API
4+
* ----------
5+
* Copyright (C) 2019 - 2020 JetBrains
6+
* ----------
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =LICENSEEND=
19+
*/
20+
import ch.tutteli.atrium.api.fluent.en_GB.*
21+
import ch.tutteli.atrium.domain.builders.migration.asExpect
22+
import ch.tutteli.atrium.verbs.expect
23+
import io.kotest.core.spec.style.ShouldSpec
24+
import org.jetbrains.spark.api.*
25+
import java.time.LocalDate
26+
27+
class ApiTest : ShouldSpec({
28+
context("integration tests") {
29+
withSpark {
30+
should("collect data classes with doubles correctly") {
31+
32+
val ll1 = LonLat(1.0, 2.0)
33+
val ll2 = LonLat(3.0, 4.0)
34+
val lonlats = dsOf(ll1, ll2).collectAsList()
35+
expect(lonlats).asExpect().contains.inAnyOrder.only.values(ll1, ll2)
36+
37+
}
38+
should("contain all generic primitives with complex schema") {
39+
val primitives = c(1, 1.0, 1.toFloat(), 1.toByte(), LocalDate.now(), true)
40+
val primitives2 = c(2, 2.0, 2.toFloat(), 2.toByte(), LocalDate.now().plusDays(1), false)
41+
val tuples: List<Arity6<Int, Double, Float, Byte, LocalDate, Boolean>> = dsOf(primitives, primitives2).toArray<Arity6<Int, Double, Float, Byte, LocalDate, Boolean>>().toList()
42+
expect(tuples).asExpect().contains.inAnyOrder.only.values(primitives, primitives2)
43+
}
44+
should("handle cached operations") {
45+
val result = dsOf(1, 2, 3, 4, 5)
46+
.map { it to (it + 2) }
47+
.withCached {
48+
showDS()
49+
50+
filter { it.first % 2 == 0 }.showDS()
51+
}
52+
.map { c(it.first, it.second, (it.first + it.second) * 2) }
53+
.collectAsList()
54+
expect(result).asExpect().contains.inOrder.only.values(c(2, 4, 12), c(4, 6, 20))
55+
}
56+
should("handle join operations") {
57+
data class Left(val id: Int, val name: String)
58+
59+
data class Right(val id: Int, val value: Int)
60+
61+
val first = dsOf(Left(1, "a"), Left(2, "b"))
62+
val second = dsOf(Right(1, 100), Right(3, 300))
63+
val result = first
64+
.leftJoin(second, first.col("id").eq(second.col("id")))
65+
.map { c(it.first.id, it.first.name, it.second?.value) }
66+
.collectAsList()
67+
expect(result).asExpect().contains.inOrder.only.values(c(1, "a", 100), c(2, "b", null))
68+
}
69+
should("handle map operations") {
70+
val result = dsOf(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6))
71+
.flatMap { it.iterator() }
72+
.map { it + 4 }
73+
.filter { it < 10 }
74+
.collectAsList()
75+
expect(result).asExpect().contains.inAnyOrder.only.values(5, 6, 7, 8, 7, 8, 9)
76+
}
77+
}
78+
}
79+
})
80+
81+
data class LonLat(val lon: Double, val lat: Double)

kotlin-spark-api/src/test/kotlin/ApiV1KtTest.kt renamed to kotlin-spark-api/src/test/kotlin/TypeInferenceTest.kt

+16-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
* limitations under the License.
1818
* =LICENSEEND=
1919
*/
20+
import ch.tutteli.atrium.api.fluent.en_GB.contains
21+
import ch.tutteli.atrium.api.fluent.en_GB.inOrder
22+
import ch.tutteli.atrium.api.fluent.en_GB.only
23+
import ch.tutteli.atrium.api.fluent.en_GB.values
24+
import ch.tutteli.atrium.domain.builders.migration.asExpect
25+
import ch.tutteli.atrium.verbs.expect
2026
import io.kotest.core.spec.style.ShouldSpec
2127
import io.kotest.inspectors.forOne
2228
import io.kotest.matchers.*
@@ -34,7 +40,7 @@ import kotlin.reflect.typeOf
3440

3541

3642
@OptIn(ExperimentalStdlibApi::class)
37-
class ApiV1KtTest : ShouldSpec({
43+
class TypeInferenceTest : ShouldSpec({
3844
context("org.jetbrains.spark.api.org.jetbrains.spark.api.schema") {
3945
data class Test2<T>(val vala2: T, val para2: Pair<T, String>)
4046
data class Test<T>(val vala: T, val tripl1: Triple<T, Test2<Long>, T>)
@@ -242,6 +248,15 @@ class ApiV1KtTest : ShouldSpec({
242248
elType.value shouldBe "integer"
243249
}
244250
}
251+
context("data class with props in order lon → lat") {
252+
data class Test(val lon: Double, val lat: Double)
253+
254+
val schema = schema(typeOf<Test>())
255+
val struct = Struct.fromJson(schema.prettyJson())!!
256+
should("Not change order of fields") {
257+
expect(struct.fields!!.map { it.name }).asExpect().contains.inOrder.only.values("lon", "lat")
258+
}
259+
}
245260
})
246261

247262
inline fun <reified T> StructField.shouldBeDescribed(name: String) = this should describedStruct<T>(name)

0 commit comments

Comments
 (0)