From 5ed44a51b923ba355aee1e724c09e83df085c730 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Fri, 26 Jun 2015 17:28:47 +0200 Subject: [PATCH 1/4] Distribution Rate test introduced --- test/libwhisper/bloomFilter.cpp | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/libwhisper/bloomFilter.cpp b/test/libwhisper/bloomFilter.cpp index 814990d52..386be2f6b 100644 --- a/test/libwhisper/bloomFilter.cpp +++ b/test/libwhisper/bloomFilter.cpp @@ -244,4 +244,53 @@ BOOST_AUTO_TEST_CASE(bloomFilterRaw) BOOST_REQUIRE(!f.contains(b00110111)); } +enum { DistributionTestSize = 8 }; + +void updateDistribution(FixedHash const& _h, unsigned* _distribution) +{ + unsigned bits = 0; + for (unsigned i = 0; i < DistributionTestSize; ++i) + if (_h[i]) + for (unsigned j = 0; j < 8; ++j) + if (_h[i] & c_powerOfTwoBitMmask[j]) + { + _distribution[i * 8 + j]++; + if (++bits >= TopicBloomFilterTest::BitsPerBloom) + return; + } +} + +BOOST_AUTO_TEST_CASE(distributionRate) +{ + cnote << "Testing Bloom Filter Distribution Rate..."; + + unsigned const c_arrSize = DistributionTestSize * 8; + unsigned distribution[c_arrSize]; + memset(distribution, 0, c_arrSize * sizeof(unsigned)); + Topic x(0xC0FFEE); // deterministic pseudorandom value + + for (unsigned i = 0; i < 22000; ++i) + { + x = sha3(x); + FixedHash h = x.template bloomPart(); + updateDistribution(h, distribution); + } + + unsigned average = 0; + for (unsigned i = 0; i < c_arrSize; ++i) + average += distribution[i]; + + average /= c_arrSize; + unsigned deviation = average / 10; // approx. 10% + unsigned maxAllowed = average + deviation; + unsigned minAllowed = average - deviation; + + for (unsigned i = 0; i < c_arrSize; ++i) + { + //cnote << i << ":" << distribution[i]; + BOOST_REQUIRE(distribution[i] > minAllowed); + BOOST_REQUIRE(distribution[i] < maxAllowed); + } +} + BOOST_AUTO_TEST_SUITE_END() From 6d37304d05a404c7ef7fd788f1b7f6ae49f5c90a Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Tue, 30 Jun 2015 18:31:00 +0200 Subject: [PATCH 2/4] style fix --- test/libwhisper/bloomFilter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libwhisper/bloomFilter.cpp b/test/libwhisper/bloomFilter.cpp index 386be2f6b..10e34df2d 100644 --- a/test/libwhisper/bloomFilter.cpp +++ b/test/libwhisper/bloomFilter.cpp @@ -244,7 +244,7 @@ BOOST_AUTO_TEST_CASE(bloomFilterRaw) BOOST_REQUIRE(!f.contains(b00110111)); } -enum { DistributionTestSize = 8 }; +static unsigned const DistributionTestSize = 8; void updateDistribution(FixedHash const& _h, unsigned* _distribution) { From ab86f1fdf2f8b9d649e96e29553014f561f4a119 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Wed, 1 Jul 2015 11:49:04 +0200 Subject: [PATCH 3/4] mega enhanced style fix --- test/libwhisper/bloomFilter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libwhisper/bloomFilter.cpp b/test/libwhisper/bloomFilter.cpp index 10e34df2d..f6c191abc 100644 --- a/test/libwhisper/bloomFilter.cpp +++ b/test/libwhisper/bloomFilter.cpp @@ -244,7 +244,7 @@ BOOST_AUTO_TEST_CASE(bloomFilterRaw) BOOST_REQUIRE(!f.contains(b00110111)); } -static unsigned const DistributionTestSize = 8; +static const unsigned DistributionTestSize = 8; void updateDistribution(FixedHash const& _h, unsigned* _distribution) { From a8197d867c860a50f5e2dfa9bc2dc59b56df58ea Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Wed, 1 Jul 2015 14:41:02 +0200 Subject: [PATCH 4/4] super mega enhanced update --- test/libwhisper/bloomFilter.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/libwhisper/bloomFilter.cpp b/test/libwhisper/bloomFilter.cpp index f6c191abc..299fd3f5b 100644 --- a/test/libwhisper/bloomFilter.cpp +++ b/test/libwhisper/bloomFilter.cpp @@ -245,8 +245,9 @@ BOOST_AUTO_TEST_CASE(bloomFilterRaw) } static const unsigned DistributionTestSize = 8; +static const unsigned TestArrSize = 8 * DistributionTestSize; -void updateDistribution(FixedHash const& _h, unsigned* _distribution) +void updateDistribution(FixedHash const& _h, array& _distribution) { unsigned bits = 0; for (unsigned i = 0; i < DistributionTestSize; ++i) @@ -264,28 +265,29 @@ BOOST_AUTO_TEST_CASE(distributionRate) { cnote << "Testing Bloom Filter Distribution Rate..."; - unsigned const c_arrSize = DistributionTestSize * 8; - unsigned distribution[c_arrSize]; - memset(distribution, 0, c_arrSize * sizeof(unsigned)); + array distribution; + for (unsigned i = 0; i < TestArrSize; ++i) + distribution[i] = 0; + Topic x(0xC0FFEE); // deterministic pseudorandom value for (unsigned i = 0; i < 22000; ++i) { x = sha3(x); - FixedHash h = x.template bloomPart(); + FixedHash h = x.template bloomPart(); updateDistribution(h, distribution); } unsigned average = 0; - for (unsigned i = 0; i < c_arrSize; ++i) + for (unsigned i = 0; i < TestArrSize; ++i) average += distribution[i]; - average /= c_arrSize; + average /= TestArrSize; unsigned deviation = average / 10; // approx. 10% unsigned maxAllowed = average + deviation; unsigned minAllowed = average - deviation; - for (unsigned i = 0; i < c_arrSize; ++i) + for (unsigned i = 0; i < TestArrSize; ++i) { //cnote << i << ":" << distribution[i]; BOOST_REQUIRE(distribution[i] > minAllowed);