Pārlūkot izejas kodu

完成对bloomfilter的创建和计算部分的测试,测试通过

Gogs 3 mēneši atpakaļ
vecāks
revīzija
7328b71303

BIN
lib/tests/filter_test


+ 48 - 0
lib/tests/filter_test.cpp

@@ -0,0 +1,48 @@
+#define NANXING_DEBUG_
+#include"../extend/filter.h"
+#include<cstdlib>
+#include<cmath>
+#include<cstdint>
+uint64_t insert_n[10]={4000,1024,57001,7421,3731,24671,19937,134561,1944416,16419};
+double insert_p[10]={0.1,0.1,0.4,0.1,0.1,0.1,0.1,0.1,0.1,0.1};
+uint64_t result_k[10]={3,3,1,3,3,3,3,3,3,3};
+uint64_t result_m[10]={19171,4908,108709,35566,17881,118237,94549,644888,9318671,78689};
+
+//由于这些都是一次性的,直接写成lambda表达式
+nanxing_extend::FilterPolicy<int> test_filter{};
+auto creat_bloomfilter=[](int i)->nanxing_extend::FilterPolicy<int>*{
+    
+    return test_filter.creat_Bloomfilter(insert_n[i],insert_p[i]);
+
+};
+auto bloomfilter_creater_test=[]()
+{
+    for(int i=0;i<10;i++)
+    {
+        nanxing_extend::FilterPolicy<int>* bloomfilter=creat_bloomfilter(i);
+        bloomfilter->init_filter();
+        if((bloomfilter->get_k())!=result_k[i]||(bloomfilter->get_m())!=result_m[i])
+        {
+            if(std::abs(static_cast<long long>(bloomfilter->get_m()-result_m[i]))<15&&bloomfilter->get_k()==result_k[i])         //这里为了测试用了g++特定的数据类型
+            {
+                continue;
+            }
+            std::cerr<<"error"<<std::endl;
+            std::cout<<"i="<<i<<std::endl;
+            std::cout<<"n="<<insert_n[i]<<std::endl;
+            std::cout<<"p="<<insert_p[i]<<std::endl;
+            std::cout<<"k="<<result_k[i]<<std::endl;
+            std::cout<<"parameter.k="<<bloomfilter->get_k()<<std::endl;
+            std::cout<<"m="<<result_m[i]<<std::endl;  
+            std::cout<<"parameterm="<<bloomfilter->get_m()<<std::endl;
+            goto LOOP;   
+        }
+    }
+    std::cout<<"bloomfilter_creater_test successful"<<std::endl;
+LOOP:
+};
+
+int main()
+{
+    bloomfilter_creater_test();
+}

BIN
lib/tests/randomfunctiontest


+ 42 - 0
lib/tests/randomfunctiontest.cpp

@@ -0,0 +1,42 @@
+//对随机数相关算法的时间分布性进行验证
+#include<iostream>
+
+//线性同余哈希函数的散布
+void line_hash(double n)
+{
+    double result[10]={0};
+    for(int i=0;i<n;i++)
+    {
+        result[((i*52223)+94399)%10]++;
+    }
+    double count=0;
+    for(int i=0;i<10;i++)
+    {
+        count+=result[i];
+        std::cout<<result[i]<<std::endl;
+    }
+    for(int i=0;i<10;i++)
+    {
+        std::cout<<double(result[i]/count)<<std::endl;
+    }
+}
+auto line_hash_text=[]->void{
+    while(1)
+    {    
+        std::cout<<"please input n:"<<std::endl;
+        int n=0;
+        if(n==-1)
+        {
+            break;
+        }
+        std::cin>>n;
+        line_hash(n);
+    }
+};
+//测试结果证明线性混合同余有很好的随机性
+
+
+int main()
+{
+    line_hash_text();
+}

+ 1 - 0
lib/tests/skiplist_test.cpp

@@ -1,5 +1,6 @@
 #define _NANXING_TEST_
 #define _RANDOM_LIST_
+#define NANXING_DEBUG_
 #include"../extend/skiplist.h"
 #include"time.h"