forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-array.rb
More file actions
188 lines (165 loc) · 5.48 KB
/
Copy pathtest-array.rb
File metadata and controls
188 lines (165 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
class TestArray < Test::Unit::TestCase
include Helper::Buildable
def test_equal
assert_equal(build_boolean_array([true, false]),
build_boolean_array([true, false]))
end
def test_equal_approx
array1 = build_double_array([1.1, 2.2 + Float::EPSILON * 10])
array2 = build_double_array([1.1, 2.2])
assert do
array1.equal_approx(array2)
end
end
def test_equal_range
array1 = build_int32_array([1, 2, 3, 4, 5])
array2 = build_int32_array([-2, -1, 0, 1, 2, 3, 4, 999])
assert do
array1.equal_range(1, array2, 4, 3)
end
end
def test_is_null
builder = Arrow::BooleanArrayBuilder.new
builder.append_null
builder.append_value(true)
array = builder.finish
assert_equal([true, false],
array.length.times.collect {|i| array.null?(i)})
end
def test_is_valid
builder = Arrow::BooleanArrayBuilder.new
builder.append_null
builder.append_value(true)
array = builder.finish
assert_equal([false, true],
array.length.times.collect {|i| array.valid?(i)})
end
def test_length
builder = Arrow::BooleanArrayBuilder.new
builder.append_value(true)
array = builder.finish
assert_equal(1, array.length)
end
def test_n_nulls
builder = Arrow::BooleanArrayBuilder.new
builder.append_null
builder.append_null
array = builder.finish
assert_equal(2, array.n_nulls)
end
def test_null_bitmap
builder = Arrow::BooleanArrayBuilder.new
builder.append_null
builder.append_value(true)
builder.append_value(false)
builder.append_null
builder.append_value(false)
array = builder.finish
assert_equal(0b10110, array.null_bitmap.data.to_s.unpack("c*")[0])
end
def test_value_data_type
builder = Arrow::BooleanArrayBuilder.new
array = builder.finish
assert_equal(Arrow::BooleanDataType.new, array.value_data_type)
end
def test_value_type
builder = Arrow::BooleanArrayBuilder.new
array = builder.finish
assert_equal(Arrow::Type::BOOLEAN, array.value_type)
end
def test_slice
builder = Arrow::BooleanArrayBuilder.new
builder.append_value(true)
builder.append_value(false)
builder.append_value(true)
array = builder.finish
sub_array = array.slice(1, 2)
assert_equal([false, true],
sub_array.length.times.collect {|i| sub_array.get_value(i)})
end
def test_to_s
assert_equal(<<-CONTENT.chomp, build_boolean_array([true, false, true]).to_s)
[
true,
false,
true
]
CONTENT
end
sub_test_case("#view") do
def test_valid
assert_equal(build_float_array([0.0, 1.5, -2.5, nil]),
build_int32_array([0, 1069547520, -1071644672, nil]).view(Arrow::FloatDataType.new))
end
def test_invalid
message = "[array][view]: Invalid: " +
"Can't view array of type int16 as int8: incompatible layouts"
error = assert_raise(Arrow::Error::Invalid) do
build_int16_array([0, -1, 3]).view(Arrow::Int8DataType.new)
end
assert_equal(message, error.message.lines.first.chomp)
end
end
sub_test_case("#diff_unified") do
def test_no_diff
array = build_string_array(["Start", "Shutdown", "Reboot"])
other_array = build_string_array(["Start", "Shutdown", "Reboot"])
assert_nil(array.diff_unified(other_array))
end
def test_diff
array = build_string_array(["Start", "Shutdown", "Reboot"])
other_array = build_string_array(["Start", "Shutdonw", "Reboot"])
assert_equal(<<-STRING.chomp, array.diff_unified(other_array))
@@ -1, +1 @@
-"Shutdown"
+"Shutdonw"
STRING
end
def test_different_type
array = build_string_array(["Start", "Shutdown", "Reboot"])
other_array = build_int8_array([2, 3, 6, 10])
assert_equal("# Array types differed: string vs int8\n",
array.diff_unified(other_array))
end
end
sub_test_case("#concatenate") do
def test_no_other_arrays
assert_equal(build_int32_array([1, 2, 3]),
build_int32_array([1, 2, 3]).concatenate([]))
end
def test_multiple_other_arrays
a = build_int32_array([1, 2, 3])
b = build_int32_array([4])
c = build_int32_array([5, 6])
assert_equal(build_int32_array([1, 2, 3, 4, 5, 6]),
a.concatenate([b, c]))
end
def test_mixed_type
int32_array = build_int32_array([1, 2, 3])
uint32_array = build_uint32_array([4])
message =
"[array][concatenate]: Invalid: " +
"arrays to be concatenated must be identically typed, " +
"but int32 and uint32 were encountered."
assert_raise(Arrow::Error::Invalid.new(message)) do
int32_array.concatenate([uint32_array])
end
end
end
end