language_model_dict_content_test.cpp revision 08894842662eff666a713a7f4deb79204a322f8c
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 "suggest/policyimpl/dictionary/structure/v4/content/language_model_dict_content.h" 18 19#include <gtest/gtest.h> 20 21#include "utils/int_array_view.h" 22 23namespace latinime { 24namespace { 25 26TEST(LanguageModelDictContentTest, TestUnigramProbability) { 27 LanguageModelDictContent LanguageModelDictContent(false /* useHistoricalInfo */); 28 29 const int flag = 0xFF; 30 const int probability = 10; 31 const int wordId = 100; 32 const ProbabilityEntry probabilityEntry(flag, probability); 33 LanguageModelDictContent.setProbabilityEntry(WordIdArrayView(), wordId, &probabilityEntry); 34 const ProbabilityEntry entry = 35 LanguageModelDictContent.getProbabilityEntry(WordIdArrayView(), wordId); 36 EXPECT_EQ(flag, entry.getFlags()); 37 EXPECT_EQ(probability, entry.getProbability()); 38} 39 40TEST(LanguageModelDictContentTest, TestUnigramProbabilityWithHistoricalInfo) { 41 LanguageModelDictContent LanguageModelDictContent(true /* useHistoricalInfo */); 42 43 const int flag = 0xF0; 44 const int timestamp = 0x3FFFFFFF; 45 const int level = 3; 46 const int count = 10; 47 const int wordId = 100; 48 const HistoricalInfo historicalInfo(timestamp, level, count); 49 const ProbabilityEntry probabilityEntry(flag, NOT_A_PROBABILITY, &historicalInfo); 50 LanguageModelDictContent.setProbabilityEntry(WordIdArrayView(), wordId, &probabilityEntry); 51 const ProbabilityEntry entry = 52 LanguageModelDictContent.getProbabilityEntry(WordIdArrayView(), wordId); 53 EXPECT_EQ(flag, entry.getFlags()); 54 EXPECT_EQ(timestamp, entry.getHistoricalInfo()->getTimeStamp()); 55 EXPECT_EQ(level, entry.getHistoricalInfo()->getLevel()); 56 EXPECT_EQ(count, entry.getHistoricalInfo()->getCount()); 57} 58 59} // namespace 60} // namespace latinime 61