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/structure/v4/content/language_model_dict_content_global_counters.h" 18 19 #include <gtest/gtest.h> 20 21 #include "dictionary/structure/v4/ver4_dict_constants.h" 22 23 namespace latinime { 24 namespace { 25 26 TEST(LanguageModelDictContentGlobalCountersTest, TestUpdateMaxValueOfCounters) { 27 LanguageModelDictContentGlobalCounters globalCounters; 28 29 EXPECT_FALSE(globalCounters.needsToHalveCounters()); 30 globalCounters.updateMaxValueOfCounters(10); 31 EXPECT_FALSE(globalCounters.needsToHalveCounters()); 32 const int count = (1 << (Ver4DictConstants::WORD_COUNT_FIELD_SIZE * CHAR_BIT)) - 1; 33 globalCounters.updateMaxValueOfCounters(count); 34 EXPECT_TRUE(globalCounters.needsToHalveCounters()); 35 globalCounters.halveCounters(); 36 EXPECT_FALSE(globalCounters.needsToHalveCounters()); 37 } 38 39 TEST(LanguageModelDictContentGlobalCountersTest, TestIncrementTotalCount) { 40 LanguageModelDictContentGlobalCounters globalCounters; 41 42 EXPECT_EQ(0, globalCounters.getTotalCount()); 43 globalCounters.incrementTotalCount(); 44 EXPECT_EQ(1, globalCounters.getTotalCount()); 45 for (int i = 1; i < 50; ++i) { 46 globalCounters.incrementTotalCount(); 47 } 48 EXPECT_EQ(50, globalCounters.getTotalCount()); 49 globalCounters.halveCounters(); 50 EXPECT_EQ(25, globalCounters.getTotalCount()); 51 globalCounters.halveCounters(); 52 EXPECT_EQ(12, globalCounters.getTotalCount()); 53 for (int i = 0; i < 4; ++i) { 54 globalCounters.halveCounters(); 55 } 56 EXPECT_EQ(0, globalCounters.getTotalCount()); 57 } 58 59 } // namespace 60 } // namespace latinime 61