|
| 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) |
0 commit comments