int_array_view_test.cpp revision 03dc44f543795040a092723085fac1209103b7bd
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
23namespace latinime {
24namespace {
25
26TEST(MemoryViewTest, TestAccess) {
27    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
35TEST(MemoryViewTest, TestIteration) {
36    std::vector<int> intVector = {3, 2, 1, 0, -1, -2};
37    IntArrayView intArrayView(intVector);
38    std::set<int> intSet(intVector.begin(), intVector.end());
39    for (const int i : intArrayView) {
40        EXPECT_TRUE(intSet.count(i) > 0);
41        intSet.erase(i);
42    }
43    EXPECT_TRUE(intSet.empty());
44}
45
46}  // namespace
47}  // namespace latinime
48