00001
00002 #include "pointFilter.h"
00003
00004 bool testFilterRandomPart()
00005 {
00006 PointFilterKey key(" ( 14, 5, true, 5) " );
00007
00008
00009 PointFilterRule rule(" [( 14, 5, true, 5),30] ");
00010 CFPointFilter pf( CFilterStrategy::FilterRandomSync_Strategy_s,"pointFilter");
00011
00012 int filteRate;
00013
00014
00015
00016
00017 pf.addFilterRule(rule);
00018
00019 int countPassed=0;
00020
00021 int passedFilterRate=30;
00022 int maxTrials=300;
00023 for (int i=0;i<maxTrials; i++)
00024 {
00025 if (pf.pointPassedFilter(14,5,true,5))
00026 countPassed++;
00027 }
00028 std::cerr << " countPassed-maxTrials*1.0/passedFilterRate = " << abs(countPassed-maxTrials*1.0/passedFilterRate) << std::endl;
00029 assert(abs(countPassed-maxTrials*1.0/passedFilterRate) < 10);
00030 }
00031
00032
00033 bool pointFilterTestPassed()
00034 {
00035
00036
00037
00038
00039 PointFilterKey key(" ( 14, 5, true, 5) " );
00040
00041
00042 PointFilterRule rule(" [( 14, 5, true, 5),1] ");
00043
00044 CFPointFilter pf( CFilterStrategy::FilterRandomSync_Strategy_s,"pointFilter");
00045
00046 int filteRate;
00047
00048
00049
00050
00051 pf.addFilterRule(rule);
00052
00053
00054
00055
00056
00057
00058
00059 assert(pf.pointPassedFilter(14,5,true,5));
00060
00061
00062 assert( pf.pointPassedFilter(15,5,true,5));
00063
00064
00065 PointFilterKey key2(" ( 15, 5, true, 5) " );
00066
00067
00068
00069 PointFilterRule rule2(key2, filteRate=3);
00070 CFPointFilter pf2(CFilterStrategy::FilterSaveFirst_Strategy_s,"pointFilter");
00071 CFPointFilter pfcopy(CFilterStrategy::FilterSaveFirst_Strategy_s,"pointFilter");
00072 pf2.addFilterRule(rule2);
00073
00074
00075 assert( pf2.pointPassedFilter(15,5,true,5));
00076 assert(! pf2.pointPassedFilter(15,5,true,5));
00077 assert(! pf2.pointPassedFilter(15,5,true,5));
00078 assert( pf2.pointPassedFilter(15,5,true,5));
00079 assert( pf2.pointPassedFilter(15,4,true,5));
00080 assert( pf2.pointPassedFilter(15,5,true,3));
00081 assert( pf2.pointPassedFilter(15,5,false,5));
00082
00083
00084
00085
00086
00087
00088 CFPointFilter pf3(" [( 16, 5, true, 5),4] , [(18,5,true,5),4]",CFilterStrategy::FilterSaveFirst_Strategy_s,"pointFilter");
00089
00090 assert( pf3.pointPassedFilter(16,5,true,5));
00091 assert(! pf3.pointPassedFilter(16,5,true,5));
00092
00093 CFilterStrategy strategy("randomStart");
00094 assert(strategy.integral()==CFilterStrategy::CF_FILTER_RANDOM_START);
00095
00096
00097
00098
00099
00100 return 1;
00101 }
00102
00103 int main()
00104 {
00105 testFilterRandomPart();
00106
00107 return ! pointFilterTestPassed();
00108
00109 }