@@ -9,137 +9,151 @@ import java.time.LocalTime
9
9
import java.time.ZoneOffset
10
10
import kotlin.math.absoluteValue
11
11
import kotlin.math.pow
12
+ import kotlin.reflect.full.withNullability
12
13
import kotlin.reflect.typeOf
13
14
14
15
/* *
15
16
* Assert that we have got the same data that was originally saved on example creation.
16
17
*/
17
- internal fun assertEstimations (exampleFrame : AnyFrame ) {
18
+ internal fun assertEstimations (exampleFrame : AnyFrame , nullable : Boolean , withNulls : Boolean ) {
18
19
/* *
19
20
* In [exampleFrame] we get two concatenated batches. To assert the estimations, we should transform frame row number to batch row number
20
21
*/
21
22
fun iBatch (iFrame : Int ): Int {
22
23
val firstBatchSize = 100 ;
23
24
return if (iFrame < firstBatchSize) iFrame else iFrame - firstBatchSize
24
25
}
26
+
27
+ fun expectedNull (rowNumber : Int ): Boolean {
28
+ return (rowNumber + 1 ) % 5 == 0 ;
29
+ }
30
+
31
+ fun assertValueOrNull (rowNumber : Int , actual : Any? , expected : Any ) {
32
+ if (withNulls && expectedNull(rowNumber)) {
33
+ actual shouldBe null
34
+ } else {
35
+ actual shouldBe expected
36
+ }
37
+ }
38
+
25
39
val asciiStringCol = exampleFrame[" asciiString" ] as DataColumn <String ?>
26
- asciiStringCol.type() shouldBe typeOf<String ?>( )
40
+ asciiStringCol.type() shouldBe typeOf<String >().withNullability(nullable )
27
41
asciiStringCol.forEachIndexed { i, element ->
28
- element shouldBe " Test Example ${iBatch(i)} "
42
+ assertValueOrNull(iBatch(i), element, " Test Example ${iBatch(i)} " )
29
43
}
30
44
31
45
val utf8StringCol = exampleFrame[" utf8String" ] as DataColumn <String ?>
32
- utf8StringCol.type() shouldBe typeOf<String ?>( )
46
+ utf8StringCol.type() shouldBe typeOf<String >().withNullability(nullable )
33
47
utf8StringCol.forEachIndexed { i, element ->
34
- element shouldBe " Тестовый пример ${iBatch(i)} "
48
+ assertValueOrNull(iBatch(i), element, " Тестовый пример ${iBatch(i)} " )
35
49
}
36
50
37
51
val largeStringCol = exampleFrame[" largeString" ] as DataColumn <String ?>
38
- largeStringCol.type() shouldBe typeOf<String ?>( )
52
+ largeStringCol.type() shouldBe typeOf<String >().withNullability(nullable )
39
53
largeStringCol.forEachIndexed { i, element ->
40
- element shouldBe " Test Example Should Be Large ${iBatch(i)} "
54
+ assertValueOrNull(iBatch(i), element, " Test Example Should Be Large ${iBatch(i)} " )
41
55
}
42
56
43
57
val booleanCol = exampleFrame[" boolean" ] as DataColumn <Boolean ?>
44
- booleanCol.type() shouldBe typeOf<Boolean ?>( )
58
+ booleanCol.type() shouldBe typeOf<Boolean >().withNullability(nullable )
45
59
booleanCol.forEachIndexed { i, element ->
46
- element shouldBe ( iBatch(i) % 2 == 0 )
60
+ assertValueOrNull(iBatch(i), element, iBatch(i) % 2 == 0 )
47
61
}
48
62
49
63
val byteCol = exampleFrame[" byte" ] as DataColumn <Byte ?>
50
- byteCol.type() shouldBe typeOf<Byte ?>( )
64
+ byteCol.type() shouldBe typeOf<Byte >().withNullability(nullable )
51
65
byteCol.forEachIndexed { i, element ->
52
- element shouldBe (iBatch(i) * 10 ).toByte()
66
+ assertValueOrNull(iBatch(i), element, (iBatch(i) * 10 ).toByte() )
53
67
}
54
68
55
69
val shortCol = exampleFrame[" short" ] as DataColumn <Short ?>
56
- shortCol.type() shouldBe typeOf<Short ?>( )
70
+ shortCol.type() shouldBe typeOf<Short >().withNullability(nullable )
57
71
shortCol.forEachIndexed { i, element ->
58
- element shouldBe (iBatch(i) * 1000 ).toShort()
72
+ assertValueOrNull(iBatch(i), element, (iBatch(i) * 1000 ).toShort() )
59
73
}
60
74
61
75
val intCol = exampleFrame[" int" ] as DataColumn <Int ?>
62
- intCol.type() shouldBe typeOf<Int ?>( )
76
+ intCol.type() shouldBe typeOf<Int >().withNullability(nullable )
63
77
intCol.forEachIndexed { i, element ->
64
- element shouldBe ( iBatch(i) * 100000000 ).toInt( )
78
+ assertValueOrNull(iBatch(i), element, iBatch(i) * 100000000 )
65
79
}
66
80
67
81
val longCol = exampleFrame[" longInt" ] as DataColumn <Long ?>
68
- longCol.type() shouldBe typeOf<Long ?>( )
82
+ longCol.type() shouldBe typeOf<Long >().withNullability(nullable )
69
83
longCol.forEachIndexed { i, element ->
70
- element shouldBe iBatch(i) * 100000000000000000L
84
+ assertValueOrNull(iBatch(i), element, iBatch(i) * 100000000000000000L )
71
85
}
72
86
73
87
val unsignedByteCol = exampleFrame[" unsigned_byte" ] as DataColumn <Short ?>
74
- unsignedByteCol.type() shouldBe typeOf<Short ?>( )
88
+ unsignedByteCol.type() shouldBe typeOf<Short >().withNullability(nullable )
75
89
unsignedByteCol.forEachIndexed { i, element ->
76
- element shouldBe (iBatch(i) * 10 % (Byte .MIN_VALUE .toShort() * 2 ).absoluteValue).toShort()
90
+ assertValueOrNull(iBatch(i), element, (iBatch(i) * 10 % (Byte .MIN_VALUE .toShort() * 2 ).absoluteValue).toShort() )
77
91
}
78
92
79
93
val unsignedShortCol = exampleFrame[" unsigned_short" ] as DataColumn <Int ?>
80
- unsignedShortCol.type() shouldBe typeOf<Int ?>( )
94
+ unsignedShortCol.type() shouldBe typeOf<Int >().withNullability(nullable )
81
95
unsignedShortCol.forEachIndexed { i, element ->
82
- element shouldBe ( iBatch(i) * 1000 % (Short .MIN_VALUE .toInt() * 2 ).absoluteValue)
96
+ assertValueOrNull(iBatch(i), element, iBatch(i) * 1000 % (Short .MIN_VALUE .toInt() * 2 ).absoluteValue)
83
97
}
84
98
85
99
val unsignedIntCol = exampleFrame[" unsigned_int" ] as DataColumn <Long ?>
86
- unsignedIntCol.type() shouldBe typeOf<Long ?>( )
100
+ unsignedIntCol.type() shouldBe typeOf<Long >().withNullability(nullable )
87
101
unsignedIntCol.forEachIndexed { i, element ->
88
- element shouldBe ( iBatch(i).toLong() * 100000000 % (Int .MIN_VALUE .toLong() * 2 ).absoluteValue)
102
+ assertValueOrNull(iBatch(i), element, iBatch(i).toLong() * 100000000 % (Int .MIN_VALUE .toLong() * 2 ).absoluteValue)
89
103
}
90
104
91
105
val unsignedLongIntCol = exampleFrame[" unsigned_longInt" ] as DataColumn <BigInteger ?>
92
- unsignedLongIntCol.type() shouldBe typeOf<BigInteger ?>( )
106
+ unsignedLongIntCol.type() shouldBe typeOf<BigInteger >().withNullability(nullable )
93
107
unsignedLongIntCol.forEachIndexed { i, element ->
94
- element shouldBe ( iBatch(i).toBigInteger() * 100000000000000000L .toBigInteger() % (Long .MIN_VALUE .toBigInteger() * 2 .toBigInteger()).abs())
108
+ assertValueOrNull(iBatch(i), element, iBatch(i).toBigInteger() * 100000000000000000L .toBigInteger() % (Long .MIN_VALUE .toBigInteger() * 2 .toBigInteger()).abs())
95
109
}
96
110
97
111
val floatCol = exampleFrame[" float" ] as DataColumn <Float ?>
98
- floatCol.type() shouldBe typeOf<Float ?>( )
112
+ floatCol.type() shouldBe typeOf<Float >().withNullability(nullable )
99
113
floatCol.forEachIndexed { i, element ->
100
- element shouldBe ( 2.0f .pow(iBatch(i).toFloat()))
114
+ assertValueOrNull(iBatch(i), element, 2.0f .pow(iBatch(i).toFloat()))
101
115
}
102
116
103
117
val doubleCol = exampleFrame[" double" ] as DataColumn <Double ?>
104
- doubleCol.type() shouldBe typeOf<Double ?>( )
118
+ doubleCol.type() shouldBe typeOf<Double >().withNullability(nullable )
105
119
doubleCol.forEachIndexed { i, element ->
106
- element shouldBe ( 2.0 .pow(iBatch(i).toDouble( )))
120
+ assertValueOrNull(iBatch(i), element, 2.0 .pow(iBatch(i)))
107
121
}
108
122
109
123
val dateCol = exampleFrame[" date32" ] as DataColumn <LocalDate ?>
110
- dateCol.type() shouldBe typeOf<LocalDate ?>( )
124
+ dateCol.type() shouldBe typeOf<LocalDate >().withNullability(nullable )
111
125
dateCol.forEachIndexed { i, element ->
112
- element shouldBe LocalDate .ofEpochDay(iBatch(i).toLong() * 30 )
126
+ assertValueOrNull(iBatch(i), element, LocalDate .ofEpochDay(iBatch(i).toLong() * 30 ) )
113
127
}
114
128
115
129
val datetimeCol = exampleFrame[" date64" ] as DataColumn <LocalDateTime ?>
116
- datetimeCol.type() shouldBe typeOf<LocalDateTime ?>( )
130
+ datetimeCol.type() shouldBe typeOf<LocalDateTime >().withNullability(nullable )
117
131
datetimeCol.forEachIndexed { i, element ->
118
- element shouldBe LocalDateTime .ofEpochSecond(iBatch(i).toLong() * 60 * 60 * 24 * 30 , 0 , ZoneOffset .UTC )
132
+ assertValueOrNull(iBatch(i), element, LocalDateTime .ofEpochSecond(iBatch(i).toLong() * 60 * 60 * 24 * 30 , 0 , ZoneOffset .UTC ) )
119
133
}
120
134
121
135
val timeSecCol = exampleFrame[" time32_seconds" ] as DataColumn <LocalTime ?>
122
- timeSecCol.type() shouldBe typeOf<LocalTime ?>( )
136
+ timeSecCol.type() shouldBe typeOf<LocalTime >().withNullability(nullable )
123
137
timeSecCol.forEachIndexed { i, element ->
124
- element shouldBe LocalTime .ofSecondOfDay(iBatch(i).toLong())
138
+ assertValueOrNull(iBatch(i), element, LocalTime .ofSecondOfDay(iBatch(i).toLong() ))
125
139
}
126
140
127
141
val timeMilliCol = exampleFrame[" time32_milli" ] as DataColumn <LocalTime ?>
128
- timeMilliCol.type() shouldBe typeOf<LocalTime ?>( )
142
+ timeMilliCol.type() shouldBe typeOf<LocalTime >().withNullability(nullable )
129
143
timeMilliCol.forEachIndexed { i, element ->
130
- element shouldBe LocalTime .ofNanoOfDay(iBatch(i).toLong() * 1000_000 )
144
+ assertValueOrNull(iBatch(i), element, LocalTime .ofNanoOfDay(iBatch(i).toLong() * 1000_000 ) )
131
145
}
132
146
133
147
val timeMicroCol = exampleFrame[" time64_micro" ] as DataColumn <LocalTime ?>
134
- timeMicroCol.type() shouldBe typeOf<LocalTime ?>( )
148
+ timeMicroCol.type() shouldBe typeOf<LocalTime >().withNullability(nullable )
135
149
timeMicroCol.forEachIndexed { i, element ->
136
- element shouldBe LocalTime .ofNanoOfDay(iBatch(i).toLong() * 1000 )
150
+ assertValueOrNull(iBatch(i), element, LocalTime .ofNanoOfDay(iBatch(i).toLong() * 1000 ) )
137
151
}
138
152
139
153
val timeNanoCol = exampleFrame[" time64_nano" ] as DataColumn <LocalTime ?>
140
- timeNanoCol.type() shouldBe typeOf<LocalTime ?>( )
154
+ timeNanoCol.type() shouldBe typeOf<LocalTime >().withNullability(nullable )
141
155
timeNanoCol.forEachIndexed { i, element ->
142
- element shouldBe LocalTime .ofNanoOfDay(iBatch(i).toLong())
156
+ assertValueOrNull(iBatch(i), element, LocalTime .ofNanoOfDay(iBatch(i).toLong() ))
143
157
}
144
158
145
159
}
0 commit comments