aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni
diff options
context:
space:
mode:
Diffstat (limited to 'native/jni')
-rw-r--r--native/jni/NativeFileList.mk4
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table.cpp2
-rw-r--r--native/jni/tests/suggest/core/dicnode/dic_node_pool_test.cpp69
-rw-r--r--native/jni/tests/suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp76
4 files changed, 149 insertions, 2 deletions
diff --git a/native/jni/NativeFileList.mk b/native/jni/NativeFileList.mk
index 018a34d18..082e1e2f9 100644
--- a/native/jni/NativeFileList.mk
+++ b/native/jni/NativeFileList.mk
@@ -121,10 +121,12 @@ LATIN_IME_CORE_SRC_FILES += $(LATIN_IME_CORE_SRC_FILES_BACKWARD_V402)
LATIN_IME_CORE_TEST_FILES := \
defines_test.cpp \
- suggest/core/layout/normal_distribution_2d_test.cpp \
+ suggest/core/dicnode/dic_node_pool_test.cpp \
suggest/core/dictionary/bloom_filter_test.cpp \
+ suggest/core/layout/normal_distribution_2d_test.cpp \
suggest/policyimpl/dictionary/structure/v4/content/language_model_dict_content_test.cpp \
suggest/policyimpl/dictionary/structure/v4/content/probability_entry_test.cpp \
+ suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp \
suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer_test.cpp \
suggest/policyimpl/dictionary/utils/byte_array_utils_test.cpp \
suggest/policyimpl/dictionary/utils/sparse_table_test.cpp \
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table.cpp
index cf238ee5f..2bdf07752 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table.cpp
@@ -34,7 +34,7 @@ int TerminalPositionLookupTable::getTerminalPtNodePosition(const int terminalId)
bool TerminalPositionLookupTable::setTerminalPtNodePosition(
const int terminalId, const int terminalPtNodePos) {
if (terminalId < 0) {
- return NOT_A_DICT_POS;
+ return false;
}
while (terminalId >= mSize) {
// Write new entry.
diff --git a/native/jni/tests/suggest/core/dicnode/dic_node_pool_test.cpp b/native/jni/tests/suggest/core/dicnode/dic_node_pool_test.cpp
new file mode 100644
index 000000000..854efdfe6
--- /dev/null
+++ b/native/jni/tests/suggest/core/dicnode/dic_node_pool_test.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "suggest/core/dicnode/dic_node_pool.h"
+
+#include <gtest/gtest.h>
+
+namespace latinime {
+namespace {
+
+TEST(DicNodePoolTest, TestGet) {
+ static const int CAPACITY = 10;
+ DicNodePool dicNodePool(CAPACITY);
+
+ for (int i = 0; i < CAPACITY; ++i) {
+ EXPECT_NE(nullptr, dicNodePool.getInstance());
+ }
+ EXPECT_EQ(nullptr, dicNodePool.getInstance());
+}
+
+TEST(DicNodePoolTest, TestPlaceBack) {
+ static const int CAPACITY = 1;
+ DicNodePool dicNodePool(CAPACITY);
+
+ DicNode *const dicNode = dicNodePool.getInstance();
+ EXPECT_NE(nullptr, dicNode);
+ EXPECT_EQ(nullptr, dicNodePool.getInstance());
+ dicNodePool.placeBackInstance(dicNode);
+ EXPECT_EQ(dicNode, dicNodePool.getInstance());
+}
+
+TEST(DicNodePoolTest, TestReset) {
+ static const int CAPACITY_SMALL = 2;
+ static const int CAPACITY_LARGE = 10;
+ DicNodePool dicNodePool(CAPACITY_SMALL);
+
+ for (int i = 0; i < CAPACITY_SMALL; ++i) {
+ EXPECT_NE(nullptr, dicNodePool.getInstance());
+ }
+ EXPECT_EQ(nullptr, dicNodePool.getInstance());
+
+ dicNodePool.reset(CAPACITY_LARGE);
+ for (int i = 0; i < CAPACITY_LARGE; ++i) {
+ EXPECT_NE(nullptr, dicNodePool.getInstance());
+ }
+ EXPECT_EQ(nullptr, dicNodePool.getInstance());
+
+ dicNodePool.reset(CAPACITY_SMALL);
+ for (int i = 0; i < CAPACITY_SMALL; ++i) {
+ EXPECT_NE(nullptr, dicNodePool.getInstance());
+ }
+ EXPECT_EQ(nullptr, dicNodePool.getInstance());
+}
+
+} // namespace
+} // namespace latinime
diff --git a/native/jni/tests/suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp b/native/jni/tests/suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp
new file mode 100644
index 000000000..23b9c55f7
--- /dev/null
+++ b/native/jni/tests/suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table.h"
+
+#include <gtest/gtest.h>
+
+#include <vector>
+
+#include "defines.h"
+#include "suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.h"
+
+namespace latinime {
+namespace {
+
+TEST(TerminalPositionLookupTableTest, TestGetFromEmptyTable) {
+ TerminalPositionLookupTable lookupTable;
+
+ EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(0));
+ EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(-1));
+ EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(
+ Ver4DictConstants::NOT_A_TERMINAL_ID));
+}
+
+TEST(TerminalPositionLookupTableTest, TestSetAndGet) {
+ TerminalPositionLookupTable lookupTable;
+
+ EXPECT_TRUE(lookupTable.setTerminalPtNodePosition(10, 100));
+ EXPECT_EQ(100, lookupTable.getTerminalPtNodePosition(10));
+ EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(9));
+ EXPECT_TRUE(lookupTable.setTerminalPtNodePosition(9, 200));
+ EXPECT_EQ(200, lookupTable.getTerminalPtNodePosition(9));
+ EXPECT_TRUE(lookupTable.setTerminalPtNodePosition(10, 300));
+ EXPECT_EQ(300, lookupTable.getTerminalPtNodePosition(10));
+ EXPECT_FALSE(lookupTable.setTerminalPtNodePosition(-1, 400));
+ EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(-1));
+ EXPECT_FALSE(lookupTable.setTerminalPtNodePosition(Ver4DictConstants::NOT_A_TERMINAL_ID, 500));
+ EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(
+ Ver4DictConstants::NOT_A_TERMINAL_ID));
+}
+
+TEST(TerminalPositionLookupTableTest, TestGC) {
+ TerminalPositionLookupTable lookupTable;
+
+ const std::vector<int> terminalIds = { 10, 20, 30 };
+ const std::vector<int> terminalPositions = { 100, 200, 300 };
+
+ for (size_t i = 0; i < terminalIds.size(); ++i) {
+ EXPECT_TRUE(lookupTable.setTerminalPtNodePosition(terminalIds[i], terminalPositions[i]));
+ }
+
+ TerminalPositionLookupTable::TerminalIdMap terminalIdMap;
+ EXPECT_TRUE(lookupTable.runGCTerminalIds(&terminalIdMap));
+
+ for (size_t i = 0; i < terminalIds.size(); ++i) {
+ EXPECT_EQ(static_cast<int>(i), terminalIdMap[terminalIds[i]])
+ << "Terminal id (" << terminalIds[i] << ") should be changed to " << i;
+ EXPECT_EQ(terminalPositions[i], lookupTable.getTerminalPtNodePosition(i));
+ }
+}
+
+} // namespace
+} // namespace latinime