aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2014-04-09 17:15:55 +0900
committerKeisuke Kuroyanagi <ksk@google.com>2014-04-09 17:15:55 +0900
commit111c05ff35763d6fe08a05ff341086de61498dc2 (patch)
treef35ba4caa4b0f5cc39c0512c43230973c4c8ead8
parent26c806620c26e048918624367ee624526613b0d2 (diff)
downloadlatinime-111c05ff35763d6fe08a05ff341086de61498dc2.tar.gz
latinime-111c05ff35763d6fe08a05ff341086de61498dc2.tar.xz
latinime-111c05ff35763d6fe08a05ff341086de61498dc2.zip
Add BloomFilterTest.
Change-Id: If97b9e9cc3bbaa4c7877991c11d7935626268ca3
-rw-r--r--native/jni/NativeFileList.mk1
-rw-r--r--native/jni/tests/suggest/core/dictionary/bloom_filter_test.cpp61
2 files changed, 62 insertions, 0 deletions
diff --git a/native/jni/NativeFileList.mk b/native/jni/NativeFileList.mk
index 1230150ea..70a6638fb 100644
--- a/native/jni/NativeFileList.mk
+++ b/native/jni/NativeFileList.mk
@@ -102,4 +102,5 @@ LATIN_IME_CORE_SRC_FILES := \
LATIN_IME_CORE_TEST_FILES := \
defines_test.cpp \
suggest/core/layout/normal_distribution_2d_test.cpp \
+ suggest/core/dictionary/bloom_filter_test.cpp \
utils/autocorrection_threshold_utils_test.cpp
diff --git a/native/jni/tests/suggest/core/dictionary/bloom_filter_test.cpp b/native/jni/tests/suggest/core/dictionary/bloom_filter_test.cpp
new file mode 100644
index 000000000..b1ab5e3ec
--- /dev/null
+++ b/native/jni/tests/suggest/core/dictionary/bloom_filter_test.cpp
@@ -0,0 +1,61 @@
+/*
+ * 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/dictionary/bloom_filter.h"
+
+#include <gtest/gtest.h>
+
+#include <cstdlib>
+#include <ctime>
+#include <unordered_set>
+#include <vector>
+
+namespace latinime {
+namespace {
+
+TEST(BloomFilterTest, TestFilter) {
+ static const int ELEMENT_COUNT = 1000;
+ srand(time(0));
+ std::vector<int> elements;
+ std::unordered_set<int> elementsThatHaveBeenSetInFilter;
+ for (int i = 0; i < ELEMENT_COUNT; ++i) {
+ elements.push_back(rand());
+ }
+ BloomFilter bloomFilter;
+ for (const int elem : elements) {
+ ASSERT_FALSE(bloomFilter.isInFilter(elem));
+ }
+ for (const int elem : elements) {
+ if (rand() % 2 == 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) {
+ ASSERT_TRUE(existsInFilter);
+ }
+ if (!existsInFilter) {
+ ASSERT_FALSE(hasBeenSetInFilter);
+ }
+ }
+}
+
+} // namespace
+} // namespace latinime