Home | History | Annotate | Download | only in utils
      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 "dictionary/utils/sparse_table.h"
     18 
     19 #include <gtest/gtest.h>
     20 
     21 #include "dictionary/utils/buffer_with_extendable_buffer.h"
     22 
     23 namespace latinime {
     24 namespace {
     25 
     26 TEST(SparseTableTest, TestSetAndGet) {
     27     static const int BLOCK_SIZE = 64;
     28     static const int DATA_SIZE = 4;
     29     BufferWithExtendableBuffer indexTableBuffer(
     30             BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE);
     31     BufferWithExtendableBuffer contentTableBuffer(
     32             BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE);
     33     SparseTable sparseTable(&indexTableBuffer, &contentTableBuffer, BLOCK_SIZE, DATA_SIZE);
     34 
     35     EXPECT_FALSE(sparseTable.contains(10));
     36     EXPECT_TRUE(sparseTable.set(10, 100u));
     37     EXPECT_EQ(100u, sparseTable.get(10));
     38     EXPECT_TRUE(sparseTable.contains(10));
     39     EXPECT_TRUE(sparseTable.contains(BLOCK_SIZE - 1));
     40     EXPECT_FALSE(sparseTable.contains(BLOCK_SIZE));
     41     EXPECT_TRUE(sparseTable.set(11, 101u));
     42     EXPECT_EQ(100u, sparseTable.get(10));
     43     EXPECT_EQ(101u, sparseTable.get(11));
     44 }
     45 
     46 }  // namespace
     47 }  // namespace latinime
     48