lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [2/4] lucenenet git commit: (1) Increased the timeout of one test. It required more time to complete.
Date Tue, 27 Jan 2015 11:11:59 GMT
(1) Increased the timeout of one test. It required more time to complete.

(2) Fixed the Clear method of OpenBitSet, FixedBitSet and LongBitSet classes.
	Masks computation was wrong, since endMask was always 0.
	Added new tests for all of them.

(3) Fixed TestSmall from TestOpenBitSet class. The test assumed that BitArray
	operations were	size-independent (they are in Java's BitSet class). Since
	some of the indexes could be out of	bounds, it failed. To fix this
	I manually enlarged the arrays, if necessary.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/a9e8fe7d
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/a9e8fe7d
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/a9e8fe7d

Branch: refs/heads/master
Commit: a9e8fe7d338a40ae4c63f200e3bdf8ab8605a316
Parents: e3c1ef7
Author: Guido Tagliavini Ponce <t-gupon@microsoft.com>
Authored: Mon Jan 26 13:55:16 2015 -0800
Committer: Itamar Syn-Hershko <itamar@code972.com>
Committed: Tue Jan 27 13:09:25 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/FixedBitSet.cs         | 10 ++-
 src/Lucene.Net.Core/Util/LongBitSet.cs          | 12 +--
 src/Lucene.Net.Core/Util/OpenBitSet.cs          | 11 +--
 .../Util/BaseDocIdSetTestCase.cs                |  2 +-
 .../core/Util/TestFixedBitSet.cs                | 59 +++++++++++++
 .../core/Util/TestLongBitSet.cs                 | 58 +++++++++++++
 .../core/Util/TestOpenBitSet.cs                 | 89 +++++++++++++++++++-
 7 files changed, 222 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a9e8fe7d/src/Lucene.Net.Core/Util/FixedBitSet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/FixedBitSet.cs b/src/Lucene.Net.Core/Util/FixedBitSet.cs
index 99858af..f37c0d6 100644
--- a/src/Lucene.Net.Core/Util/FixedBitSet.cs
+++ b/src/Lucene.Net.Core/Util/FixedBitSet.cs
@@ -681,12 +681,14 @@ namespace Lucene.Net.Util
             int startWord = startIndex >> 6;
             int endWord = (endIndex - 1) >> 6;
 
-            long startmask = -1L << startIndex;
-            long endmask = -(int)((uint)1L >> -endIndex); // 64-(endIndex&0x3f)
is the same as -endIndex due to wrap
+            long startmask = (-1L) << startIndex;  // -1 << (startIndex mod 64)
+            long endmask = (-1L) << endIndex;      // -1 << (endIndex mod 64)
+            if ((endIndex & 0x3f) == 0)
+            {
+                endmask = 0;
+            }
 
-            // invert masks since we are clearing
             startmask = ~startmask;
-            endmask = ~endmask;
 
             if (startWord == endWord)
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a9e8fe7d/src/Lucene.Net.Core/Util/LongBitSet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/LongBitSet.cs b/src/Lucene.Net.Core/Util/LongBitSet.cs
index 6c0093b..927e712 100644
--- a/src/Lucene.Net.Core/Util/LongBitSet.cs
+++ b/src/Lucene.Net.Core/Util/LongBitSet.cs
@@ -390,13 +390,15 @@ namespace Lucene.Net.Util
             int startWord = (int)(startIndex >> 6);
             int endWord = (int)((endIndex - 1) >> 6);
 
-            //LUCENE TO-DO
-            long startmask = -1L << (int)startIndex;
-            long endmask = -(int)((uint)1L >> (int)-endIndex); // 64-(endIndex&0x3f)
is the same as -endIndex due to wrap
+            // Casting long to int discards MSBs, so it is no problem because we are taking
mod 64.
+            long startmask = (-1L) << (int)startIndex;  // -1 << (startIndex
mod 64)
+            long endmask = (-1L) << (int)endIndex;            // -1 << (endIndex
mod 64)
+            if ((endIndex & 0x3f) == 0)
+            {
+                endmask = 0;
+            }
 
-            // invert masks since we are clearing
             startmask = ~startmask;
