1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements.  See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership.  The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License.  You may obtain a copy of the License at
8#
9#   http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied.  See the License for the
15# specific language governing permissions and limitations
16# under the License.
17
18class TestDictionaryArray < Test::Unit::TestCase
19  include Helper::Buildable
20
21  def setup
22    @index_data_type = Arrow::Int32DataType.new
23    @dictionary = build_string_array(["C", "C++", "Ruby"])
24    @ordered = false
25    @data_type = Arrow::DictionaryDataType.new(@index_data_type,
26                                               @dictionary.value_data_type,
27                                               @ordered)
28  end
29
30  sub_test_case(".new") do
31    def test_new
32      indices = build_int32_array([0, 2, 2, 1, 0])
33      dictionary_array = Arrow::DictionaryArray.new(@data_type,
34                                                    indices,
35                                                    @dictionary)
36      assert_equal(<<-STRING.chomp, dictionary_array.to_s)
37
38-- dictionary:
39  [
40    "C",
41    "C++",
42    "Ruby"
43  ]
44-- indices:
45  [
46    0,
47    2,
48    2,
49    1,
50    0
51  ]
52      STRING
53    end
54  end
55
56  sub_test_case("instance methods") do
57    def setup
58      super
59      @indices = build_int32_array([0, 2, 2, 1, 0])
60      @dictionary_array = Arrow::DictionaryArray.new(@data_type,
61                                                     @indices,
62                                                     @dictionary)
63    end
64
65    def test_indices
66      assert_equal(@indices, @dictionary_array.indices)
67    end
68
69    def test_dictionary
70      assert_equal(@dictionary, @dictionary_array.dictionary)
71    end
72
73    def test_dictionary_data_type
74      assert_equal(@data_type,
75                   @dictionary_array.dictionary_data_type)
76    end
77  end
78end
79