Skip to content

Commit 6783900

Browse files
committed
Added tests for new DataSchema.equals behavior
1 parent 2378ba3 commit 6783900

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/MatchSchemeTests.kt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
55
import org.jetbrains.kotlinx.dataframe.DataRow
66
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
77
import org.jetbrains.kotlinx.dataframe.api.add
8+
import org.jetbrains.kotlinx.dataframe.api.after
89
import org.jetbrains.kotlinx.dataframe.api.cast
910
import org.jetbrains.kotlinx.dataframe.api.columnOf
1011
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
1112
import org.jetbrains.kotlinx.dataframe.api.generateCode
13+
import org.jetbrains.kotlinx.dataframe.api.move
1214
import org.jetbrains.kotlinx.dataframe.api.schema
15+
import org.jetbrains.kotlinx.dataframe.api.update
16+
import org.jetbrains.kotlinx.dataframe.api.with
1317
import org.jetbrains.kotlinx.dataframe.impl.codeGen.ReplCodeGenerator
1418
import org.jetbrains.kotlinx.dataframe.io.readJsonStr
1519
import org.jetbrains.kotlinx.dataframe.schema.CompareResult.IsDerived
@@ -196,4 +200,48 @@ class MatchSchemeTests {
196200
scheme1.compare(scheme3, STRICT) shouldBe None
197201
scheme3.compare(scheme1, STRICT) shouldBe None
198202
}
203+
204+
@Test
205+
fun `comparison with order`() {
206+
val scheme1 = dataFrameOf(
207+
"a" to columnOf(1, 2, 3, 4),
208+
"b" to columnOf(1.0, 2.0, 3.0, 4.0),
209+
).schema()
210+
211+
val scheme1a = dataFrameOf(
212+
"a" to columnOf(1, 2, 3, 4),
213+
"b" to columnOf(1.0, 2.0, 3.0, 4.0),
214+
).schema()
215+
216+
val scheme2 = dataFrameOf(
217+
"b" to columnOf(1.0, 2.0, 3.0, 4.0),
218+
"a" to columnOf(1, 2, 3, 4),
219+
).schema()
220+
221+
scheme1.compare(scheme1a).matches() shouldBe true
222+
(scheme1 == scheme1a) shouldBe true
223+
224+
scheme1.compare(scheme2).matches() shouldBe true
225+
(scheme1 == scheme2) shouldBe false
226+
}
227+
228+
@Test
229+
fun `nested comparison with order`() {
230+
typed.schema().compare(typed.schema()).matches() shouldBe true
231+
(typed.schema() == typed.schema()) shouldBe true
232+
233+
val movedInGroup = typed.move { pageInfo.resultsPerPage }.after { pageInfo.snippets }
234+
235+
typed.schema().compare(movedInGroup.schema()).matches() shouldBe true
236+
(typed.schema() == movedInGroup.schema()) shouldBe false
237+
238+
val movedInFrameAndGroup = typed
239+
.update { items }.with {
240+
it.move { kind }.after { id }
241+
.move { snippet.position }.after { snippet.info }
242+
}
243+
244+
typed.schema().compare(movedInFrameAndGroup.schema()).matches() shouldBe true
245+
(typed.schema() == movedInFrameAndGroup.schema()) shouldBe false
246+
}
199247
}

0 commit comments

Comments
 (0)