-            endmask = ~endmask;
 
             if (startWord == endWord)
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a9e8fe7d/src/Lucene.Net.Core/Util/OpenBitSet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/OpenBitSet.cs b/src/Lucene.Net.Core/Util/OpenBitSet.cs
index 2e3d265..cae4546 100644
--- a/src/Lucene.Net.Core/Util/OpenBitSet.cs
+++ b/src/Lucene.Net.Core/Util/OpenBitSet.cs
@@ -436,13 +436,14 @@ namespace Lucene.Net.Util
             // word to be changed.
             int endWord = ((endIndex - 1) >> 6);
 
-            //LUCENE TO-DO
-            long startmask = -1L << startIndex;
-            long endmask = -(int)((uint)1L >> -endIndex); // 64-(endIndex&0x3f)
is the same as -endIndex due to wrap
+            long startmask = (-1L) << startIndex;  // -1 << (startIndex mod 64)
+            long endmask = (-1L) << endIndex;      // -1 << (endIndex mod 64)
+            if ((endIndex & 0x3f) == 0)
+            {
+                endmask = 0;
+            }
 
-            // invert masks since we are clearing
             startmask = ~startmask;
-            endmask = ~endmask;
 
             if (startWord == endWord)
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a9e8fe7d/src/Lucene.Net.TestFramework/Util/BaseDocIdSetTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/BaseDocIdSetTestCase.cs b/src/Lucene.Net.TestFramework/Util/BaseDocIdSetTestCase.cs
index 8c69a3f..a4b23ba 100644
--- a/src/Lucene.Net.TestFramework/Util/BaseDocIdSetTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Util/BaseDocIdSetTestCase.cs
@@ -121,7 +121,7 @@ namespace Lucene.Net.Util
         /// <summary>
         /// Compare the content of the set against a <seealso cref="BitSet"/>.
         /// </summary>
-        [Test, Timeout(40000)]
+        [Test, Timeout(150000)]
         public void TestAgainstBitSet()
         {
             int numBits = TestUtil.NextInt(Random(), 100, 1 << 20);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a9e8fe7d/src/Lucene.Net.Tests/core/Util/TestFixedBitSet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestFixedBitSet.cs b/src/Lucene.Net.Tests/core/Util/TestFixedBitSet.cs
index a8a42fb..90bd19c 100644
--- a/src/Lucene.Net.Tests/core/Util/TestFixedBitSet.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestFixedBitSet.cs
@@ -1,3 +1,4 @@
+using System;
 using Lucene.Net.Randomized.Generators;
 using Lucene.Net.Support;
 using NUnit.Framework;
@@ -266,6 +267,64 @@ namespace Lucene.Net.Util
             DoRandomSets(AtLeast(1200), AtLeast(1000), 2);
         }
 
