Skip to content

Commit a22f863

Browse files
committed
new tests taking sortWithConstructors into account
1 parent 89ddd20 commit a22f863

File tree

6 files changed

+48
-26
lines changed

6 files changed

+48
-26
lines changed

core/generated-sources/src/test/java/org/jetbrains/kotlinx/dataframe/api/JavaPojo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class JavaPojo {
99

1010
public JavaPojo() {}
1111

12-
public JavaPojo(int a, String b) {
12+
public JavaPojo(String b, int a) {
1313
this.a = a;
1414
this.b = b;
1515
}
@@ -51,8 +51,8 @@ public int hashCode() {
5151
@Override
5252
public String toString() {
5353
return "TestPojo{" +
54-
"a=" + a +
55-
", b='" + b + '\'' +
56-
'}';
54+
"a=" + a +
55+
", b='" + b + '\'' +
56+
'}';
5757
}
5858
}

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/Utils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ fun <T : DataFrame<*>> T.alsoDebug(println: String? = null, rowsLimit: Int = 20)
2424
print(borders = true, title = true, columnTypes = true, valueLimit = -1, rowsLimit = rowsLimit)
2525
schema().print()
2626
}
27-

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class CreateDataFrameTests {
193193
fun treatErasedGenericAsAny() {
194194
class IncompatibleVersionErrorData<T>(val expected: T, val actual: T)
195195
class DeserializedContainerSource(val incompatibility: IncompatibleVersionErrorData<*>)
196+
196197
val functions = listOf(DeserializedContainerSource(IncompatibleVersionErrorData(1, 2)))
197198

198199
val df = functions.toDataFrame(maxDepth = 2)
@@ -320,11 +321,19 @@ class CreateDataFrameTests {
320321

321322
constructor()
322323

323-
constructor(a: Int, b: String) {
324+
constructor(b: String, a: Int) {
324325
this.a = a
325326
this.b = b
326327
}
327328

329+
constructor(b: String) {
330+
this.b = b
331+
}
332+
333+
constructor(a: Int) {
334+
this.a = a
335+
}
336+
328337
fun getA(): Int = a
329338
fun setA(a: Int) {
330339
this.a = a
@@ -358,18 +367,21 @@ class CreateDataFrameTests {
358367

359368
@Test
360369
fun `convert POJO to DF`() {
361-
listOf(KotlinPojo(1, "a")).toDataFrame() shouldBe dataFrameOf("a", "b")(1, "a")
362-
listOf(JavaPojo(1, "a")).toDataFrame() shouldBe dataFrameOf("a", "b")(1, "a")
370+
// even though the names b, a, follow the constructor order
371+
listOf(KotlinPojo("bb", 1)).toDataFrame() shouldBe dataFrameOf("b", "a")("bb", 1)
372+
373+
// cannot read java constructor parameter names with reflection, so sort lexigographically
374+
listOf(JavaPojo("bb", 1)).toDataFrame() shouldBe dataFrameOf("a", "b")(1, "bb")
363375

364-
listOf(KotlinPojo(1, "a")).toDataFrame { properties(KotlinPojo::getA) } shouldBe dataFrameOf("a")(1)
365-
listOf(KotlinPojo(1, "a")).toDataFrame { properties(KotlinPojo::getB) } shouldBe dataFrameOf("b")("a")
376+
listOf(KotlinPojo("bb", 1)).toDataFrame { properties(KotlinPojo::getA) } shouldBe dataFrameOf("a")(1)
377+
listOf(KotlinPojo("bb", 1)).toDataFrame { properties(KotlinPojo::getB) } shouldBe dataFrameOf("b")("bb")
366378

367-
listOf(JavaPojo(1, "a")).toDataFrame {
379+
listOf(JavaPojo("bb", 1)).toDataFrame {
368380
properties(JavaPojo::getA)
369381
} shouldBe dataFrameOf("a")(1)
370382

371-
listOf(JavaPojo(1, "a")).toDataFrame {
383+
listOf(JavaPojo("bb", 1)).toDataFrame {
372384
properties(JavaPojo::getB)
373-
} shouldBe dataFrameOf("b")("a")
385+
} shouldBe dataFrameOf("b")("bb")
374386
}
375387
}

core/src/test/java/org/jetbrains/kotlinx/dataframe/api/JavaPojo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class JavaPojo {
99

1010
public JavaPojo() {}
1111

12-
public JavaPojo(int a, String b) {
12+
public JavaPojo(String b, int a) {
1313
this.a = a;
1414
this.b = b;
1515
}
@@ -51,8 +51,8 @@ public int hashCode() {
5151
@Override
5252
public String toString() {
5353
return "TestPojo{" +
54-
"a=" + a +
55-
", b='" + b + '\'' +
56-
'}';
54+
"a=" + a +
55+
", b='" + b + '\'' +
56+
'}';
5757
}
5858
}

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/Utils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ fun <T : DataFrame<*>> T.alsoDebug(println: String? = null, rowsLimit: Int = 20)
2424
print(borders = true, title = true, columnTypes = true, valueLimit = -1, rowsLimit = rowsLimit)
2525
schema().print()
2626
}
27-

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class CreateDataFrameTests {
193193
fun treatErasedGenericAsAny() {
194194
class IncompatibleVersionErrorData<T>(val expected: T, val actual: T)
195195
class DeserializedContainerSource(val incompatibility: IncompatibleVersionErrorData<*>)
196+
196197
val functions = listOf(DeserializedContainerSource(IncompatibleVersionErrorData(1, 2)))
197198

198199
val df = functions.toDataFrame(maxDepth = 2)
@@ -320,11 +321,19 @@ class CreateDataFrameTests {
320321

321322
constructor()
322323

323-
constructor(a: Int, b: String) {
324+
constructor(b: String, a: Int) {
324325
this.a = a
325326
this.b = b
326327
}
327328

329+
constructor(b: String) {
330+
this.b = b
331+
}
332+
333+
constructor(a: Int) {
334+
this.a = a
335+
}
336+
328337
fun getA(): Int = a
329338
fun setA(a: Int) {
330339
this.a = a
@@ -358,18 +367,21 @@ class CreateDataFrameTests {
358367

359368
@Test
360369
fun `convert POJO to DF`() {
361-
listOf(KotlinPojo(1, "a")).toDataFrame() shouldBe dataFrameOf("a", "b")(1, "a")
362-
listOf(JavaPojo(1, "a")).toDataFrame() shouldBe dataFrameOf("a", "b")(1, "a")
370+
// even though the names b, a, follow the constructor order
371+
listOf(KotlinPojo("bb", 1)).toDataFrame() shouldBe dataFrameOf("b", "a")("bb", 1)
372+
373+
// cannot read java constructor parameter names with reflection, so sort lexigographically
374+
listOf(JavaPojo("bb", 1)).toDataFrame() shouldBe dataFrameOf("a", "b")(1, "bb")
363375

364-
listOf(KotlinPojo(1, "a")).toDataFrame { properties(KotlinPojo::getA) } shouldBe dataFrameOf("a")(1)
365-
listOf(KotlinPojo(1, "a")).toDataFrame { properties(KotlinPojo::getB) } shouldBe dataFrameOf("b")("a")
376+
listOf(KotlinPojo("bb", 1)).toDataFrame { properties(KotlinPojo::getA) } shouldBe dataFrameOf("a")(1)
377+
listOf(KotlinPojo("bb", 1)).toDataFrame { properties(KotlinPojo::getB) } shouldBe dataFrameOf("b")("bb")
366378

367-
listOf(JavaPojo(1, "a")).toDataFrame {
379+
listOf(JavaPojo("bb", 1)).toDataFrame {
368380
properties(JavaPojo::getA)
369381
} shouldBe dataFrameOf("a")(1)
370382

371-
listOf(JavaPojo(1, "a")).toDataFrame {
383+
listOf(JavaPojo("bb", 1)).toDataFrame {
372384
properties(JavaPojo::getB)
373-
} shouldBe dataFrameOf("b")("a")
385+
} shouldBe dataFrameOf("b")("bb")
374386
}
375387
}

0 commit comments

Comments
 (0)