• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "utils/int_array_view.h"
18 
19 #include <gtest/gtest.h>
20 
21 #include <vector>
22 
23 namespace latinime {
24 namespace {
25 
TEST(IntArrayViewTest,TestAccess)26 TEST(IntArrayViewTest, TestAccess) {
27     const std::vector<int> intVector = {3, 2, 1, 0, -1, -2};
28     IntArrayView intArrayView(intVector);
29     EXPECT_EQ(intVector.size(), intArrayView.size());
30     for (int i = 0; i < static_cast<int>(intVector.size()); ++i) {
31         EXPECT_EQ(intVector[i], intArrayView[i]);
32     }
33 }
34 
TEST(IntArrayViewTest,TestIteration)35 TEST(IntArrayViewTest, TestIteration) {
36     const std::vector<int> intVector = {3, 2, 1, 0, -1, -2};
37     IntArrayView intArrayView(intVector);
38     size_t expectedIndex = 0;
39     for (const int element : intArrayView) {
40         EXPECT_EQ(intVector[expectedIndex], element);
41         ++expectedIndex;
42     }
43     EXPECT_EQ(expectedIndex, intArrayView.size());
44 }
45 
TEST(IntArrayViewTest,TestConstructFromArray)46 TEST(IntArrayViewTest, TestConstructFromArray) {
47     const size_t ARRAY_SIZE = 100;
48     int intArray[ARRAY_SIZE];
49     const auto intArrayView = IntArrayView::fromFixedSizeArray(intArray);
50     EXPECT_EQ(ARRAY_SIZE, intArrayView.size());
51 }
52 
TEST(IntArrayViewTest,TestConstructFromObject)53 TEST(IntArrayViewTest, TestConstructFromObject) {
54     const int object = 10;
55     const auto intArrayView = IntArrayView::fromObject(&object);
56     EXPECT_EQ(1, intArrayView.size());
57     EXPECT_EQ(object, intArrayView[0]);
58 }
59 
60 }  // namespace
61 }  // namespace latinime
62