probability_entry_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/probability_entry.h" 18 19#include <gtest/gtest.h> 20 21#include "defines.h" 22 23namespace latinime { 24namespace { 25 26TEST(ProbabilityEntryTest, TestEncodeDecode) { 27 const int flag = 0xFF; 28 const int probability = 10; 29 30 const ProbabilityEntry entry(flag, probability); 31 const uint64_t encodedEntry = entry.encode(false /* hasHistoricalInfo */); 32 const ProbabilityEntry decodedEntry = 33 ProbabilityEntry::decode(encodedEntry, false /* hasHistoricalInfo */); 34 EXPECT_EQ(0xFF0Aull, encodedEntry); 35 EXPECT_EQ(flag, decodedEntry.getFlags()); 36 EXPECT_EQ(probability, decodedEntry.getProbability()); 37} 38 39TEST(ProbabilityEntryTest, TestEncodeDecodeWithHistoricalInfo) { 40 const int flag = 0xF0; 41 const int timestamp = 0x3FFFFFFF; 42 const int level = 3; 43 const int count = 10; 44 45 const HistoricalInfo historicalInfo(timestamp, level, count); 46 const ProbabilityEntry entry(flag, NOT_A_PROBABILITY, &historicalInfo); 47 48 const uint64_t encodedEntry = entry.encode(true /* hasHistoricalInfo */); 49 EXPECT_EQ(0xF03FFFFFFF030Aull, encodedEntry); 50 const ProbabilityEntry decodedEntry = 51 ProbabilityEntry::decode(encodedEntry, true /* hasHistoricalInfo */); 52 53 EXPECT_EQ(flag, decodedEntry.getFlags()); 54 EXPECT_EQ(timestamp, decodedEntry.getHistoricalInfo()->getTimeStamp()); 55 EXPECT_EQ(level, decodedEntry.getHistoricalInfo()->getLevel()); 56 EXPECT_EQ(count, decodedEntry.getHistoricalInfo()->getCount()); 57} 58 59} // namespace 60} // namespace latinime 61