+        [Test]
+        public void TestClearSmall()
+        {
+            FixedBitSet a = new FixedBitSet(30);   // 0110010111001000101101001001110...0
+            int[] onesA = { 1, 2, 5, 7, 8, 9, 12, 16, 18, 19, 21, 24, 27, 28, 29 };
+
+            for (int i = 0; i < onesA.size(); i++)
+            {
+                a.Set(onesA[i]);
+            }
+
+            FixedBitSet b = new FixedBitSet(30);   // 0110000001001000101101001001110...0
+            int[] onesB = { 1, 2, 9, 12, 16, 18, 19, 21, 24, 27, 28, 29 };
+
+            for (int i = 0; i < onesB.size(); i++)
+            {
+                b.Set(onesB[i]);
+            }
+
+            a.Clear(5, 9);
+            Assert.True(a.Equals(b));
+
+            a.Clear(9, 10);
+            Assert.False(a.Equals(b));
+
+            a.Set(9);
+            Assert.True(a.Equals(b));
+        }
+
+        [Test]
+        public void TestClearLarge()
+        {
+            int iters = AtLeast(1000);
+            for (int it = 0; it < iters; it++)
+            {
+                Random random = new Random();
+                int sz = AtLeast(1200);
+                FixedBitSet a = new FixedBitSet(sz);
+                FixedBitSet b = new FixedBitSet(sz);
+                int from = random.Next(sz - 1);
+                int to = random.Next(from, sz);
+
+                for (int i = 0; i < sz / 2; i++)
+                {
+                    int index = random.Next(sz - 1);
+                    a.Set(index);
+
+                    if (index < from || index >= to)
+                    {
+                        b.Set(index);
+                    }
+                }
+
+                a.Clear(from, to);
+                Assert.True(a.Equals(b));
+            }
+        }
+
         // uncomment to run a bigger test (~2 minutes).
         /*
         public void testBig() {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a9e8fe7d/src/Lucene.Net.Tests/core/Util/TestLongBitSet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestLongBitSet.cs b/src/Lucene.Net.Tests/core/Util/TestLongBitSet.cs
index 94d2e9e..6c3e1c6 100644
--- a/src/Lucene.Net.Tests/core/Util/TestLongBitSet.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestLongBitSet.cs
@@ -210,6 +210,64 @@ namespace Lucene.Net.Util
             DoRandomSets(AtLeast(1200), AtLeast(1000), 2);
         }
 
+        [Test]
+        public void TestClearSmall()
+        {
+            LongBitSet a = new LongBitSet(30);   // 0110010111001000101101001001110...0
+            int[] onesA = { 1, 2, 5, 7, 8, 9, 12, 16, 18, 19, 21, 24, 27, 28, 29 };
+
+            for (int i = 0; i < onesA.size(); i++)
+            {
+                a.Set(onesA[i]);
+            }
+
+            LongBitSet b = new LongBitSet(30);   // 0110000001001000101101001001110...0
+            int[] onesB = { 1, 2, 9, 12, 16, 18, 19, 21, 24, 27, 28, 29 };
+
+            for (int i = 0; i < onesB.size(); i++)
+            {
+                b.Set(onesB[i]);
+            }
+
+            a.Clear(5, 9);
+            Assert.True(a.Equals(b));
+
+            a.Clear(9, 10);
+            Assert.False(a.Equals(b));
+
+            a.Set(9);
+            Assert.True(a.Equals(b));
+        }
+
+        [Test]
+        public void TestClearLarge()
+        {
+            int iters = AtLeast(1000);
+            for (int it = 0; it < iters; it++)
+            {
+                Random random = new Random();
+                int sz = AtLeast(1200);
+                LongBitSet a = new LongBitSet(sz);
+                LongBitSet b = new LongBitSet(sz);
+                int from = random.Next(sz - 1);
+                int to = random.Next(from, sz);
+
+                for (int i = 0; i < sz / 2; i++)
+                {
+                    int index = random.Next(sz - 1);
+                    a.Set(index);
+
+                    if (index < from || index >= to)
+                    {
+                        b.Set(index);
+                    }
+                }
+
+                a.Clear(from, to);
+                Assert.True(a.Equals(b));
+            }
+        }
+
         // uncomment to run a bigger test (~2 minutes).
         /*
         public void testBig() {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a9e8fe7d/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs b/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs
index db033a1..5d4dbb8 100644
--- a/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 
+using System;
 using Lucene.Net.Randomized.Generators;
 using Lucene.Net.Support;
 using NUnit.Framework;
@@ -232,7 +233,14 @@ namespace Lucene.Net.Util
                 int fromIndex, toIndex;
                 fromIndex = Random().Next(sz + 80);
                 toIndex = fromIndex + Random().Next((sz >> 1) + 1);
+
                 BitArray aa = (BitArray)a.Clone();
+                // C# BitArray class does not support dynamic sizing.
+                // We have to explicitly change its size using the Length attribute.
+                if (toIndex > aa.Length)
+                {
+                    aa.Length = toIndex;
+                }
                 aa.Flip(fromIndex, toIndex);
                 OpenBitSet bb = (OpenBitSet)b.Clone();
                 bb.Flip(fromIndex, toIndex);
@@ -242,6 +250,10 @@ namespace Lucene.Net.Util
                 fromIndex = Random().Next(sz + 80);
                 toIndex = fromIndex + Random().Next((sz >> 1) + 1);
                 aa = (BitArray)a.Clone();
+                if (toIndex > aa.Length)
+                {
+                    aa.Length = toIndex;
+                }
                 aa.Clear(fromIndex, toIndex);
                 bb = (OpenBitSet)b.Clone();
                 bb.Clear(fromIndex, toIndex);
@@ -255,6 +267,10 @@ namespace Lucene.Net.Util
                 fromIndex = Random().Next(sz + 80);
                 toIndex = fromIndex + Random().Next((sz >> 1) + 1);
                 aa = (BitArray)a.Clone();
+                if (toIndex > aa.Length)
+                {
+                    aa.Length = toIndex;
+                }
                 aa.Set(fromIndex, toIndex);
                 bb = (OpenBitSet)b.Clone();
                 bb.Set(fromIndex, toIndex);
@@ -267,16 +283,23 @@ namespace Lucene.Net.Util
 
                 if (a0 != null)
                 {
-                    Assert.AreEqual(a.BitWiseEquals(a0), b.Equals(b0));
+                    aa = (BitArray)a.Clone();
+                    BitArray aa0 = (BitArray) a0.Clone();
+                    int largest = Math.Max(a.Length, a0.Length);
+                    aa.Length = aa0.Length = largest;
+                    // BitWiseEquals needs both arrays to be the same size for succeeding.
+                    // We could enlarge the smallest of a and a0, but then the tests below
+                    // won't test "UnequalLengths" operations.
+                    Assert.AreEqual(aa.BitWiseEquals(aa0), b.Equals(b0));
 
                     Assert.AreEqual(a.Cardinality(), b.Cardinality());
 
                     BitArray a_and = (BitArray)a.Clone();
-                    a_and = a_and.And(a0);
+                    a_and = a_and.And_UnequalLengths(a0);
                     BitArray a_or = (BitArray)a.Clone();
-                    a_or = a_or.Or(a0);
+                    a_or = a_or.Or_UnequalLengths(a0);
                     BitArray a_xor = (BitArray)a.Clone();
-                    a_xor = a_xor.Xor(a0);
+                    a_xor = a_xor.Xor_UnequalLengths(a0);
                     BitArray a_andn = (BitArray)a.Clone();
                     a_andn.AndNot(a0);
 
@@ -321,6 +344,64 @@ namespace Lucene.Net.Util
             DoRandomSets(AtLeast(1200), AtLeast(1000), 2);
         }
 
+        [Test]
+        public void TestClearSmall()
+        {
+            OpenBitSet a = new OpenBitSet(30);   // 0110010111001000101101001001110...0
+            int[] onesA = { 1, 2, 5, 7, 8, 9, 12, 16, 18, 19, 21, 24, 27, 28, 29 };
+
+            for (int i = 0; i < onesA.size(); i++)
+            {
+                a.Set(onesA[i]);
+            }
+
+            OpenBitSet b = new OpenBitSet(30);   // 0110000001001000101101001001110...0
+            int[] onesB = { 1, 2, 9, 12, 16, 18, 19, 21, 24, 27, 28, 29 };
+
+            for (int i = 0; i < onesB.size(); i++)
+            {
+                b.Set(onesB[i]);
+            }
+
+            a.Clear(5, 9);
+            Assert.True(a.Equals(b));
+
+            a.Clear(9, 10);
+            Assert.False(a.Equals(b));
+
+            a.Set(9);
+            Assert.True(a.Equals(b));
+        }
+
+        [Test]
+        public void TestClearLarge()
+        {
+            int iters = AtLeast(1000);
+            for (int it = 0; it < iters; it++)
+            {
+                Random random = new Random();
+                int sz = AtLeast(1200);
+                OpenBitSet a = new OpenBitSet(sz);
+                OpenBitSet b = new OpenBitSet(sz);
+                int from = random.Next(sz - 1);
+                int to = random.Next(from, sz);
+
+                for (int i = 0; i < sz / 2; i++)
+                {
+                    int index = random.Next(sz - 1);
+                    a.Set(index);
+
+                    if (index < from || index >= to)
+                    {
+                        b.Set(index);
+                    }
+                }
+
+                a.Clear(from, to);
+                Assert.True(a.Equals(b));
+            }
+        }
+
         // uncomment to run a bigger test (~2 minutes).
         /*
         public void TestBig() {


Mime
View raw message