@@ -0,0 +1,1565 @@
+package lbms.plugins.mldht.indexer.utils;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport lbms.plugins.mldht.kad.utils.BitVector;%0A%0Aimport java.nio.ByteBuffer;%0Aimport java.util.concurrent.ThreadLocalRandom;%0A%0Aimport org.junit.Test;%0A%0Apublic class RotatingBloomFilterTest %7B%0A%09%0A%09@Test%0A%09public void testAutorotation() %7B%0A%09%09int num = 512*1024;%0A%09%09%0A%09%09RotatingBloomFilter filter = new RotatingBloomFilter(num , 0.001f);%0A%09%09filter.setAutoRotate(true);%0A%09%09byte%5B%5D buf = new byte%5B32%5D;%0A%09%09for(int i=0;i%3Cnum-1;i++) %7B%0A%09%09%09ThreadLocalRandom.current().nextBytes(buf);%0A%09%09%09filter.insert(ByteBuffer.wrap(buf));%0A%09%09%7D%0A%09%09int contains = 0;%0A%09%09for(int i=0;i%3C10000;i++) %7B%0A%09%09%09ThreadLocalRandom.current().nextBytes(buf);%0A%09%09%09if(filter.contains(ByteBuffer.wrap(buf))) %7B%0A%09%09%09%09contains += 1;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09assertTrue(contains %3C 20);%0A%09%09assertEquals(0, filter.rotations);%0A%09%09%0A%09%09for(int i=0;i%3C2000;i++) %7B%0A%09%09%09ThreadLocalRandom.current().nextBytes(buf);%0A%09%09%09filter.insert(ByteBuffer.wrap(buf));%0A%09%09%7D%0A%09%09assertEquals(1, filter.rotations);%0A%09%09%0A%09%7D%0A%09%0A%09@Test%0A%09public void testBitvector() %7B%0A%09%09byte%5B%5D array = new byte%5B16%5D;%0A%09%09array%5B0%5D = 0b0000_1000;%0A%09%09array%5B1%5D = 0b0100_0000;%0A%09%09BitVector bv = new BitVector(128, array);%0A%09%09assertEquals(0b1000_0100, bv.rangeToInt(4, 8));%0A%09%09%0A%09%09array%5B0%5D = (byte) 0b1111_1000;%0A%09%09array%5B1%5D = 0b0100_1111;%0A%09%09bv = new BitVector(128, array);%0A%09%09assertEquals(0b1000_0100, bv.rangeToInt(4, 8));%0A%0A%09%09array%5B0%5D = (byte) 0b1111_1001;%0A%09%09array%5B1%5D = 0b0100_1111;%0A%09%09bv = new BitVector(128, array);%0A%09%09assertEquals(0b1_0010_1001, bv.rangeToInt(4, 9));%0A%09%09%0A%09%09%0A%09%09%0A%09%7D%0A%0A%7D%0A

add test