diff --git a/app/src/keyboards/java/be/scri/helpers/AutocompletionHandler.kt b/app/src/keyboards/java/be/scri/helpers/AutocompletionHandler.kt index b8475281..c4214600 100644 --- a/app/src/keyboards/java/be/scri/helpers/AutocompletionHandler.kt +++ b/app/src/keyboards/java/be/scri/helpers/AutocompletionHandler.kt @@ -46,7 +46,8 @@ class AutocompletionHandler( return@Runnable } - val completions = ime.getAutocompletions(currentWord, limit = 5) + val previousWord = ime.getPreviousWordBeforeCursor() + val completions = ime.getAutocompletions(currentWord, previousWord, limit = 5) if (completions.isNotEmpty()) { ime.updateAutocompleteSuggestions(completions) diff --git a/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt b/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt index 1b8b6afb..3b6a18c6 100644 --- a/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt +++ b/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt @@ -1112,10 +1112,11 @@ abstract class GeneralKeyboardIME( */ fun getAutocompletions( prefix: String, + previousWord: String? = null, limit: Int = 3, ): List { if (this::nativeSuggestionEngine.isInitialized) { - val nativeCompletions = nativeSuggestionEngine.getAutocompletions(language, prefix, limit) + val nativeCompletions = nativeSuggestionEngine.getAutocompletions(language, prefix, previousWord, limit) if (nativeCompletions.isNotEmpty()) { return nativeCompletions } @@ -1156,6 +1157,18 @@ abstract class GeneralKeyboardIME( */ fun getLastWordBeforeCursor(): String? = getText()?.trim()?.split("\\s+".toRegex())?.lastOrNull() + /** + * Extracts the word immediately before the one currently being composed, i.e. the last + * completed word preceding the in-progress word at the cursor. Used to give the autocomplete + * engine sentence context so it can bias completions instead of scoring the prefix in isolation. + * + * @return The previous completed word as a [String], or null if there isn't one. + */ + fun getPreviousWordBeforeCursor(): String? { + val words = getText()?.trim()?.split("\\s+".toRegex()) ?: return null + return words.getOrNull(words.size - 2) + } + /** * Retrieves the text immediately preceding the cursor. * diff --git a/app/src/main/assets/dicts/main_bg.dict b/app/src/main/assets/dicts/main_bg.dict deleted file mode 100644 index b39d7e3f..00000000 Binary files a/app/src/main/assets/dicts/main_bg.dict and /dev/null differ diff --git a/app/src/main/assets/dicts/main_bn.dict b/app/src/main/assets/dicts/main_bn.dict deleted file mode 100644 index c0329fff..00000000 Binary files a/app/src/main/assets/dicts/main_bn.dict and /dev/null differ diff --git a/app/src/main/assets/dicts/main_de.dict b/app/src/main/assets/dicts/main_de.dict index 58aecf9e..b3c8c8fb 100644 Binary files a/app/src/main/assets/dicts/main_de.dict and b/app/src/main/assets/dicts/main_de.dict differ diff --git a/app/src/main/assets/dicts/main_el.dict b/app/src/main/assets/dicts/main_el.dict deleted file mode 100644 index fb8bbcee..00000000 Binary files a/app/src/main/assets/dicts/main_el.dict and /dev/null differ diff --git a/app/src/main/assets/dicts/main_en-GB.dict b/app/src/main/assets/dicts/main_en-GB.dict deleted file mode 100644 index 77145c7d..00000000 Binary files a/app/src/main/assets/dicts/main_en-GB.dict and /dev/null differ diff --git a/app/src/main/assets/dicts/main_en-US.dict b/app/src/main/assets/dicts/main_en-US.dict index 081a8c8c..ba56d826 100644 Binary files a/app/src/main/assets/dicts/main_en-US.dict and b/app/src/main/assets/dicts/main_en-US.dict differ diff --git a/app/src/main/assets/dicts/main_es.dict b/app/src/main/assets/dicts/main_es.dict index 076d5aa8..3e4a10ee 100644 Binary files a/app/src/main/assets/dicts/main_es.dict and b/app/src/main/assets/dicts/main_es.dict differ diff --git a/app/src/main/assets/dicts/main_fr.dict b/app/src/main/assets/dicts/main_fr.dict index 0e868609..25744c28 100644 Binary files a/app/src/main/assets/dicts/main_fr.dict and b/app/src/main/assets/dicts/main_fr.dict differ diff --git a/app/src/main/assets/dicts/main_hu.dict b/app/src/main/assets/dicts/main_hu.dict deleted file mode 100644 index 0b05b265..00000000 Binary files a/app/src/main/assets/dicts/main_hu.dict and /dev/null differ diff --git a/app/src/main/assets/dicts/main_it.dict b/app/src/main/assets/dicts/main_it.dict index 609ef13b..65edbed5 100644 Binary files a/app/src/main/assets/dicts/main_it.dict and b/app/src/main/assets/dicts/main_it.dict differ diff --git a/app/src/main/assets/dicts/main_nl.dict b/app/src/main/assets/dicts/main_nl.dict deleted file mode 100644 index 4d031d0c..00000000 Binary files a/app/src/main/assets/dicts/main_nl.dict and /dev/null differ diff --git a/app/src/main/assets/dicts/main_pl.dict b/app/src/main/assets/dicts/main_pl.dict deleted file mode 100644 index f55af662..00000000 Binary files a/app/src/main/assets/dicts/main_pl.dict and /dev/null differ diff --git a/app/src/main/assets/dicts/main_pt-BR.dict b/app/src/main/assets/dicts/main_pt-BR.dict index c3386518..091a1195 100644 Binary files a/app/src/main/assets/dicts/main_pt-BR.dict and b/app/src/main/assets/dicts/main_pt-BR.dict differ diff --git a/app/src/main/assets/dicts/main_pt-PT.dict b/app/src/main/assets/dicts/main_pt-PT.dict deleted file mode 100644 index a685e35d..00000000 Binary files a/app/src/main/assets/dicts/main_pt-PT.dict and /dev/null differ diff --git a/app/src/main/assets/dicts/main_ro.dict b/app/src/main/assets/dicts/main_ro.dict deleted file mode 100644 index 1f69a653..00000000 Binary files a/app/src/main/assets/dicts/main_ro.dict and /dev/null differ diff --git a/app/src/main/assets/dicts/main_ru.dict b/app/src/main/assets/dicts/main_ru.dict index f24552dd..f022ca16 100644 Binary files a/app/src/main/assets/dicts/main_ru.dict and b/app/src/main/assets/dicts/main_ru.dict differ diff --git a/app/src/main/assets/dicts/main_sv.dict b/app/src/main/assets/dicts/main_sv.dict index 0e7fdda6..dc74757d 100644 Binary files a/app/src/main/assets/dicts/main_sv.dict and b/app/src/main/assets/dicts/main_sv.dict differ diff --git a/app/src/main/assets/dicts/main_tr.dict b/app/src/main/assets/dicts/main_tr.dict deleted file mode 100644 index 3951fa23..00000000 Binary files a/app/src/main/assets/dicts/main_tr.dict and /dev/null differ diff --git a/app/src/main/java/be/scri/helpers/NativeSuggestionEngine.kt b/app/src/main/java/be/scri/helpers/NativeSuggestionEngine.kt index cfb3778c..0059f8e2 100644 --- a/app/src/main/java/be/scri/helpers/NativeSuggestionEngine.kt +++ b/app/src/main/java/be/scri/helpers/NativeSuggestionEngine.kt @@ -116,6 +116,7 @@ class NativeSuggestionEngine(private val context: Context) { fun getAutocompletions( language: String, prefix: String, + previousWord: String? = null, limit: Int = 3 ): List { val dict = getDictionary(language) ?: return emptyList() @@ -123,18 +124,30 @@ class NativeSuggestionEngine(private val context: Context) { return try { val composedData = ComposedData.createForWord(prefix) + val ngramContext = + if (previousWord.isNullOrBlank()) { + NgramContext.EMPTY_PREV_WORDS_INFO + } else { + NgramContext(NgramContext.WordInfo(previousWord)) + } val suggestions = dict.getSuggestions( composedData, - NgramContext.EMPTY_PREV_WORDS_INFO, + ngramContext, dummyProximityInfo.nativeProximityInfo, // proximityInfoHandle - SettingsValuesForSuggestion(false, false), + SettingsValuesForSuggestion(true, false), // blockPotentiallyOffensive, spaceAwareGesture 1, // sessionId 1.0f, // weightForLocale null // inOutWeightOfLangModelVsSpatialModel ) + val isCapitalized = StringUtils.isWordCapitalized(prefix) suggestions?.map { it.mWord } - ?.filter { it.isNotBlank() && it.lowercase(Locale.ROOT) != prefix.lowercase(Locale.ROOT) } + ?.filter { + it.isNotBlank() && + it.startsWith(prefix, ignoreCase = true) && + it.lowercase(Locale.ROOT) != prefix.lowercase(Locale.ROOT) + } + ?.map { if (isCapitalized) it.replaceFirstChar { c -> c.uppercaseChar() } else it } ?.take(limit) ?: emptyList() } catch (e: Exception) { @@ -162,14 +175,14 @@ class NativeSuggestionEngine(private val context: Context) { composedData, ngramContext, dummyProximityInfo.nativeProximityInfo, // proximityInfoHandle - SettingsValuesForSuggestion(false, false), + SettingsValuesForSuggestion(true, false), // blockPotentiallyOffensive, spaceAwareGesture 1, // sessionId 1.0f, // weightForLocale null // inOutWeightOfLangModelVsSpatialModel ) suggestions?.map { it.mWord } - ?.filter { it.isNotBlank() } + ?.filter { it.isNotBlank() && it.lowercase(Locale.ROOT) != lastWord.lowercase(Locale.ROOT) } ?.take(limit) ?: emptyList() } catch (e: Exception) { diff --git a/app/src/main/java/be/scri/latin/common/ComposedData.kt b/app/src/main/java/be/scri/latin/common/ComposedData.kt index d0d1e416..3a8f9d77 100644 --- a/app/src/main/java/be/scri/latin/common/ComposedData.kt +++ b/app/src/main/java/be/scri/latin/common/ComposedData.kt @@ -8,8 +8,6 @@ */ package be.scri.latin.common -import kotlin.random.Random - /** An immutable class that encapsulates a snapshot of word composition data. */ class ComposedData( @JvmField val mInputPointers: InputPointers, @@ -48,10 +46,12 @@ class ComposedData( companion object { fun createForWord(word: String): ComposedData { val codePoints = StringUtils.toCodePointArray(word) - val coordinates = CoordinateUtils.newCoordinateArray(codePoints.size) - for (i in codePoints.indices) { - CoordinateUtils.setXYInArray(coordinates, i, Random.nextBits(2), Random.nextBits(2)) - } + val coordinates = + CoordinateUtils.newCoordinateArray( + codePoints.size, + Constants.NOT_A_COORDINATE, + Constants.NOT_A_COORDINATE, + ) val pointers = InputPointers(codePoints.size).apply { for (i in codePoints.indices) { addPointer(CoordinateUtils.xFromArray(coordinates, i), CoordinateUtils.yFromArray(coordinates, i), 0, 0) diff --git a/app/src/main/jni/Android.bp b/app/src/main/jni/Android.bp deleted file mode 100644 index 5649fc1e..00000000 --- a/app/src/main/jni/Android.bp +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright (C) 2013 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. - -filegroup { - name: "LATIN_IME_CORE_SRC_FILES", - srcs: [ - "src/dictionary/header/header_policy.cpp", - "src/dictionary/header/header_read_write_utils.cpp", - "src/dictionary/property/ngram_context.cpp", - "src/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp", - "src/dictionary/structure/pt_common/bigram/bigram_list_read_write_utils.cpp", - "src/dictionary/structure/pt_common/dynamic_pt_gc_event_listeners.cpp", - "src/dictionary/structure/pt_common/dynamic_pt_reading_helper.cpp", - "src/dictionary/structure/pt_common/dynamic_pt_reading_utils.cpp", - "src/dictionary/structure/pt_common/dynamic_pt_updating_helper.cpp", - "src/dictionary/structure/pt_common/dynamic_pt_writing_utils.cpp", - "src/dictionary/structure/pt_common/patricia_trie_reading_utils.cpp", - "src/dictionary/structure/pt_common/shortcut/shortcut_list_reading_utils.cpp", - "src/dictionary/structure/v2/patricia_trie_policy.cpp", - "src/dictionary/structure/v2/ver2_patricia_trie_node_reader.cpp", - "src/dictionary/structure/v2/ver2_pt_node_array_reader.cpp", - "src/dictionary/structure/v4/ver4_dict_buffers.cpp", - "src/dictionary/structure/v4/ver4_dict_constants.cpp", - "src/dictionary/structure/v4/ver4_patricia_trie_node_reader.cpp", - "src/dictionary/structure/v4/ver4_patricia_trie_node_writer.cpp", - "src/dictionary/structure/v4/ver4_patricia_trie_policy.cpp", - "src/dictionary/structure/v4/ver4_patricia_trie_reading_utils.cpp", - "src/dictionary/structure/v4/ver4_patricia_trie_writing_helper.cpp", - "src/dictionary/structure/v4/ver4_pt_node_array_reader.cpp", - "src/dictionary/structure/v4/content/dynamic_language_model_probability_utils.cpp", - "src/dictionary/structure/v4/content/language_model_dict_content.cpp", - "src/dictionary/structure/v4/content/language_model_dict_content_global_counters.cpp", - "src/dictionary/structure/v4/content/shortcut_dict_content.cpp", - "src/dictionary/structure/v4/content/sparse_table_dict_content.cpp", - "src/dictionary/structure/v4/content/terminal_position_lookup_table.cpp", - "src/dictionary/utils/buffer_with_extendable_buffer.cpp", - "src/dictionary/utils/byte_array_utils.cpp", - "src/dictionary/utils/dict_file_writing_utils.cpp", - "src/dictionary/utils/file_utils.cpp", - "src/dictionary/utils/forgetting_curve_utils.cpp", - "src/dictionary/utils/format_utils.cpp", - "src/dictionary/utils/mmapped_buffer.cpp", - "src/dictionary/utils/multi_bigram_map.cpp", - "src/dictionary/utils/probability_utils.cpp", - "src/dictionary/utils/sparse_table.cpp", - "src/dictionary/utils/trie_map.cpp", - "src/suggest/core/suggest.cpp", - "src/suggest/core/dicnode/dic_node.cpp", - "src/suggest/core/dicnode/dic_node_utils.cpp", - "src/suggest/core/dicnode/dic_nodes_cache.cpp", - "src/suggest/core/dictionary/dictionary.cpp", - "src/suggest/core/dictionary/dictionary_utils.cpp", - "src/suggest/core/dictionary/digraph_utils.cpp", - "src/suggest/core/dictionary/error_type_utils.cpp", - "src/suggest/core/layout/additional_proximity_chars.cpp", - "src/suggest/core/layout/proximity_info.cpp", - "src/suggest/core/layout/proximity_info_params.cpp", - "src/suggest/core/layout/proximity_info_state.cpp", - "src/suggest/core/layout/proximity_info_state_utils.cpp", - "src/suggest/core/policy/weighting.cpp", - "src/suggest/core/session/dic_traverse_session.cpp", - "src/suggest/core/result/suggestion_results.cpp", - "src/suggest/core/result/suggestions_output_utils.cpp", - "src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp", - "src/suggest/policyimpl/typing/scoring_params.cpp", - "src/suggest/policyimpl/typing/typing_scoring.cpp", - "src/suggest/policyimpl/typing/typing_suggest_policy.cpp", - "src/suggest/policyimpl/typing/typing_traversal.cpp", - "src/suggest/policyimpl/typing/typing_weighting.cpp", - "src/utils/autocorrection_threshold_utils.cpp", - "src/utils/char_utils.cpp", - "src/utils/jni_data_utils.cpp", - "src/utils/log_utils.cpp", - "src/utils/time_keeper.cpp", - - // BACKWARD_V402 - "src/dictionary/structure/backward/v402/ver4_dict_buffers.cpp", - "src/dictionary/structure/backward/v402/ver4_dict_constants.cpp", - "src/dictionary/structure/backward/v402/ver4_patricia_trie_node_reader.cpp", - "src/dictionary/structure/backward/v402/ver4_patricia_trie_node_writer.cpp", - "src/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp", - "src/dictionary/structure/backward/v402/ver4_patricia_trie_reading_utils.cpp", - "src/dictionary/structure/backward/v402/ver4_patricia_trie_writing_helper.cpp", - "src/dictionary/structure/backward/v402/ver4_pt_node_array_reader.cpp", - "src/dictionary/structure/backward/v402/content/bigram_dict_content.cpp", - "src/dictionary/structure/backward/v402/content/probability_dict_content.cpp", - "src/dictionary/structure/backward/v402/content/shortcut_dict_content.cpp", - "src/dictionary/structure/backward/v402/content/sparse_table_dict_content.cpp", - "src/dictionary/structure/backward/v402/content/terminal_position_lookup_table.cpp", - "src/dictionary/structure/backward/v402/bigram/ver4_bigram_list_policy.cpp", - ], -} - -cc_library { - name: "libjni_latinime", - host_supported: true, - product_specific: true, - - sdk_version: "14", - cflags: [ - "-Werror", - "-Wall", - "-Wextra", - "-Weffc++", - "-Wformat=2", - "-Wcast-qual", - "-Wcast-align", - "-Wwrite-strings", - "-Wfloat-equal", - "-Wpointer-arith", - "-Winit-self", - "-Wredundant-decls", - "-Woverloaded-virtual", - "-Wsign-promo", - "-Wno-system-headers", - "-Wno-format-nonliteral", - - // To suppress compiler warnings for unused variables/functions used for debug features etc. - "-Wno-unused-parameter", - "-Wno-unused-function", - ], - local_include_dirs: ["src"], - - srcs: [ - "com_android_inputmethod_keyboard_ProximityInfo.cpp", - "com_android_inputmethod_latin_BinaryDictionary.cpp", - "com_android_inputmethod_latin_BinaryDictionaryUtils.cpp", - "com_android_inputmethod_latin_DicTraverseSession.cpp", - "jni_common.cpp", - - ":LATIN_IME_CORE_SRC_FILES", - ], - - target: { - android_x86: { - // HACK: -mstackrealign is required for x86 builds running on pre-KitKat devices to avoid crashes - // with SSE instructions. - cflags: ["-mstackrealign"], - }, - android: { - stl: "libc++_static", - }, - host: { - cflags: ["-DHOST_TOOL"], - }, - }, -} - -cc_library_static { - name: "liblatinime_static_for_unittests", - host_supported: true, - - cflags: [ - "-Wno-unused-parameter", - "-Wno-unused-function", - "-Wall", - "-Werror", - ], - local_include_dirs: ["src"], - sdk_version: "14", - stl: "libc++_static", - - srcs: [":LATIN_IME_CORE_SRC_FILES"], -} - -cc_test { - name: "liblatinime_unittests", - host_supported: true, - - cflags: [ - "-Wno-unused-parameter", - "-Wno-unused-function", - "-Wall", - "-Werror", - ], - local_include_dirs: ["src"], - sdk_version: "14", - stl: "libc++_static", - - srcs: [ - "tests/defines_test.cpp", - "tests/dictionary/header/header_read_write_utils_test.cpp", - "tests/dictionary/structure/v4/content/language_model_dict_content_test.cpp", - "tests/dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp", - "tests/dictionary/structure/v4/content/probability_entry_test.cpp", - "tests/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp", - "tests/dictionary/utils/bloom_filter_test.cpp", - "tests/dictionary/utils/buffer_with_extendable_buffer_test.cpp", - "tests/dictionary/utils/byte_array_utils_test.cpp", - "tests/dictionary/utils/format_utils_test.cpp", - "tests/dictionary/utils/probability_utils_test.cpp", - "tests/dictionary/utils/sparse_table_test.cpp", - "tests/dictionary/utils/trie_map_test.cpp", - "tests/suggest/core/dicnode/dic_node_pool_test.cpp", - "tests/suggest/core/layout/geometry_utils_test.cpp", - "tests/suggest/core/layout/normal_distribution_2d_test.cpp", - "tests/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy_test.cpp", - "tests/utils/autocorrection_threshold_utils_test.cpp", - "tests/utils/char_utils_test.cpp", - "tests/utils/int_array_view_test.cpp", - "tests/utils/time_keeper_test.cpp", - ], - static_libs: ["liblatinime_static_for_unittests"], -} diff --git a/app/src/main/jni/Android.mk b/app/src/main/jni/Android.mk deleted file mode 100755 index 0099cafb..00000000 --- a/app/src/main/jni/Android.mk +++ /dev/null @@ -1,106 +0,0 @@ -# Copyright (C) 2011 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. - -LOCAL_PATH := $(call my-dir) - -############ some local flags -# If you change any of those flags, you need to rebuild both libjni_latinime_common_static -# and the shared library that uses libjni_latinime_common_static. -FLAG_DBG ?= false -FLAG_DO_PROFILE ?= false - -###################################### -include $(CLEAR_VARS) - -LATIN_IME_SRC_DIR := src - -LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR) - -LOCAL_CFLAGS += -Wall -Wextra -Weffc++ -Wformat=2 -Wcast-qual -Wcast-align \ - -Wwrite-strings -Wfloat-equal -Wpointer-arith -Winit-self -Wredundant-decls \ - -Woverloaded-virtual -Wsign-promo -Wno-system-headers - -# To suppress compiler warnings for unused variables/functions used for debug features etc. -LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function - -# HACK: -mstackrealign is required for x86 builds running on pre-KitKat devices to avoid crashes -# with SSE instructions. -ifeq ($(TARGET_ARCH), x86) - LOCAL_CFLAGS += -mstackrealign -endif # x86 - -include $(LOCAL_PATH)/NativeFileList.mk - -LOCAL_SRC_FILES := \ - $(LATIN_IME_JNI_SRC_FILES) \ - $(addprefix $(LATIN_IME_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES)) - -ifeq ($(FLAG_DO_PROFILE), true) - $(warning Making profiling version of native library) - LOCAL_CFLAGS += -DFLAG_DO_PROFILE -funwind-tables -else # FLAG_DO_PROFILE -ifeq ($(FLAG_DBG), true) - $(warning Making debug version of native library) - LOCAL_CFLAGS += -DFLAG_DBG -funwind-tables -fno-inline -ifeq ($(FLAG_FULL_DBG), true) - $(warning Making full debug version of native library) - LOCAL_CFLAGS += -DFLAG_FULL_DBG -endif # FLAG_FULL_DBG -endif # FLAG_DBG -endif # FLAG_DO_PROFILE - -LOCAL_MODULE := libjni_latinime_common_static -LOCAL_MODULE_TAGS := optional - -LOCAL_CLANG := true -LOCAL_SDK_VERSION := 14 -LOCAL_NDK_STL_VARIANT := c++_static - -include $(BUILD_STATIC_LIBRARY) -###################################### -include $(CLEAR_VARS) - -# All code in LOCAL_WHOLE_STATIC_LIBRARIES will be built into this shared library. -LOCAL_WHOLE_STATIC_LIBRARIES := libjni_latinime_common_static - -ifeq ($(FLAG_DO_PROFILE), true) - $(warning Making profiling version of native library) - LOCAL_LDFLAGS += -llog -else # FLAG_DO_PROFILE -ifeq ($(FLAG_DBG), true) - $(warning Making debug version of native library) - LOCAL_LDFLAGS += -llog -endif # FLAG_DBG -endif # FLAG_DO_PROFILE - -LOCAL_MODULE := libjni_latinime -LOCAL_MODULE_TAGS := optional - -LOCAL_CLANG := true -LOCAL_SDK_VERSION := 14 -LOCAL_NDK_STL_VARIANT := c++_static -LOCAL_LDFLAGS += -ldl - -# Avoid issues with reproducible builds, see https://gitlab.com/fdroid/rfp/-/issues/2662 -LOCAL_LDFLAGS += -Wl,--build-id=none -Wl,--hash-style=both -Wl,-z,max-page-size=16384 - -include $(BUILD_SHARED_LIBRARY) -#################### Clean up the tmp vars -include $(LOCAL_PATH)/CleanupNativeFileList.mk - -#################### Unit test on host environment -#include $(LOCAL_PATH)/HostUnitTests.mk - -#################### Unit test on target environment -#include $(LOCAL_PATH)/TargetUnitTests.mk diff --git a/app/src/main/jni/Application.mk b/app/src/main/jni/Application.mk deleted file mode 100755 index a169e740..00000000 --- a/app/src/main/jni/Application.mk +++ /dev/null @@ -1,2 +0,0 @@ -APP_STL := c++_static -APP_ABI := all diff --git a/app/src/main/jni/CleanupNativeFileList.mk b/app/src/main/jni/CleanupNativeFileList.mk deleted file mode 100755 index eed6f1e6..00000000 --- a/app/src/main/jni/CleanupNativeFileList.mk +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (C) 2013 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. - -LATIN_IME_CORE_SRC_FILES := -LATIN_IME_CORE_SRC_FILES_BACKWARD_V401 := -LATIN_IME_CORE_TEST_FILES := -LATIN_IME_JNI_SRC_FILES := -LATIN_IME_SRC_DIR := diff --git a/app/src/main/jni/HostUnitTests.mk b/app/src/main/jni/HostUnitTests.mk deleted file mode 100755 index 6a8bcec2..00000000 --- a/app/src/main/jni/HostUnitTests.mk +++ /dev/null @@ -1,64 +0,0 @@ -# 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. - -# Host build is never supported in unbundled (NDK/tapas) build -ifeq (,$(TARGET_BUILD_APPS)) - -# HACK: Temporarily disable host tool build on Mac until the build system is ready for C++11. -LATINIME_HOST_OSNAME := $(shell uname -s) -ifneq ($(LATINIME_HOST_OSNAME), Darwin) # TODO: Remove this - -LOCAL_PATH := $(call my-dir) - -###################################### -include $(CLEAR_VARS) - -include $(LOCAL_PATH)/NativeFileList.mk - -#################### Host library for unit test -LATIN_IME_SRC_DIR := src -LOCAL_ADDRESS_SANITIZER := true -LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function -LOCAL_CLANG := true -LOCAL_CXX_STL := libc++ -LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR) -LOCAL_MODULE := liblatinime_host_static_for_unittests -LOCAL_MODULE_TAGS := optional -LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES)) -include $(BUILD_HOST_STATIC_LIBRARY) - -#################### Host native tests -include $(CLEAR_VARS) -LATIN_IME_TEST_SRC_DIR := tests -LOCAL_ADDRESS_SANITIZER := true -LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function -LOCAL_CLANG := true -LOCAL_CXX_STL := libc++ -LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR) -LOCAL_MODULE := liblatinime_host_unittests -LOCAL_MODULE_TAGS := tests -LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_TEST_SRC_DIR)/, $(LATIN_IME_CORE_TEST_FILES)) -LOCAL_STATIC_LIBRARIES += liblatinime_host_static_for_unittests -include $(BUILD_HOST_NATIVE_TEST) - -include $(LOCAL_PATH)/CleanupNativeFileList.mk - -endif # Darwin - TODO: Remove this - -endif # TARGET_BUILD_APPS - -#################### Clean up the tmp vars -LATINIME_HOST_OSNAME := -LATIN_IME_SRC_DIR := -LATIN_IME_TEST_SRC_DIR := diff --git a/app/src/main/jni/NativeFileList.mk b/app/src/main/jni/NativeFileList.mk deleted file mode 100755 index d8b69bfd..00000000 --- a/app/src/main/jni/NativeFileList.mk +++ /dev/null @@ -1,146 +0,0 @@ -# Copyright (C) 2013 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. - -LATIN_IME_JNI_SRC_FILES := \ - com_android_inputmethod_keyboard_ProximityInfo.cpp \ - com_android_inputmethod_latin_BinaryDictionary.cpp \ - com_android_inputmethod_latin_BinaryDictionaryUtils.cpp \ - com_android_inputmethod_latin_DicTraverseSession.cpp \ - jni_common.cpp - -LATIN_IME_CORE_SRC_FILES := \ - $(addprefix dictionary/header/, \ - header_policy.cpp \ - header_read_write_utils.cpp) \ - dictionary/property/ngram_context.cpp \ - dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp \ - $(addprefix dictionary/structure/pt_common/, \ - bigram/bigram_list_read_write_utils.cpp \ - dynamic_pt_gc_event_listeners.cpp \ - dynamic_pt_reading_helper.cpp \ - dynamic_pt_reading_utils.cpp \ - dynamic_pt_updating_helper.cpp \ - dynamic_pt_writing_utils.cpp \ - patricia_trie_reading_utils.cpp \ - shortcut/shortcut_list_reading_utils.cpp) \ - $(addprefix dictionary/structure/v2/, \ - patricia_trie_policy.cpp \ - ver2_patricia_trie_node_reader.cpp \ - ver2_pt_node_array_reader.cpp) \ - $(addprefix dictionary/structure/v4/, \ - ver4_dict_buffers.cpp \ - ver4_dict_constants.cpp \ - ver4_patricia_trie_node_reader.cpp \ - ver4_patricia_trie_node_writer.cpp \ - ver4_patricia_trie_policy.cpp \ - ver4_patricia_trie_reading_utils.cpp \ - ver4_patricia_trie_writing_helper.cpp \ - ver4_pt_node_array_reader.cpp) \ - $(addprefix dictionary/structure/v4/content/, \ - dynamic_language_model_probability_utils.cpp \ - language_model_dict_content.cpp \ - language_model_dict_content_global_counters.cpp \ - shortcut_dict_content.cpp \ - sparse_table_dict_content.cpp \ - terminal_position_lookup_table.cpp) \ - $(addprefix dictionary/utils/, \ - buffer_with_extendable_buffer.cpp \ - byte_array_utils.cpp \ - dict_file_writing_utils.cpp \ - file_utils.cpp \ - forgetting_curve_utils.cpp \ - format_utils.cpp \ - mmapped_buffer.cpp \ - multi_bigram_map.cpp \ - probability_utils.cpp \ - sparse_table.cpp \ - trie_map.cpp ) \ - suggest/core/suggest.cpp \ - $(addprefix suggest/core/dicnode/, \ - dic_node.cpp \ - dic_node_utils.cpp \ - dic_nodes_cache.cpp) \ - $(addprefix suggest/core/dictionary/, \ - dictionary.cpp \ - dictionary_utils.cpp \ - digraph_utils.cpp \ - error_type_utils.cpp ) \ - $(addprefix suggest/core/layout/, \ - additional_proximity_chars.cpp \ - proximity_info.cpp \ - proximity_info_params.cpp \ - proximity_info_state.cpp \ - proximity_info_state_utils.cpp) \ - suggest/core/policy/weighting.cpp \ - suggest/core/session/dic_traverse_session.cpp \ - $(addprefix suggest/core/result/, \ - suggestion_results.cpp \ - suggestions_output_utils.cpp) \ - suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp \ - $(addprefix suggest/policyimpl/typing/, \ - scoring_params.cpp \ - typing_scoring.cpp \ - typing_suggest_policy.cpp \ - typing_traversal.cpp \ - typing_weighting.cpp) \ - $(addprefix utils/, \ - autocorrection_threshold_utils.cpp \ - char_utils.cpp \ - jni_data_utils.cpp \ - log_utils.cpp \ - time_keeper.cpp) - -LATIN_IME_CORE_SRC_FILES_BACKWARD_V402 := \ - $(addprefix dictionary/structure/backward/v402/, \ - ver4_dict_buffers.cpp \ - ver4_dict_constants.cpp \ - ver4_patricia_trie_node_reader.cpp \ - ver4_patricia_trie_node_writer.cpp \ - ver4_patricia_trie_policy.cpp \ - ver4_patricia_trie_reading_utils.cpp \ - ver4_patricia_trie_writing_helper.cpp \ - ver4_pt_node_array_reader.cpp) \ - $(addprefix dictionary/structure/backward/v402/content/, \ - bigram_dict_content.cpp \ - probability_dict_content.cpp \ - shortcut_dict_content.cpp \ - sparse_table_dict_content.cpp \ - terminal_position_lookup_table.cpp) \ - $(addprefix dictionary/structure/backward/v402/bigram/, \ - ver4_bigram_list_policy.cpp) - -LATIN_IME_CORE_SRC_FILES += $(LATIN_IME_CORE_SRC_FILES_BACKWARD_V402) - -LATIN_IME_CORE_TEST_FILES := \ - defines_test.cpp \ - dictionary/header/header_read_write_utils_test.cpp \ - dictionary/structure/v4/content/language_model_dict_content_test.cpp \ - dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp \ - dictionary/structure/v4/content/probability_entry_test.cpp \ - dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp \ - dictionary/utils/bloom_filter_test.cpp \ - dictionary/utils/buffer_with_extendable_buffer_test.cpp \ - dictionary/utils/byte_array_utils_test.cpp \ - dictionary/utils/format_utils_test.cpp \ - dictionary/utils/probability_utils_test.cpp \ - dictionary/utils/sparse_table_test.cpp \ - dictionary/utils/trie_map_test.cpp \ - suggest/core/dicnode/dic_node_pool_test.cpp \ - suggest/core/layout/geometry_utils_test.cpp \ - suggest/core/layout/normal_distribution_2d_test.cpp \ - suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy_test.cpp \ - utils/autocorrection_threshold_utils_test.cpp \ - utils/char_utils_test.cpp \ - utils/int_array_view_test.cpp \ - utils/time_keeper_test.cpp diff --git a/app/src/main/jni/TargetUnitTests.mk b/app/src/main/jni/TargetUnitTests.mk deleted file mode 100755 index 69a32edb..00000000 --- a/app/src/main/jni/TargetUnitTests.mk +++ /dev/null @@ -1,52 +0,0 @@ -# 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. - -LOCAL_PATH := $(call my-dir) - -###################################### -include $(CLEAR_VARS) - -include $(LOCAL_PATH)/NativeFileList.mk - -#################### Target library for unit test -LATIN_IME_SRC_DIR := src -LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function -LOCAL_CLANG := true -LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR) -LOCAL_MODULE := liblatinime_target_static_for_unittests -LOCAL_MODULE_TAGS := optional -LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES)) -LOCAL_SDK_VERSION := 14 -LOCAL_NDK_STL_VARIANT := c++_static -include $(BUILD_STATIC_LIBRARY) - -#################### Target native tests -include $(CLEAR_VARS) -LATIN_IME_TEST_SRC_DIR := tests -LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function -LOCAL_CLANG := true -LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR) -LOCAL_MODULE := liblatinime_target_unittests -LOCAL_MODULE_TAGS := tests -LOCAL_SRC_FILES := \ - $(addprefix $(LATIN_IME_TEST_SRC_DIR)/, $(LATIN_IME_CORE_TEST_FILES)) -LOCAL_STATIC_LIBRARIES += liblatinime_target_static_for_unittests -LOCAL_SDK_VERSION := 14 -LOCAL_NDK_STL_VARIANT := c++_static -include $(BUILD_NATIVE_TEST) - -#################### Clean up the tmp vars -LATIN_IME_SRC_DIR := -LATIN_IME_TEST_SRC_DIR := -include $(LOCAL_PATH)/CleanupNativeFileList.mk diff --git a/app/src/main/jni/run-tests.sh b/app/src/main/jni/run-tests.sh deleted file mode 100755 index a7fa82d9..00000000 --- a/app/src/main/jni/run-tests.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash -# Copyright 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. - -function usage() { - echo "usage: source run-tests.sh [--host] [--target] [-h] [--help]" 1>&2 - echo " --host: run test on the host environment" 1>&2 - echo " --no-host: skip host test" 1>&2 - echo " --target: run test on the target environment" 1>&2 - echo " --no-target: skip target device test" 1>&2 -} - -# check script arguments -if [[ $(type -t mmm) != function ]]; then -usage -if [[ ${BASH_SOURCE[0]} != $0 ]]; then return; else exit 1; fi -fi - -show_usage=no -enable_host_test=yes -enable_target_device_test=no -while [ "$1" != "" ] - do - case "$1" in - "-h") show_usage=yes;; - "--help") show_usage=yes;; - "--target") enable_target_device_test=yes;; - "--no-target") enable_target_device_test=no;; - "--host") enable_host_test=yes;; - "--no-host") enable_host_test=no;; - esac - shift -done - -if [[ $show_usage == yes ]]; then - usage - if [[ ${BASH_SOURCE[0]} != $0 ]]; then return; else exit 1; fi -fi - -# Host build is never supported in unbundled (NDK/tapas) build -if [[ $enable_host_test == yes && -n $TARGET_BUILD_APPS ]]; then - echo "Host build is never supported in tapas build." 1>&2 - echo "Use lunch command instead." 1>&2 - if [[ ${BASH_SOURCE[0]} != $0 ]]; then return; else exit 1; fi -fi - -target_test_name=liblatinime_target_unittests -host_test_name=liblatinime_host_unittests - -pushd $PWD > /dev/null -cd $(gettop) -mmm -j16 packages/inputmethods/LatinIME/native/jni || \ - make -j16 adb $target_test_name $host_test_name -if [[ $enable_host_test == yes ]]; then - $ANDROID_HOST_OUT/bin/$host_test_name -fi -if [[ $enable_target_device_test == yes ]]; then - target_test_local=$ANDROID_PRODUCT_OUT/data/nativetest/$target_test_name/$target_test_name - target_test_device=/data/nativetest/$target_test_name/$target_test_name - adb push $target_test_local $target_test_device - adb shell $target_test_device - adb shell rm -rf $target_test_device -fi -popd > /dev/null diff --git a/app/src/main/jni/tests/defines_test.cpp b/app/src/main/jni/tests/defines_test.cpp deleted file mode 100644 index f7b80b2b..00000000 --- a/app/src/main/jni/tests/defines_test.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 "defines.h" - -#include - -namespace latinime { -namespace { - -TEST(DefinesTest, NELEMSForFixedLengthArray) { - const size_t SMALL_ARRAY_SIZE = 1; - const size_t LARGE_ARRAY_SIZE = 100; - int smallArray[SMALL_ARRAY_SIZE]; - int largeArray[LARGE_ARRAY_SIZE]; - EXPECT_EQ(SMALL_ARRAY_SIZE, NELEMS(smallArray)); - EXPECT_EQ(LARGE_ARRAY_SIZE, NELEMS(largeArray)); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/header/header_read_write_utils_test.cpp b/app/src/main/jni/tests/dictionary/header/header_read_write_utils_test.cpp deleted file mode 100644 index eab5d657..00000000 --- a/app/src/main/jni/tests/dictionary/header/header_read_write_utils_test.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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 "dictionary/header/header_read_write_utils.h" - -#include - -#include -#include - -#include "dictionary/interface/dictionary_header_structure_policy.h" - -namespace latinime { -namespace { - -TEST(HeaderReadWriteUtilsTest, TestInsertCharactersIntoVector) { - DictionaryHeaderStructurePolicy::AttributeMap::key_type vector; - - HeaderReadWriteUtils::insertCharactersIntoVector("", &vector); - EXPECT_TRUE(vector.empty()); - - static const char *str = "abc-xyz!?"; - HeaderReadWriteUtils::insertCharactersIntoVector(str, &vector); - EXPECT_EQ(strlen(str) , vector.size()); - for (size_t i = 0; i < vector.size(); ++i) { - EXPECT_EQ(str[i], vector[i]); - } -} - -TEST(HeaderReadWriteUtilsTest, TestAttributeMapForInt) { - DictionaryHeaderStructurePolicy::AttributeMap attributeMap; - - // Returns default value if not exists. - EXPECT_EQ(-1, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "", -1)); - EXPECT_EQ(100, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100)); - - HeaderReadWriteUtils::setIntAttribute(&attributeMap, "abc", 10); - EXPECT_EQ(10, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100)); - HeaderReadWriteUtils::setIntAttribute(&attributeMap, "abc", 20); - EXPECT_EQ(20, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100)); - HeaderReadWriteUtils::setIntAttribute(&attributeMap, "abcd", 30); - EXPECT_EQ(30, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abcd", 100)); - EXPECT_EQ(20, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100)); -} - -TEST(HeaderReadWriteUtilsTest, TestAttributeMapCodeForPoints) { - DictionaryHeaderStructurePolicy::AttributeMap attributeMap; - - // Returns empty vector if not exists. - EXPECT_TRUE(HeaderReadWriteUtils::readCodePointVectorAttributeValue(&attributeMap, "").empty()); - EXPECT_TRUE(HeaderReadWriteUtils::readCodePointVectorAttributeValue( - &attributeMap, "abc").empty()); - - HeaderReadWriteUtils::setCodePointVectorAttribute(&attributeMap, "abc", {}); - EXPECT_TRUE(HeaderReadWriteUtils::readCodePointVectorAttributeValue( - &attributeMap, "abc").empty()); - - const std::vector codePoints = { 0x0, 0x20, 0x1F, 0x100000 }; - HeaderReadWriteUtils::setCodePointVectorAttribute(&attributeMap, "abc", codePoints); - EXPECT_EQ(codePoints, HeaderReadWriteUtils::readCodePointVectorAttributeValue( - &attributeMap, "abc")); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp b/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp deleted file mode 100644 index 2e3047ed..00000000 --- a/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 "dictionary/structure/v4/content/language_model_dict_content_global_counters.h" - -#include - -#include "dictionary/structure/v4/ver4_dict_constants.h" - -namespace latinime { -namespace { - -TEST(LanguageModelDictContentGlobalCountersTest, TestUpdateMaxValueOfCounters) { - LanguageModelDictContentGlobalCounters globalCounters; - - EXPECT_FALSE(globalCounters.needsToHalveCounters()); - globalCounters.updateMaxValueOfCounters(10); - EXPECT_FALSE(globalCounters.needsToHalveCounters()); - const int count = (1 << (Ver4DictConstants::WORD_COUNT_FIELD_SIZE * CHAR_BIT)) - 1; - globalCounters.updateMaxValueOfCounters(count); - EXPECT_TRUE(globalCounters.needsToHalveCounters()); - globalCounters.halveCounters(); - EXPECT_FALSE(globalCounters.needsToHalveCounters()); -} - -TEST(LanguageModelDictContentGlobalCountersTest, TestIncrementTotalCount) { - LanguageModelDictContentGlobalCounters globalCounters; - - EXPECT_EQ(0, globalCounters.getTotalCount()); - globalCounters.incrementTotalCount(); - EXPECT_EQ(1, globalCounters.getTotalCount()); - for (int i = 1; i < 50; ++i) { - globalCounters.incrementTotalCount(); - } - EXPECT_EQ(50, globalCounters.getTotalCount()); - globalCounters.halveCounters(); - EXPECT_EQ(25, globalCounters.getTotalCount()); - globalCounters.halveCounters(); - EXPECT_EQ(12, globalCounters.getTotalCount()); - for (int i = 0; i < 4; ++i) { - globalCounters.halveCounters(); - } - EXPECT_EQ(0, globalCounters.getTotalCount()); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_test.cpp b/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_test.cpp deleted file mode 100644 index ab11975c..00000000 --- a/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_test.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 "dictionary/structure/v4/content/language_model_dict_content.h" - -#include - -#include -#include - -#include "utils/int_array_view.h" - -namespace latinime { -namespace { - -TEST(LanguageModelDictContentTest, TestUnigramProbability) { - LanguageModelDictContent languageModelDictContent(false /* useHistoricalInfo */); - - const int flag = 0xF0; - const int probability = 10; - const int wordId = 100; - const ProbabilityEntry probabilityEntry(flag, probability); - languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry); - const ProbabilityEntry entry = - languageModelDictContent.getProbabilityEntry(wordId); - EXPECT_EQ(flag, entry.getFlags()); - EXPECT_EQ(probability, entry.getProbability()); - - // Remove - EXPECT_TRUE(languageModelDictContent.removeProbabilityEntry(wordId)); - EXPECT_FALSE(languageModelDictContent.getProbabilityEntry(wordId).isValid()); - EXPECT_FALSE(languageModelDictContent.removeProbabilityEntry(wordId)); - EXPECT_TRUE(languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry)); - EXPECT_TRUE(languageModelDictContent.getProbabilityEntry(wordId).isValid()); -} - -TEST(LanguageModelDictContentTest, TestUnigramProbabilityWithHistoricalInfo) { - LanguageModelDictContent languageModelDictContent(true /* useHistoricalInfo */); - - const int flag = 0xF0; - const int timestamp = 0x3FFFFFFF; - const int count = 10; - const int wordId = 100; - const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count); - const ProbabilityEntry probabilityEntry(flag, &historicalInfo); - languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry); - const ProbabilityEntry entry = languageModelDictContent.getProbabilityEntry(wordId); - EXPECT_EQ(flag, entry.getFlags()); - EXPECT_EQ(timestamp, entry.getHistoricalInfo()->getTimestamp()); - EXPECT_EQ(count, entry.getHistoricalInfo()->getCount()); - - // Remove - EXPECT_TRUE(languageModelDictContent.removeProbabilityEntry(wordId)); - EXPECT_FALSE(languageModelDictContent.getProbabilityEntry(wordId).isValid()); - EXPECT_FALSE(languageModelDictContent.removeProbabilityEntry(wordId)); - EXPECT_TRUE(languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry)); - EXPECT_TRUE(languageModelDictContent.removeProbabilityEntry(wordId)); -} - -TEST(LanguageModelDictContentTest, TestIterateProbabilityEntry) { - LanguageModelDictContent languageModelDictContent(false /* useHistoricalInfo */); - - const ProbabilityEntry originalEntry(0xFC, 100); - - const int wordIds[] = { 1, 2, 3, 4, 5 }; - for (const int wordId : wordIds) { - languageModelDictContent.setProbabilityEntry(wordId, &originalEntry); - } - std::unordered_set wordIdSet(std::begin(wordIds), std::end(wordIds)); - for (const auto& entry : languageModelDictContent.getProbabilityEntries(WordIdArrayView())) { - EXPECT_EQ(originalEntry.getFlags(), entry.getProbabilityEntry().getFlags()); - EXPECT_EQ(originalEntry.getProbability(), entry.getProbabilityEntry().getProbability()); - wordIdSet.erase(entry.getWordId()); - } - EXPECT_TRUE(wordIdSet.empty()); -} - -TEST(LanguageModelDictContentTest, TestGetWordProbability) { - LanguageModelDictContent languageModelDictContent(false /* useHistoricalInfo */); - - const int flag = 0xFF; - const int probability = 10; - const int bigramProbability = 20; - const int trigramProbability = 30; - const int wordId = 100; - const std::array prevWordIdArray = {{ 1, 2 }}; - const WordIdArrayView prevWordIds = WordIdArrayView::fromArray(prevWordIdArray); - - const ProbabilityEntry probabilityEntry(flag, probability); - languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry); - const ProbabilityEntry bigramProbabilityEntry(flag, bigramProbability); - languageModelDictContent.setProbabilityEntry(prevWordIds[0], &probabilityEntry); - languageModelDictContent.setNgramProbabilityEntry(prevWordIds.limit(1), wordId, - &bigramProbabilityEntry); - EXPECT_EQ(bigramProbability, languageModelDictContent.getWordAttributes(prevWordIds, wordId, - false /* mustMatchAllPrevWords */, nullptr /* headerPolicy */).getProbability()); - const ProbabilityEntry trigramProbabilityEntry(flag, trigramProbability); - languageModelDictContent.setNgramProbabilityEntry(prevWordIds.limit(1), - prevWordIds[1], &probabilityEntry); - languageModelDictContent.setNgramProbabilityEntry(prevWordIds.limit(2), wordId, - &trigramProbabilityEntry); - EXPECT_EQ(trigramProbability, languageModelDictContent.getWordAttributes(prevWordIds, wordId, - false /* mustMatchAllPrevWords */, nullptr /* headerPolicy */).getProbability()); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/structure/v4/content/probability_entry_test.cpp b/app/src/main/jni/tests/dictionary/structure/v4/content/probability_entry_test.cpp deleted file mode 100644 index ba81671b..00000000 --- a/app/src/main/jni/tests/dictionary/structure/v4/content/probability_entry_test.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 "dictionary/structure/v4/content/probability_entry.h" - -#include - -#include "defines.h" - -namespace latinime { -namespace { - -TEST(ProbabilityEntryTest, TestEncodeDecode) { - const int flag = 0xFF; - const int probability = 10; - - const ProbabilityEntry entry(flag, probability); - const uint64_t encodedEntry = entry.encode(false /* hasHistoricalInfo */); - const ProbabilityEntry decodedEntry = - ProbabilityEntry::decode(encodedEntry, false /* hasHistoricalInfo */); - EXPECT_EQ(0xFF0Aull, encodedEntry); - EXPECT_EQ(flag, decodedEntry.getFlags()); - EXPECT_EQ(probability, decodedEntry.getProbability()); -} - -TEST(ProbabilityEntryTest, TestEncodeDecodeWithHistoricalInfo) { - const int flag = 0xF0; - const int timestamp = 0x3FFFFFFF; - const int count = 0xABCD; - - const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count); - const ProbabilityEntry entry(flag, &historicalInfo); - - const uint64_t encodedEntry = entry.encode(true /* hasHistoricalInfo */); - EXPECT_EQ(0xF03FFFFFFFABCDull, encodedEntry); - const ProbabilityEntry decodedEntry = - ProbabilityEntry::decode(encodedEntry, true /* hasHistoricalInfo */); - - EXPECT_EQ(flag, decodedEntry.getFlags()); - EXPECT_EQ(timestamp, decodedEntry.getHistoricalInfo()->getTimestamp()); - EXPECT_EQ(count, decodedEntry.getHistoricalInfo()->getCount()); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp b/app/src/main/jni/tests/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp deleted file mode 100644 index 4f23889c..00000000 --- a/app/src/main/jni/tests/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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 "dictionary/structure/v4/content/terminal_position_lookup_table.h" - -#include - -#include - -#include "defines.h" -#include "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 terminalIds = { 10, 20, 30 }; - const std::vector 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(i), terminalIdMap[terminalIds[i]]) - << "Terminal id (" << terminalIds[i] << ") should be changed to " << i; - EXPECT_EQ(terminalPositions[i], lookupTable.getTerminalPtNodePosition(i)); - } -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/utils/bloom_filter_test.cpp b/app/src/main/jni/tests/dictionary/utils/bloom_filter_test.cpp deleted file mode 100644 index bcc88438..00000000 --- a/app/src/main/jni/tests/dictionary/utils/bloom_filter_test.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 "dictionary/utils/bloom_filter.h" - -#include - -#include -#include -#include -#include -#include -#include - -namespace latinime { -namespace { - -TEST(BloomFilterTest, TestFilter) { - static const int TEST_RANDOM_DATA_MAX = 65536; - static const int ELEMENT_COUNT = 1000; - std::vector elements; - - // Initialize data set with random integers. - { - // Use the uniform integer distribution [0, TEST_RANDOM_DATA_MAX]. - std::uniform_int_distribution distribution(0, TEST_RANDOM_DATA_MAX); - auto randomNumberGenerator = std::bind(distribution, std::mt19937()); - for (int i = 0; i < ELEMENT_COUNT; ++i) { - elements.push_back(randomNumberGenerator()); - } - } - - // Make sure BloomFilter contains nothing by default. - BloomFilter bloomFilter; - for (const int elem : elements) { - ASSERT_FALSE(bloomFilter.isInFilter(elem)); - } - - // Copy some of the test vector into bloom filter. - std::unordered_set elementsThatHaveBeenSetInFilter; - { - // Use the uniform integer distribution [0, 1]. - std::uniform_int_distribution distribution(0, 1); - auto randomBitGenerator = std::bind(distribution, std::mt19937()); - for (const int elem : elements) { - if (randomBitGenerator() == 0) { - bloomFilter.setInFilter(elem); - elementsThatHaveBeenSetInFilter.insert(elem); - } - } - } - - for (const int elem : elements) { - const bool existsInFilter = bloomFilter.isInFilter(elem); - const bool hasBeenSetInFilter = - elementsThatHaveBeenSetInFilter.find(elem) != elementsThatHaveBeenSetInFilter.end(); - if (hasBeenSetInFilter) { - EXPECT_TRUE(existsInFilter) << "elem: " << elem; - } - if (!existsInFilter) { - EXPECT_FALSE(hasBeenSetInFilter) << "elem: " << elem; - } - } -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/utils/buffer_with_extendable_buffer_test.cpp b/app/src/main/jni/tests/dictionary/utils/buffer_with_extendable_buffer_test.cpp deleted file mode 100644 index 25878910..00000000 --- a/app/src/main/jni/tests/dictionary/utils/buffer_with_extendable_buffer_test.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 "dictionary/utils/buffer_with_extendable_buffer.h" - -#include - -namespace latinime { -namespace { - -const int DEFAULT_MAX_BUFFER_SIZE = 1024; - -TEST(BufferWithExtendablebufferTest, TestWriteAndRead) { - BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE); - int pos = 0; - // 1 byte - const uint32_t data_1 = 0xFF; - EXPECT_TRUE(buffer.writeUint(data_1, 1 /* size */, pos)); - EXPECT_EQ(data_1, buffer.readUint(1, pos)); - pos += 1; - // 2 byte - const uint32_t data_2 = 0xFFFF; - EXPECT_TRUE(buffer.writeUint(data_2, 2 /* size */, pos)); - EXPECT_EQ(data_2, buffer.readUint(2, pos)); - pos += 2; - // 3 byte - const uint32_t data_3 = 0xFFFFFF; - EXPECT_TRUE(buffer.writeUint(data_3, 3 /* size */, pos)); - EXPECT_EQ(data_3, buffer.readUint(3, pos)); - pos += 3; - // 4 byte - const uint32_t data_4 = 0xFFFFFFFF; - EXPECT_TRUE(buffer.writeUint(data_4, 4 /* size */, pos)); - EXPECT_EQ(data_4, buffer.readUint(4, pos)); -} - -TEST(BufferWithExtendablebufferTest, TestExtend) { - BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE); - EXPECT_EQ(0, buffer.getTailPosition()); - EXPECT_TRUE(buffer.writeUint(0xFF /* data */, 4 /* size */, 0 /* pos */)); - EXPECT_EQ(4, buffer.getTailPosition()); - EXPECT_TRUE(buffer.extend(8 /* size */)); - EXPECT_EQ(12, buffer.getTailPosition()); - EXPECT_TRUE(buffer.writeUint(0xFFFF /* data */, 4 /* size */, 8 /* pos */)); - EXPECT_TRUE(buffer.writeUint(0xFF /* data */, 4 /* size */, 0 /* pos */)); -} - -TEST(BufferWithExtendablebufferTest, TestCopy) { - BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE); - EXPECT_TRUE(buffer.writeUint(0xFF /* data */, 4 /* size */, 0 /* pos */)); - EXPECT_TRUE(buffer.writeUint(0xFFFF /* data */, 4 /* size */, 4 /* pos */)); - BufferWithExtendableBuffer targetBuffer(DEFAULT_MAX_BUFFER_SIZE); - EXPECT_TRUE(targetBuffer.copy(&buffer)); - EXPECT_EQ(0xFFu, targetBuffer.readUint(4 /* size */, 0 /* pos */)); - EXPECT_EQ(0xFFFFu, targetBuffer.readUint(4 /* size */, 4 /* pos */)); -} - -TEST(BufferWithExtendablebufferTest, TestSizeLimit) { - BufferWithExtendableBuffer emptyBuffer(0 /* maxAdditionalBufferSize */); - EXPECT_FALSE(emptyBuffer.writeUint(0 /* data */, 1 /* size */, 0 /* pos */)); - EXPECT_FALSE(emptyBuffer.extend(1 /* size */)); - - BufferWithExtendableBuffer smallBuffer(4 /* maxAdditionalBufferSize */); - EXPECT_TRUE(smallBuffer.writeUint(0 /* data */, 4 /* size */, 0 /* pos */)); - EXPECT_FALSE(smallBuffer.writeUint(0 /* data */, 1 /* size */, 4 /* pos */)); - - EXPECT_TRUE(smallBuffer.copy(&emptyBuffer)); - EXPECT_FALSE(emptyBuffer.copy(&smallBuffer)); - - BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE); - EXPECT_FALSE(buffer.isNearSizeLimit()); - int pos = 0; - while (!buffer.isNearSizeLimit()) { - EXPECT_TRUE(buffer.writeUintAndAdvancePosition(0 /* data */, 4 /* size */, &pos)); - } - EXPECT_GT(pos, 0); - EXPECT_LE(pos, DEFAULT_MAX_BUFFER_SIZE); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/utils/byte_array_utils_test.cpp b/app/src/main/jni/tests/dictionary/utils/byte_array_utils_test.cpp deleted file mode 100644 index 07257530..00000000 --- a/app/src/main/jni/tests/dictionary/utils/byte_array_utils_test.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 "dictionary/utils/byte_array_utils.h" - -#include - -#include - -namespace latinime { -namespace { - -TEST(ByteArrayUtilsTest, TestReadCodePointTable) { - const int codePointTable[] = { 0x6f, 0x6b }; - const uint8_t buffer[] = { 0x20u, 0x21u, 0x00u, 0x01u, 0x00u }; - int pos = 0; - // Expect the first entry of codePointTable - EXPECT_EQ(0x6f, ByteArrayUtils::readCodePointAndAdvancePosition(buffer, codePointTable, &pos)); - // Expect the second entry of codePointTable - EXPECT_EQ(0x6b, ByteArrayUtils::readCodePointAndAdvancePosition(buffer, codePointTable, &pos)); - // Expect the original code point from buffer[2] to buffer[4], 0x100 - // It isn't picked from the codePointTable, since it exceeds the range of the codePointTable. - EXPECT_EQ(0x100, ByteArrayUtils::readCodePointAndAdvancePosition(buffer, codePointTable, &pos)); -} - -TEST(ByteArrayUtilsTest, TestReadInt) { - const uint8_t buffer[] = { 0x1u, 0x8Au, 0x0u, 0xAAu }; - - EXPECT_EQ(0x01u, ByteArrayUtils::readUint8(buffer, 0)); - EXPECT_EQ(0x8Au, ByteArrayUtils::readUint8(buffer, 1)); - EXPECT_EQ(0x0u, ByteArrayUtils::readUint8(buffer, 2)); - EXPECT_EQ(0xAAu, ByteArrayUtils::readUint8(buffer, 3)); - - EXPECT_EQ(0x018Au, ByteArrayUtils::readUint16(buffer, 0)); - EXPECT_EQ(0x8A00u, ByteArrayUtils::readUint16(buffer, 1)); - EXPECT_EQ(0xAAu, ByteArrayUtils::readUint16(buffer, 2)); - - EXPECT_EQ(0x18A00AAu, ByteArrayUtils::readUint32(buffer, 0)); - - int pos = 0; - EXPECT_EQ(0x18A00, ByteArrayUtils::readSint24AndAdvancePosition(buffer, &pos)); - pos = 1; - EXPECT_EQ(-0xA00AA, ByteArrayUtils::readSint24AndAdvancePosition(buffer, &pos)); -} - -TEST(ByteArrayUtilsTest, TestWriteAndReadInt) { - uint8_t buffer[4]; - - int pos = 0; - const uint8_t data_1B = 0xC8; - ByteArrayUtils::writeUintAndAdvancePosition(buffer, data_1B, 1, &pos); - EXPECT_EQ(data_1B, ByteArrayUtils::readUint(buffer, 1, 0)); - - pos = 0; - const uint32_t data_4B = 0xABCD1234; - ByteArrayUtils::writeUintAndAdvancePosition(buffer, data_4B, 4, &pos); - EXPECT_EQ(data_4B, ByteArrayUtils::readUint(buffer, 4, 0)); -} - -TEST(ByteArrayUtilsTest, TestReadCodePoint) { - const uint8_t buffer[] = { 0x10, 0xFF, 0x00u, 0x20u, 0x41u, 0x1Fu, 0x60 }; - - EXPECT_EQ(0x10FF00, ByteArrayUtils::readCodePoint(buffer, 0)); - EXPECT_EQ(0x20, ByteArrayUtils::readCodePoint(buffer, 3)); - EXPECT_EQ(0x41, ByteArrayUtils::readCodePoint(buffer, 4)); - EXPECT_EQ(NOT_A_CODE_POINT, ByteArrayUtils::readCodePoint(buffer, 5)); - - int pos = 0; - int codePointArray[3]; - EXPECT_EQ(3, ByteArrayUtils::readStringAndAdvancePosition(buffer, MAX_WORD_LENGTH, nullptr, - codePointArray, &pos)); - EXPECT_EQ(0x10FF00, codePointArray[0]); - EXPECT_EQ(0x20, codePointArray[1]); - EXPECT_EQ(0x41, codePointArray[2]); - EXPECT_EQ(0x60, ByteArrayUtils::readCodePoint(buffer, pos)); -} - -TEST(ByteArrayUtilsTest, TestWriteAndReadCodePoint) { - uint8_t buffer[10]; - - const int codePointArray[] = { 0x10FF00, 0x20, 0x41 }; - int pos = 0; - ByteArrayUtils::writeCodePointsAndAdvancePosition(buffer, codePointArray, 3, - true /* writesTerminator */, &pos); - EXPECT_EQ(0x10FF00, ByteArrayUtils::readCodePoint(buffer, 0)); - EXPECT_EQ(0x20, ByteArrayUtils::readCodePoint(buffer, 3)); - EXPECT_EQ(0x41, ByteArrayUtils::readCodePoint(buffer, 4)); - EXPECT_EQ(NOT_A_CODE_POINT, ByteArrayUtils::readCodePoint(buffer, 5)); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/utils/format_utils_test.cpp b/app/src/main/jni/tests/dictionary/utils/format_utils_test.cpp deleted file mode 100644 index 3561bda3..00000000 --- a/app/src/main/jni/tests/dictionary/utils/format_utils_test.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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 "dictionary/utils/format_utils.h" - -#include - -#include - -#include "utils/byte_array_view.h" - -namespace latinime { -namespace { - -TEST(FormatUtilsTest, TestMagicNumber) { - EXPECT_EQ(0x9BC13AFE, FormatUtils::MAGIC_NUMBER) << "Magic number must not be changed."; -} - -const std::vector getBuffer(const int magicNumber, const int version, const uint16_t flags, - const size_t headerSize) { - std::vector buffer; - buffer.push_back(magicNumber >> 24); - buffer.push_back(magicNumber >> 16); - buffer.push_back(magicNumber >> 8); - buffer.push_back(magicNumber); - - buffer.push_back(version >> 8); - buffer.push_back(version); - - buffer.push_back(flags >> 8); - buffer.push_back(flags); - - buffer.push_back(headerSize >> 24); - buffer.push_back(headerSize >> 16); - buffer.push_back(headerSize >> 8); - buffer.push_back(headerSize); - return buffer; -} - -TEST(FormatUtilsTest, TestDetectFormatVersion) { - EXPECT_EQ(FormatUtils::UNKNOWN_VERSION, - FormatUtils::detectFormatVersion(ReadOnlyByteArrayView())); - - { - const std::vector buffer = - getBuffer(FormatUtils::MAGIC_NUMBER, FormatUtils::VERSION_2, 0, 0); - EXPECT_EQ(FormatUtils::VERSION_2, FormatUtils::detectFormatVersion( - ReadOnlyByteArrayView(buffer.data(), buffer.size()))); - } - { - const std::vector buffer = - getBuffer(FormatUtils::MAGIC_NUMBER, FormatUtils::VERSION_402, 0, 0); - EXPECT_EQ(FormatUtils::VERSION_402, FormatUtils::detectFormatVersion( - ReadOnlyByteArrayView(buffer.data(), buffer.size()))); - } - { - const std::vector buffer = - getBuffer(FormatUtils::MAGIC_NUMBER, FormatUtils::VERSION_403, 0, 0); - EXPECT_EQ(FormatUtils::VERSION_403, FormatUtils::detectFormatVersion( - ReadOnlyByteArrayView(buffer.data(), buffer.size()))); - } - - { - const std::vector buffer = - getBuffer(FormatUtils::MAGIC_NUMBER - 1, FormatUtils::VERSION_2, 0, 0); - EXPECT_EQ(FormatUtils::UNKNOWN_VERSION, FormatUtils::detectFormatVersion( - ReadOnlyByteArrayView(buffer.data(), buffer.size()))); - } - { - const std::vector buffer = - getBuffer(FormatUtils::MAGIC_NUMBER, 100, 0, 0); - EXPECT_EQ(FormatUtils::UNKNOWN_VERSION, FormatUtils::detectFormatVersion( - ReadOnlyByteArrayView(buffer.data(), buffer.size()))); - } - { - const std::vector buffer = - getBuffer(FormatUtils::MAGIC_NUMBER, FormatUtils::VERSION_2, 0, 0); - EXPECT_EQ(FormatUtils::UNKNOWN_VERSION, FormatUtils::detectFormatVersion( - ReadOnlyByteArrayView(buffer.data(), buffer.size() - 1))); - } -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/utils/probability_utils_test.cpp b/app/src/main/jni/tests/dictionary/utils/probability_utils_test.cpp deleted file mode 100644 index 4020ea44..00000000 --- a/app/src/main/jni/tests/dictionary/utils/probability_utils_test.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 "dictionary/utils/probability_utils.h" - -#include - -#include "defines.h" - -namespace latinime { -namespace { - -TEST(ProbabilityUtilsTest, TestEncodeRawProbability) { - EXPECT_EQ(MAX_PROBABILITY, ProbabilityUtils::encodeRawProbability(1.0f)); - EXPECT_EQ(MAX_PROBABILITY - 9, ProbabilityUtils::encodeRawProbability(0.5f)); - EXPECT_EQ(0, ProbabilityUtils::encodeRawProbability(0.0f)); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/utils/sparse_table_test.cpp b/app/src/main/jni/tests/dictionary/utils/sparse_table_test.cpp deleted file mode 100644 index 237c9631..00000000 --- a/app/src/main/jni/tests/dictionary/utils/sparse_table_test.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 "dictionary/utils/sparse_table.h" - -#include - -#include "dictionary/utils/buffer_with_extendable_buffer.h" - -namespace latinime { -namespace { - -TEST(SparseTableTest, TestSetAndGet) { - static const int BLOCK_SIZE = 64; - static const int DATA_SIZE = 4; - BufferWithExtendableBuffer indexTableBuffer( - BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE); - BufferWithExtendableBuffer contentTableBuffer( - BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE); - SparseTable sparseTable(&indexTableBuffer, &contentTableBuffer, BLOCK_SIZE, DATA_SIZE); - - EXPECT_FALSE(sparseTable.contains(10)); - EXPECT_TRUE(sparseTable.set(10, 100u)); - EXPECT_EQ(100u, sparseTable.get(10)); - EXPECT_TRUE(sparseTable.contains(10)); - EXPECT_TRUE(sparseTable.contains(BLOCK_SIZE - 1)); - EXPECT_FALSE(sparseTable.contains(BLOCK_SIZE)); - EXPECT_TRUE(sparseTable.set(11, 101u)); - EXPECT_EQ(100u, sparseTable.get(10)); - EXPECT_EQ(101u, sparseTable.get(11)); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/dictionary/utils/trie_map_test.cpp b/app/src/main/jni/tests/dictionary/utils/trie_map_test.cpp deleted file mode 100644 index 8f3ec9d2..00000000 --- a/app/src/main/jni/tests/dictionary/utils/trie_map_test.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* - * 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 "dictionary/utils/trie_map.h" - -#include - -#include -#include -#include -#include -#include -#include - -namespace latinime { -namespace { - -TEST(TrieMapTest, TestSetAndGet) { - TrieMap trieMap; - trieMap.putRoot(10, 10); - EXPECT_EQ(10ull, trieMap.getRoot(10).mValue); - trieMap.putRoot(0x10A, 10); - EXPECT_EQ(10ull, trieMap.getRoot(10).mValue); - EXPECT_EQ(10ull, trieMap.getRoot(0x10A).mValue); - trieMap.putRoot(10, 1000); - EXPECT_EQ(1000ull, trieMap.getRoot(10).mValue); - trieMap.putRoot(11, 1000); - EXPECT_EQ(1000ull, trieMap.getRoot(11).mValue); - const int next = trieMap.getNextLevelBitmapEntryIndex(10); - EXPECT_EQ(1000ull, trieMap.getRoot(10).mValue); - trieMap.put(9, 9, next); - EXPECT_EQ(9ull, trieMap.get(9, next).mValue); - EXPECT_FALSE(trieMap.get(11, next).mIsValid); - trieMap.putRoot(0, 0xFFFFFFFFFull); - EXPECT_EQ(0xFFFFFFFFFull, trieMap.getRoot(0).mValue); -} - -TEST(TrieMapTest, TestRemove) { - TrieMap trieMap; - trieMap.putRoot(10, 10); - EXPECT_EQ(10ull, trieMap.getRoot(10).mValue); - EXPECT_TRUE(trieMap.remove(10, trieMap.getRootBitmapEntryIndex())); - EXPECT_FALSE(trieMap.getRoot(10).mIsValid); - for (const auto &element : trieMap.getEntriesInRootLevel()) { - (void)element; // not used - EXPECT_TRUE(false); - } - EXPECT_TRUE(trieMap.putRoot(10, 0x3FFFFF)); - EXPECT_FALSE(trieMap.remove(11, trieMap.getRootBitmapEntryIndex())) - << "Should fail if the key does not exist."; - EXPECT_EQ(0x3FFFFFull, trieMap.getRoot(10).mValue); - trieMap.putRoot(12, 11); - const int nextLevel = trieMap.getNextLevelBitmapEntryIndex(10); - trieMap.put(10, 10, nextLevel); - EXPECT_EQ(0x3FFFFFull, trieMap.getRoot(10).mValue); - EXPECT_EQ(10ull, trieMap.get(10, nextLevel).mValue); - EXPECT_TRUE(trieMap.remove(10, trieMap.getRootBitmapEntryIndex())); - const TrieMap::Result result = trieMap.getRoot(10); - EXPECT_FALSE(result.mIsValid); - EXPECT_EQ(TrieMap::INVALID_INDEX, result.mNextLevelBitmapEntryIndex); - EXPECT_EQ(11ull, trieMap.getRoot(12).mValue); - EXPECT_TRUE(trieMap.putRoot(S_INT_MAX, 0xFFFFFFFFFull)); - EXPECT_TRUE(trieMap.remove(S_INT_MAX, trieMap.getRootBitmapEntryIndex())); -} - -TEST(TrieMapTest, TestSetAndGetLarge) { - static const int ELEMENT_COUNT = 200000; - TrieMap trieMap; - for (int i = 0; i < ELEMENT_COUNT; ++i) { - EXPECT_TRUE(trieMap.putRoot(i, i)); - } - for (int i = 0; i < ELEMENT_COUNT; ++i) { - EXPECT_EQ(static_cast(i), trieMap.getRoot(i).mValue); - } -} - -TEST(TrieMapTest, TestRandSetAndGetLarge) { - static const int ELEMENT_COUNT = 100000; - TrieMap trieMap; - std::unordered_map testKeyValuePairs; - - // Use the uniform integer distribution [S_INT_MIN, S_INT_MAX]. - std::uniform_int_distribution keyDistribution(S_INT_MIN, S_INT_MAX); - auto keyRandomNumberGenerator = std::bind(keyDistribution, std::mt19937()); - - // Use the uniform distribution [0, TrieMap::MAX_VALUE]. - std::uniform_int_distribution valueDistribution(0, TrieMap::MAX_VALUE); - auto valueRandomNumberGenerator = std::bind(valueDistribution, std::mt19937()); - - for (int i = 0; i < ELEMENT_COUNT; ++i) { - const int key = keyRandomNumberGenerator(); - const uint64_t value = valueRandomNumberGenerator(); - EXPECT_TRUE(trieMap.putRoot(key, value)) << key << " " << value; - testKeyValuePairs[key] = value; - } - for (const auto &v : testKeyValuePairs) { - EXPECT_EQ(v.second, trieMap.getRoot(v.first).mValue); - } -} - -TEST(TrieMapTest, TestMultiLevel) { - static const int FIRST_LEVEL_ENTRY_COUNT = 10000; - static const int SECOND_LEVEL_ENTRY_COUNT = 20000; - static const int THIRD_LEVEL_ENTRY_COUNT = 40000; - - TrieMap trieMap; - std::vector firstLevelKeys; - std::map firstLevelEntries; - std::vector> secondLevelKeys; - std::map> twoLevelMap; - std::map>> threeLevelMap; - - // Use the uniform integer distribution [0, S_INT_MAX]. - std::uniform_int_distribution distribution(0, S_INT_MAX); - auto keyRandomNumberGenerator = std::bind(distribution, std::mt19937()); - auto randomNumberGeneratorForKeySelection = std::bind(distribution, std::mt19937()); - - // Use the uniform distribution [0, TrieMap::MAX_VALUE]. - std::uniform_int_distribution valueDistribution(0, TrieMap::MAX_VALUE); - auto valueRandomNumberGenerator = std::bind(valueDistribution, std::mt19937()); - - for (int i = 0; i < FIRST_LEVEL_ENTRY_COUNT; ++i) { - const int key = keyRandomNumberGenerator(); - const uint64_t value = valueRandomNumberGenerator(); - EXPECT_TRUE(trieMap.putRoot(key, value)); - firstLevelKeys.push_back(key); - firstLevelEntries[key] = value; - } - - for (int i = 0; i < SECOND_LEVEL_ENTRY_COUNT; ++i) { - const int key = keyRandomNumberGenerator(); - const uint64_t value = valueRandomNumberGenerator(); - const int firstLevelKey = - firstLevelKeys[randomNumberGeneratorForKeySelection() % FIRST_LEVEL_ENTRY_COUNT]; - const int nextLevelBitmapEntryIndex = trieMap.getNextLevelBitmapEntryIndex(firstLevelKey); - EXPECT_NE(TrieMap::INVALID_INDEX, nextLevelBitmapEntryIndex); - EXPECT_TRUE(trieMap.put(key, value, nextLevelBitmapEntryIndex)); - secondLevelKeys.push_back(std::make_pair(firstLevelKey, key)); - twoLevelMap[firstLevelKey][key] = value; - } - - for (int i = 0; i < THIRD_LEVEL_ENTRY_COUNT; ++i) { - const int key = keyRandomNumberGenerator(); - const uint64_t value = valueRandomNumberGenerator(); - const std::pair secondLevelKey = - secondLevelKeys[randomNumberGeneratorForKeySelection() % SECOND_LEVEL_ENTRY_COUNT]; - const int secondLevel = trieMap.getNextLevelBitmapEntryIndex(secondLevelKey.first); - EXPECT_NE(TrieMap::INVALID_INDEX, secondLevel); - const int thirdLevel = trieMap.getNextLevelBitmapEntryIndex( - secondLevelKey.second, secondLevel); - EXPECT_NE(TrieMap::INVALID_INDEX, thirdLevel); - EXPECT_TRUE(trieMap.put(key, value, thirdLevel)); - threeLevelMap[secondLevelKey.first][secondLevelKey.second][key] = value; - } - - for (const auto &firstLevelEntry : firstLevelEntries) { - EXPECT_EQ(firstLevelEntry.second, trieMap.getRoot(firstLevelEntry.first).mValue); - } - - for (const auto &firstLevelEntry : twoLevelMap) { - const int secondLevel = trieMap.getNextLevelBitmapEntryIndex(firstLevelEntry.first); - EXPECT_NE(TrieMap::INVALID_INDEX, secondLevel); - for (const auto &secondLevelEntry : firstLevelEntry.second) { - EXPECT_EQ(secondLevelEntry.second, - trieMap.get(secondLevelEntry.first, secondLevel).mValue); - } - } - - for (const auto &firstLevelEntry : threeLevelMap) { - const int secondLevel = trieMap.getNextLevelBitmapEntryIndex(firstLevelEntry.first); - EXPECT_NE(TrieMap::INVALID_INDEX, secondLevel); - for (const auto &secondLevelEntry : firstLevelEntry.second) { - const int thirdLevel = - trieMap.getNextLevelBitmapEntryIndex(secondLevelEntry.first, secondLevel); - EXPECT_NE(TrieMap::INVALID_INDEX, thirdLevel); - for (const auto &thirdLevelEntry : secondLevelEntry.second) { - EXPECT_EQ(thirdLevelEntry.second, - trieMap.get(thirdLevelEntry.first, thirdLevel).mValue); - } - } - } - - // Iteration - for (const auto &firstLevelEntry : trieMap.getEntriesInRootLevel()) { - EXPECT_EQ(trieMap.getRoot(firstLevelEntry.key()).mValue, firstLevelEntry.value()); - EXPECT_EQ(firstLevelEntries[firstLevelEntry.key()], firstLevelEntry.value()); - firstLevelEntries.erase(firstLevelEntry.key()); - for (const auto &secondLevelEntry : firstLevelEntry.getEntriesInNextLevel()) { - EXPECT_EQ(twoLevelMap[firstLevelEntry.key()][secondLevelEntry.key()], - secondLevelEntry.value()); - twoLevelMap[firstLevelEntry.key()].erase(secondLevelEntry.key()); - for (const auto &thirdLevelEntry : secondLevelEntry.getEntriesInNextLevel()) { - EXPECT_EQ(threeLevelMap[firstLevelEntry.key()][secondLevelEntry.key()] - [thirdLevelEntry.key()], thirdLevelEntry.value()); - threeLevelMap[firstLevelEntry.key()][secondLevelEntry.key()].erase( - thirdLevelEntry.key()); - } - } - } - - // Ensure all entries have been traversed. - EXPECT_TRUE(firstLevelEntries.empty()); - for (const auto &secondLevelEntry : twoLevelMap) { - EXPECT_TRUE(secondLevelEntry.second.empty()); - } - for (const auto &secondLevelEntry : threeLevelMap) { - for (const auto &thirdLevelEntry : secondLevelEntry.second) { - EXPECT_TRUE(thirdLevelEntry.second.empty()); - } - } -} - -TEST(TrieMapTest, TestIteration) { - static const int ELEMENT_COUNT = 200000; - TrieMap trieMap; - std::unordered_map testKeyValuePairs; - - // Use the uniform integer distribution [S_INT_MIN, S_INT_MAX]. - std::uniform_int_distribution keyDistribution(S_INT_MIN, S_INT_MAX); - auto keyRandomNumberGenerator = std::bind(keyDistribution, std::mt19937()); - - // Use the uniform distribution [0, TrieMap::MAX_VALUE]. - std::uniform_int_distribution valueDistribution(0, TrieMap::MAX_VALUE); - auto valueRandomNumberGenerator = std::bind(valueDistribution, std::mt19937()); - for (int i = 0; i < ELEMENT_COUNT; ++i) { - const int key = keyRandomNumberGenerator(); - const uint64_t value = valueRandomNumberGenerator(); - EXPECT_TRUE(trieMap.putRoot(key, value)); - testKeyValuePairs[key] = value; - } - for (const auto &entry : trieMap.getEntriesInRootLevel()) { - EXPECT_EQ(trieMap.getRoot(entry.key()).mValue, entry.value()); - EXPECT_EQ(testKeyValuePairs[entry.key()], entry.value()); - testKeyValuePairs.erase(entry.key()); - } - EXPECT_TRUE(testKeyValuePairs.empty()); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/suggest/core/dicnode/dic_node_pool_test.cpp b/app/src/main/jni/tests/suggest/core/dicnode/dic_node_pool_test.cpp deleted file mode 100644 index 854efdfe..00000000 --- a/app/src/main/jni/tests/suggest/core/dicnode/dic_node_pool_test.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 - -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/app/src/main/jni/tests/suggest/core/layout/geometry_utils_test.cpp b/app/src/main/jni/tests/suggest/core/layout/geometry_utils_test.cpp deleted file mode 100644 index f5f89ede..00000000 --- a/app/src/main/jni/tests/suggest/core/layout/geometry_utils_test.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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/layout/geometry_utils.h" - -#include - -namespace latinime { -namespace { - -::testing::AssertionResult ExpectAngleDiffEq(const char* expectedExpression, - const char* actualExpression, float expected, float actual) { - if (actual < 0.0f || M_PI_F < actual) { - return ::testing::AssertionFailure() - << "Must be in the range of [0.0f, M_PI_F]." - << " expected: " << expected - << " actual: " << actual; - } - return ::testing::internal::CmpHelperFloatingPointEQ( - expectedExpression, actualExpression, expected, actual); -} - -#define EXPECT_ANGLE_DIFF_EQ(expected, actual) \ - EXPECT_PRED_FORMAT2(ExpectAngleDiffEq, expected, actual); - -TEST(GeometryUtilsTest, testSquareFloat) { - const float test_data[] = { 0.0f, 1.0f, 123.456f, -1.0f, -9876.54321f }; - for (const float value : test_data) { - EXPECT_FLOAT_EQ(value * value, GeometryUtils::SQUARE_FLOAT(value)); - } -} - -TEST(GeometryUtilsTest, testGetAngle) { - EXPECT_FLOAT_EQ(0.0f, GeometryUtils::getAngle(0, 0, 0, 0)); - EXPECT_FLOAT_EQ(0.0f, GeometryUtils::getAngle(100, -10, 100, -10)); - - EXPECT_FLOAT_EQ(M_PI_F / 4.0f, GeometryUtils::getAngle(1, 1, 0, 0)); - EXPECT_FLOAT_EQ(M_PI_F, GeometryUtils::getAngle(-1, 0, 0, 0)); - - EXPECT_FLOAT_EQ(GeometryUtils::getAngle(0, 0, -1, 0), GeometryUtils::getAngle(1, 0, 0, 0)); - EXPECT_FLOAT_EQ(GeometryUtils::getAngle(1, 2, 3, 4), - GeometryUtils::getAngle(100, 200, 300, 400)); -} - -TEST(GeometryUtilsTest, testGetAngleDiff) { - EXPECT_ANGLE_DIFF_EQ(0.0f, GeometryUtils::getAngleDiff(0.0f, 0.0f)); - EXPECT_ANGLE_DIFF_EQ(0.0f, GeometryUtils::getAngleDiff(10000.0f, 10000.0f)); - EXPECT_ANGLE_DIFF_EQ(ROUND_FLOAT_10000(M_PI_F), - GeometryUtils::getAngleDiff(0.0f, M_PI_F)); - EXPECT_ANGLE_DIFF_EQ(ROUND_FLOAT_10000(M_PI_F / 6.0f), - GeometryUtils::getAngleDiff(M_PI_F / 3.0f, M_PI_F / 2.0f)); - EXPECT_ANGLE_DIFF_EQ(ROUND_FLOAT_10000(M_PI_F / 2.0f), - GeometryUtils::getAngleDiff(0.0f, M_PI_F * 1.5f)); - EXPECT_ANGLE_DIFF_EQ(0.0f, GeometryUtils::getAngleDiff(0.0f, M_PI_F * 1024.0f)); - EXPECT_ANGLE_DIFF_EQ(0.0f, GeometryUtils::getAngleDiff(-M_PI_F, M_PI_F)); -} - -TEST(GeometryUtilsTest, testGetDistanceInt) { - EXPECT_EQ(0, GeometryUtils::getDistanceInt(0, 0, 0, 0)); - EXPECT_EQ(0, GeometryUtils::getAngle(100, -10, 100, -10)); - - EXPECT_EQ(5, GeometryUtils::getDistanceInt(0, 0, 5, 0)); - EXPECT_EQ(5, GeometryUtils::getDistanceInt(0, 0, 3, 4)); - EXPECT_EQ(5, GeometryUtils::getDistanceInt(0, -4, 3, 0)); - EXPECT_EQ(5, GeometryUtils::getDistanceInt(0, 0, -3, -4)); - EXPECT_EQ(500, GeometryUtils::getDistanceInt(0, 0, 300, -400)); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/suggest/core/layout/normal_distribution_2d_test.cpp b/app/src/main/jni/tests/suggest/core/layout/normal_distribution_2d_test.cpp deleted file mode 100644 index 1d6a27c4..00000000 --- a/app/src/main/jni/tests/suggest/core/layout/normal_distribution_2d_test.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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/layout/normal_distribution_2d.h" - -#include - -#include - -namespace latinime { -namespace { - -static const float ORIGIN_X = 0.0f; -static const float ORIGIN_Y = 0.0f; -static const float LARGE_STANDARD_DEVIATION = 100.0f; -static const float SMALL_STANDARD_DEVIATION = 10.0f; -static const float ZERO_RADIAN = 0.0f; - -TEST(NormalDistribution2DTest, ProbabilityDensity) { - const NormalDistribution2D distribution(ORIGIN_X, LARGE_STANDARD_DEVIATION, ORIGIN_Y, - SMALL_STANDARD_DEVIATION, ZERO_RADIAN); - - static const float SMALL_COORDINATE = 10.0f; - static const float LARGE_COORDINATE = 20.0f; - // The probability density of the point near the distribution center is larger than the - // probability density of the point that is far from distribution center. - EXPECT_GE(distribution.getProbabilityDensity(SMALL_COORDINATE, SMALL_COORDINATE), - distribution.getProbabilityDensity(LARGE_COORDINATE, LARGE_COORDINATE)); - // The probability density of the point shifted toward the direction that has larger standard - // deviation is larger than the probability density of the point shifted towards another - // direction. - EXPECT_GE(distribution.getProbabilityDensity(LARGE_COORDINATE, SMALL_COORDINATE), - distribution.getProbabilityDensity(SMALL_COORDINATE, LARGE_COORDINATE)); -} - -TEST(NormalDistribution2DTest, Rotate) { - static const float COORDINATES[] = {0.0f, 10.0f, 100.0f, -20.0f}; - static const float EPSILON = 0.01f; - const NormalDistribution2D distribution(ORIGIN_X, LARGE_STANDARD_DEVIATION, ORIGIN_Y, - SMALL_STANDARD_DEVIATION, ZERO_RADIAN); - const NormalDistribution2D rotatedDistribution(ORIGIN_X, LARGE_STANDARD_DEVIATION, ORIGIN_Y, - SMALL_STANDARD_DEVIATION, M_PI_4); - for (const float x : COORDINATES) { - for (const float y : COORDINATES) { - // The probability density of the rotated distribution at the point and the probability - // density of the original distribution at the rotated point are the same. - const float probabilityDensity0 = distribution.getProbabilityDensity(x, y); - const float probabilityDensity1 = rotatedDistribution.getProbabilityDensity(-y, x); - EXPECT_NEAR(probabilityDensity0, probabilityDensity1, EPSILON); - } - } -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy_test.cpp b/app/src/main/jni/tests/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy_test.cpp deleted file mode 100644 index d1341796..00000000 --- a/app/src/main/jni/tests/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy_test.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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/utils/damerau_levenshtein_edit_distance_policy.h" - -#include - -#include - -#include "suggest/policyimpl/utils/edit_distance.h" -#include "utils/int_array_view.h" - -namespace latinime { -namespace { - -TEST(DamerauLevenshteinEditDistancePolicyTest, TestConstructPolicy) { - const std::vector codePoints0 = { 0x20, 0x40, 0x60 }; - const std::vector codePoints1 = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 }; - DamerauLevenshteinEditDistancePolicy policy(codePoints0.data(), codePoints0.size(), - codePoints1.data(), codePoints1.size()); - - EXPECT_EQ(static_cast(codePoints0.size()), policy.getString0Length()); - EXPECT_EQ(static_cast(codePoints1.size()), policy.getString1Length()); -} - -float getEditDistance(const std::vector &codePoints0, const std::vector &codePoints1) { - DamerauLevenshteinEditDistancePolicy policy(codePoints0.data(), codePoints0.size(), - codePoints1.data(), codePoints1.size()); - return EditDistance::getEditDistance(&policy); -} - -TEST(DamerauLevenshteinEditDistancePolicyTest, TestEditDistance) { - EXPECT_FLOAT_EQ(0.0f, getEditDistance({}, {})); - EXPECT_FLOAT_EQ(0.0f, getEditDistance({ 1 }, { 1 })); - EXPECT_FLOAT_EQ(0.0f, getEditDistance({ 1, 2, 3 }, { 1, 2, 3 })); - - EXPECT_FLOAT_EQ(1.0f, getEditDistance({ 1 }, { })); - EXPECT_FLOAT_EQ(1.0f, getEditDistance({}, { 100 })); - EXPECT_FLOAT_EQ(5.0f, getEditDistance({}, { 1, 2, 3, 4, 5 })); - - EXPECT_FLOAT_EQ(1.0f, getEditDistance({ 0 }, { 100 })); - EXPECT_FLOAT_EQ(5.0f, getEditDistance({ 1, 2, 3, 4, 5 }, { 11, 12, 13, 14, 15 })); - - EXPECT_FLOAT_EQ(1.0f, getEditDistance({ 1 }, { 1, 2 })); - EXPECT_FLOAT_EQ(2.0f, getEditDistance({ 1, 2 }, { 0, 1, 2, 3 })); - EXPECT_FLOAT_EQ(2.0f, getEditDistance({ 0, 1, 2, 3 }, { 1, 2 })); - - EXPECT_FLOAT_EQ(1.0f, getEditDistance({ 1, 2 }, { 2, 1 })); - EXPECT_FLOAT_EQ(2.0f, getEditDistance({ 1, 2, 3, 4 }, { 2, 1, 4, 3 })); -} -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/utils/autocorrection_threshold_utils_test.cpp b/app/src/main/jni/tests/utils/autocorrection_threshold_utils_test.cpp deleted file mode 100644 index cc8db700..00000000 --- a/app/src/main/jni/tests/utils/autocorrection_threshold_utils_test.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 "utils/autocorrection_threshold_utils.h" - -#include - -#include - -namespace latinime { -namespace { - -int CalcEditDistance(const std::vector &before, - const std::vector &after) { - return AutocorrectionThresholdUtils::editDistance( - &before[0], before.size(), &after[0], after.size()); -} - -TEST(AutocorrectionThresholdUtilsTest, SameData) { - EXPECT_EQ(0, CalcEditDistance({1}, {1})); - EXPECT_EQ(0, CalcEditDistance({2, 2}, {2, 2})); - EXPECT_EQ(0, CalcEditDistance({3, 3, 3}, {3, 3, 3})); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/utils/char_utils_test.cpp b/app/src/main/jni/tests/utils/char_utils_test.cpp deleted file mode 100644 index 01d53404..00000000 --- a/app/src/main/jni/tests/utils/char_utils_test.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 "utils/char_utils.h" - -#include - -#include "defines.h" - -namespace latinime { -namespace { - -TEST(CharUtilsTest, TestIsAsciiUpper) { - EXPECT_TRUE(CharUtils::isAsciiUpper('A')); - EXPECT_TRUE(CharUtils::isAsciiUpper('Z')); - EXPECT_FALSE(CharUtils::isAsciiUpper('a')); - EXPECT_FALSE(CharUtils::isAsciiUpper('z')); - EXPECT_FALSE(CharUtils::isAsciiUpper('@')); - EXPECT_FALSE(CharUtils::isAsciiUpper(' ')); - EXPECT_FALSE(CharUtils::isAsciiUpper(0x00C0 /* LATIN CAPITAL LETTER A WITH GRAVE */)); - EXPECT_FALSE(CharUtils::isAsciiUpper(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */)); - EXPECT_FALSE(CharUtils::isAsciiUpper(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */)); - EXPECT_FALSE(CharUtils::isAsciiUpper(0x0410 /* CYRILLIC CAPITAL LETTER A */)); - EXPECT_FALSE(CharUtils::isAsciiUpper(0x0430 /* CYRILLIC SMALL LETTER A */)); - EXPECT_FALSE(CharUtils::isAsciiUpper(0x3042 /* HIRAGANA LETTER A */)); - EXPECT_FALSE(CharUtils::isAsciiUpper(0x1F36A /* COOKIE */)); -} - -TEST(CharUtilsTest, TestToLowerCase) { - EXPECT_EQ('a', CharUtils::toLowerCase('A')); - EXPECT_EQ('z', CharUtils::toLowerCase('Z')); - EXPECT_EQ('a', CharUtils::toLowerCase('a')); - EXPECT_EQ('z', CharUtils::toLowerCase('z')); - EXPECT_EQ('@', CharUtils::toLowerCase('@')); - EXPECT_EQ(' ', CharUtils::toLowerCase(' ')); - EXPECT_EQ(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */, - CharUtils::toLowerCase(0x00C0 /* LATIN CAPITAL LETTER A WITH GRAVE */)); - EXPECT_EQ(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */, - CharUtils::toLowerCase(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */)); - EXPECT_EQ(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */, - CharUtils::toLowerCase(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */)); - EXPECT_EQ(0x0430 /* CYRILLIC SMALL LETTER A */, - CharUtils::toLowerCase(0x0410 /* CYRILLIC CAPITAL LETTER A */)); - EXPECT_EQ(0x0430 /* CYRILLIC SMALL LETTER A */, - CharUtils::toLowerCase(0x0430 /* CYRILLIC SMALL LETTER A */)); - EXPECT_EQ(0x3042 /* HIRAGANA LETTER A */, - CharUtils::toLowerCase(0x3042 /* HIRAGANA LETTER A */)); - EXPECT_EQ(0x1F36A /* COOKIE */, CharUtils::toLowerCase(0x1F36A /* COOKIE */)); -} - -TEST(CharUtilsTest, TestToBaseLowerCase) { - EXPECT_EQ('a', CharUtils::toBaseLowerCase('A')); - EXPECT_EQ('z', CharUtils::toBaseLowerCase('Z')); - EXPECT_EQ('a', CharUtils::toBaseLowerCase('a')); - EXPECT_EQ('z', CharUtils::toBaseLowerCase('z')); - EXPECT_EQ('@', CharUtils::toBaseLowerCase('@')); - EXPECT_EQ(' ', CharUtils::toBaseLowerCase(' ')); - EXPECT_EQ('a', CharUtils::toBaseLowerCase(0x00C0 /* LATIN CAPITAL LETTER A WITH GRAVE */)); - EXPECT_EQ('a', CharUtils::toBaseLowerCase(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */)); - EXPECT_EQ(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */, - CharUtils::toBaseLowerCase(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */)); - EXPECT_EQ(0x0430 /* CYRILLIC SMALL LETTER A */, - CharUtils::toBaseLowerCase(0x0410 /* CYRILLIC CAPITAL LETTER A */)); - EXPECT_EQ(0x0430 /* CYRILLIC SMALL LETTER A */, - CharUtils::toBaseLowerCase(0x0430 /* CYRILLIC SMALL LETTER A */)); - EXPECT_EQ(0x3042 /* HIRAGANA LETTER A */, - CharUtils::toBaseLowerCase(0x3042 /* HIRAGANA LETTER A */)); - EXPECT_EQ(0x1F36A /* COOKIE */, CharUtils::toBaseLowerCase(0x1F36A /* COOKIE */)); -} - -TEST(CharUtilsTest, TestToBaseCodePoint) { - EXPECT_EQ('A', CharUtils::toBaseCodePoint('A')); - EXPECT_EQ('Z', CharUtils::toBaseCodePoint('Z')); - EXPECT_EQ('a', CharUtils::toBaseCodePoint('a')); - EXPECT_EQ('z', CharUtils::toBaseCodePoint('z')); - EXPECT_EQ('@', CharUtils::toBaseCodePoint('@')); - EXPECT_EQ(' ', CharUtils::toBaseCodePoint(' ')); - EXPECT_EQ('A', CharUtils::toBaseCodePoint(0x00C0 /* LATIN CAPITAL LETTER A WITH GRAVE */)); - EXPECT_EQ('a', CharUtils::toBaseCodePoint(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */)); - EXPECT_EQ(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */, - CharUtils::toBaseLowerCase(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */)); - EXPECT_EQ(0x0410 /* CYRILLIC CAPITAL LETTER A */, - CharUtils::toBaseCodePoint(0x0410 /* CYRILLIC CAPITAL LETTER A */)); - EXPECT_EQ(0x0430 /* CYRILLIC SMALL LETTER A */, - CharUtils::toBaseCodePoint(0x0430 /* CYRILLIC SMALL LETTER A */)); - EXPECT_EQ(0x3042 /* HIRAGANA LETTER A */, - CharUtils::toBaseCodePoint(0x3042 /* HIRAGANA LETTER A */)); - EXPECT_EQ(0x1F36A /* COOKIE */, CharUtils::toBaseCodePoint(0x1F36A /* COOKIE */)); -} - -TEST(CharUtilsTest, TestIsIntentionalOmissionCodePoint) { - EXPECT_TRUE(CharUtils::isIntentionalOmissionCodePoint('\'')); - EXPECT_TRUE(CharUtils::isIntentionalOmissionCodePoint('-')); - EXPECT_FALSE(CharUtils::isIntentionalOmissionCodePoint('a')); - EXPECT_FALSE(CharUtils::isIntentionalOmissionCodePoint('?')); - EXPECT_FALSE(CharUtils::isIntentionalOmissionCodePoint('/')); -} - -TEST(CharUtilsTest, TestIsInUnicodeSpace) { - EXPECT_FALSE(CharUtils::isInUnicodeSpace(NOT_A_CODE_POINT)); - EXPECT_FALSE(CharUtils::isInUnicodeSpace(CODE_POINT_BEGINNING_OF_SENTENCE)); - EXPECT_TRUE(CharUtils::isInUnicodeSpace('a')); - EXPECT_TRUE(CharUtils::isInUnicodeSpace(0x0410 /* CYRILLIC CAPITAL LETTER A */)); - EXPECT_TRUE(CharUtils::isInUnicodeSpace(0x3042 /* HIRAGANA LETTER A */)); - EXPECT_TRUE(CharUtils::isInUnicodeSpace(0x1F36A /* COOKIE */)); -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/utils/int_array_view_test.cpp b/app/src/main/jni/tests/utils/int_array_view_test.cpp deleted file mode 100644 index 2fce633f..00000000 --- a/app/src/main/jni/tests/utils/int_array_view_test.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * 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 "utils/int_array_view.h" - -#include - -#include -#include - -namespace latinime { -namespace { - -TEST(IntArrayViewTest, TestAccess) { - const std::vector intVector = {3, 2, 1, 0, -1, -2}; - IntArrayView intArrayView(intVector); - EXPECT_EQ(intVector.size(), intArrayView.size()); - for (int i = 0; i < static_cast(intVector.size()); ++i) { - EXPECT_EQ(intVector[i], intArrayView[i]); - } -} - -TEST(IntArrayViewTest, TestIteration) { - const std::vector intVector = {3, 2, 1, 0, -1, -2}; - IntArrayView intArrayView(intVector); - size_t expectedIndex = 0; - for (const int element : intArrayView) { - EXPECT_EQ(intVector[expectedIndex], element); - ++expectedIndex; - } - EXPECT_EQ(expectedIndex, intArrayView.size()); -} - -TEST(IntArrayViewTest, TestConstructFromArray) { - const size_t ARRAY_SIZE = 100; - std::array intArray; - const auto intArrayView = IntArrayView::fromArray(intArray); - EXPECT_EQ(ARRAY_SIZE, intArrayView.size()); -} - -TEST(IntArrayViewTest, TestConstructFromObject) { - const int object = 10; - const auto intArrayView = IntArrayView::singleElementView(&object); - EXPECT_EQ(1u, intArrayView.size()); - EXPECT_EQ(object, intArrayView[0]); -} - -TEST(IntArrayViewTest, TestContains) { - EXPECT_FALSE(IntArrayView().contains(0)); - EXPECT_FALSE(IntArrayView().contains(1)); - - const std::vector intVector = {3, 2, 1, 0, -1, -2}; - IntArrayView intArrayView(intVector); - EXPECT_TRUE(intArrayView.contains(0)); - EXPECT_TRUE(intArrayView.contains(3)); - EXPECT_TRUE(intArrayView.contains(-2)); - EXPECT_FALSE(intArrayView.contains(-3)); - EXPECT_FALSE(intArrayView.limit(0).contains(3)); -} - -TEST(IntArrayViewTest, TestLimit) { - const std::vector intVector = {3, 2, 1, 0, -1, -2}; - IntArrayView intArrayView(intVector); - - EXPECT_TRUE(intArrayView.limit(0).empty()); - EXPECT_EQ(intArrayView.size(), intArrayView.limit(intArrayView.size()).size()); - EXPECT_EQ(intArrayView.size(), intArrayView.limit(1000).size()); - - IntArrayView subView = intArrayView.limit(4); - EXPECT_EQ(4u, subView.size()); - for (size_t i = 0; i < subView.size(); ++i) { - EXPECT_EQ(intVector[i], subView[i]); - } -} - -TEST(IntArrayViewTest, TestSkip) { - const std::vector intVector = {3, 2, 1, 0, -1, -2}; - IntArrayView intArrayView(intVector); - - EXPECT_TRUE(intArrayView.skip(intVector.size()).empty()); - EXPECT_TRUE(intArrayView.skip(intVector.size() + 1).empty()); - EXPECT_EQ(intArrayView.size(), intArrayView.skip(0).size()); - EXPECT_EQ(intArrayView.size(), intArrayView.limit(1000).size()); - - static const size_t SKIP_COUNT = 2; - IntArrayView subView = intArrayView.skip(SKIP_COUNT); - EXPECT_EQ(intVector.size() - SKIP_COUNT, subView.size()); - for (size_t i = 0; i < subView.size(); ++i) { - EXPECT_EQ(intVector[i + SKIP_COUNT], subView[i]); - } -} - -TEST(IntArrayViewTest, TestCopyToArray) { - // "{{" to suppress warning. - std::array buffer = {{10, 20, 30, 40, 50, 60, 70}}; - const std::vector intVector = {3, 2, 1, 0, -1, -2}; - IntArrayView intArrayView(intVector); - intArrayView.limit(0).copyToArray(&buffer, 0); - EXPECT_EQ(10, buffer[0]); - EXPECT_EQ(20, buffer[1]); - intArrayView.limit(1).copyToArray(&buffer, 0); - EXPECT_EQ(intVector[0], buffer[0]); - EXPECT_EQ(20, buffer[1]); - intArrayView.limit(1).copyToArray(&buffer, 1); - EXPECT_EQ(intVector[0], buffer[0]); - EXPECT_EQ(intVector[0], buffer[1]); - intArrayView.copyToArray(&buffer, 0); - for (size_t i = 0; i < intArrayView.size(); ++i) { - EXPECT_EQ(intVector[i], buffer[i]); - } - EXPECT_EQ(70, buffer[6]); -} - -TEST(IntArrayViewTest, TestFirstOrDefault) { - const std::vector intVector = {3, 2, 1, 0, -1, -2}; - IntArrayView intArrayView(intVector); - - EXPECT_EQ(3, intArrayView.firstOrDefault(10)); - EXPECT_EQ(10, intArrayView.limit(0).firstOrDefault(10)); - EXPECT_EQ(-10, intArrayView.limit(0).firstOrDefault(-10)); - EXPECT_EQ(10, intArrayView.skip(6).firstOrDefault(10)); -} - -TEST(IntArrayViewTest, TestLastOrDefault) { - const std::vector intVector = {3, 2, 1, 0, -1, -2}; - IntArrayView intArrayView(intVector); - - EXPECT_EQ(-2, intArrayView.lastOrDefault(10)); - EXPECT_EQ(10, intArrayView.limit(0).lastOrDefault(10)); - EXPECT_EQ(-10, intArrayView.limit(0).lastOrDefault(-10)); - EXPECT_EQ(10, intArrayView.skip(6).lastOrDefault(10)); -} - -TEST(IntArrayViewTest, TestToVector) { - const std::vector intVector = {3, 2, 1, 0, -1, -2}; - IntArrayView intArrayView(intVector); - EXPECT_EQ(intVector, intArrayView.toVector()); - EXPECT_EQ(std::vector(), CodePointArrayView().toVector()); -} - -TEST(IntArrayViewTest, TestSplit) { - EXPECT_TRUE(IntArrayView().split(0, 0).empty()); - { - const auto intArrayViews = IntArrayView().split(0, 1); - EXPECT_EQ(1u, intArrayViews.size()); - EXPECT_TRUE(intArrayViews[0].empty()); - } - { - const auto intArrayViews = IntArrayView().split(0, 100); - EXPECT_EQ(1u, intArrayViews.size()); - EXPECT_TRUE(intArrayViews[0].empty()); - } - - const std::vector intVector = {1, 2, 3, 3, 2, 3}; - const IntArrayView intArrayView(intVector); - { - const auto intArrayViews = intArrayView.split(2); - EXPECT_EQ(3u, intArrayViews.size()); - EXPECT_EQ(std::vector({1}), intArrayViews[0].toVector()); - EXPECT_EQ(std::vector({3, 3}), intArrayViews[1].toVector()); - EXPECT_EQ(std::vector({3}), intArrayViews[2].toVector()); - } - { - const auto intArrayViews = intArrayView.split(2, 2); - EXPECT_EQ(2u, intArrayViews.size()); - EXPECT_EQ(std::vector({1}), intArrayViews[0].toVector()); - EXPECT_EQ(std::vector({3, 3, 2, 3}), intArrayViews[1].toVector()); - } - { - const auto intArrayViews = intArrayView.split(2, 1); - EXPECT_EQ(1u, intArrayViews.size()); - EXPECT_EQ(intVector, intArrayViews[0].toVector()); - } - { - const auto intArrayViews = intArrayView.split(2, 0); - EXPECT_EQ(0u, intArrayViews.size()); - } - { - const auto intArrayViews = intArrayView.split(3); - EXPECT_EQ(4u, intArrayViews.size()); - EXPECT_EQ(std::vector({1, 2}), intArrayViews[0].toVector()); - EXPECT_EQ(std::vector(), intArrayViews[1].toVector()); - EXPECT_EQ(std::vector({2}), intArrayViews[2].toVector()); - EXPECT_EQ(std::vector(), intArrayViews[3].toVector()); - } -} - -} // namespace -} // namespace latinime diff --git a/app/src/main/jni/tests/utils/time_keeper_test.cpp b/app/src/main/jni/tests/utils/time_keeper_test.cpp deleted file mode 100644 index 3f54b91f..00000000 --- a/app/src/main/jni/tests/utils/time_keeper_test.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 "utils/time_keeper.h" - -#include - -namespace latinime { -namespace { - -TEST(TimeKeeperTest, TestTestMode) { - TimeKeeper::setCurrentTime(); - const int startTime = TimeKeeper::peekCurrentTime(); - static const int TEST_CURRENT_TIME = 100; - TimeKeeper::startTestModeWithForceCurrentTime(TEST_CURRENT_TIME); - EXPECT_EQ(TEST_CURRENT_TIME, TimeKeeper::peekCurrentTime()); - TimeKeeper::setCurrentTime(); - EXPECT_EQ(TEST_CURRENT_TIME, TimeKeeper::peekCurrentTime()); - TimeKeeper::stopTestMode(); - TimeKeeper::setCurrentTime(); - EXPECT_LE(startTime, TimeKeeper::peekCurrentTime()); -} - -} // namespace -} // namespace latinime