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
18#include <vector>
19
20#include <gtest/gtest.h>
21
22#include "arrow/util/stl.h"
23
24namespace arrow {
25namespace internal {
26
27TEST(StlUtilTest, VectorAddRemoveTest) {
28 std::vector<int> values;
29 std::vector<int> result = AddVectorElement(values, 0, 100);
30 EXPECT_EQ(values.size(), 0);
31 EXPECT_EQ(result.size(), 1);
32 EXPECT_EQ(result[0], 100);
33
34 // Add 200 at index 0 and 300 at the end.
35 std::vector<int> result2 = AddVectorElement(result, 0, 200);
36 result2 = AddVectorElement(result2, result2.size(), 300);
37 EXPECT_EQ(result.size(), 1);
38 EXPECT_EQ(result2.size(), 3);
39 EXPECT_EQ(result2[0], 200);
40 EXPECT_EQ(result2[1], 100);
41 EXPECT_EQ(result2[2], 300);
42
43 // Remove 100, 300, 200
44 std::vector<int> result3 = DeleteVectorElement(result2, 1);
45 EXPECT_EQ(result2.size(), 3);
46 EXPECT_EQ(result3.size(), 2);
47 EXPECT_EQ(result3[0], 200);
48 EXPECT_EQ(result3[1], 300);
49
50 result3 = DeleteVectorElement(result3, 1);
51 EXPECT_EQ(result3.size(), 1);
52 EXPECT_EQ(result3[0], 200);
53
54 result3 = DeleteVectorElement(result3, 0);
55 EXPECT_TRUE(result3.empty());
56}
57
58} // namespace internal
59} // namespace arrow
60