lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [04/13] git commit: Fixed TestOpenBitSet.TestSmall
Date Mon, 15 Sep 2014 22:52:55 GMT
Fixed TestOpenBitSet.TestSmall

Fixed problems from Java->C# conversion for OpenBitSet's Fill and Set
methods. Found that Java's BitSet.Equals does a deep compare, while C#'s
does a reference comparison; added a deep equals extension method to
BitArray to support this case. We still need to modify occurrences of
BitArray.Equals outside of this testcase.


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

Branch: refs/heads/master
Commit: 2603ae8b51d1b3c640a5b19efeacf91cda61c0d4
Parents: fd5e63c
Author: Prad Nelluru <prnell@microsoft.com>
Authored: Thu Sep 11 14:50:23 2014 -0700
Committer: Prad Nelluru <prnell@microsoft.com>
Committed: Thu Sep 11 14:50:23 2014 -0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Support/BitSetSupport.cs    | 35 +++++++++++++++++++-
 src/Lucene.Net.Core/Util/OpenBitSet.cs          |  5 +--
 .../core/Util/TestOpenBitSet.cs                 |  2 +-
 3 files changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2603ae8b/src/Lucene.Net.Core/Support/BitSetSupport.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/BitSetSupport.cs b/src/Lucene.Net.Core/Support/BitSetSupport.cs
index 46ae2b4..7b816d0 100644
--- a/src/Lucene.Net.Core/Support/BitSetSupport.cs
+++ b/src/Lucene.Net.Core/Support/BitSetSupport.cs
@@ -21,6 +21,7 @@
 
 using System;
 using System.Collections;
+using Lucene.Net.Util;
 
 namespace Lucene.Net.Support
 {
@@ -228,7 +229,6 @@ namespace Lucene.Net.Support
             }
         }
 
-
         // Emulates the Java BitSet.Get() method.
         // Prevents exceptions from being thrown when the index is too high.
         public static bool SafeGet(this BitArray a, int loc)
@@ -262,5 +262,38 @@ namespace Lucene.Net.Support
                 }
             }
         }
+
+        //Does a deep comparison of two BitArrays
+        public static bool BitWiseEquals(this BitArray bitsA, BitArray bitsB)
+        {
+            if (bitsA == bitsB)
+                return true;
+            if (bitsA.Count != bitsB.Count)
+                return false;
+
+            for (int i = 0; i < bitsA.Count; i++)
+            {
+                if (bitsA[i] != bitsB[i])
+                    return false;
+            }
+
+            return true;
+        }
+
+        //Compares a BitArray with an OpenBitSet
+        public static bool Equals(BitArray a, OpenBitSet b)
+        {
+            var bitArrayCardinality = a.Cardinality();
+            if (bitArrayCardinality != b.Cardinality())
+                return false;
+
+            for (int i = 0; i < bitArrayCardinality; i++)
+            {
+                if (a.Get(i) != b.Get(i))
+                    return false;
+            }
+
+            return true;
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2603ae8b/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 8e5f698..2e3d265 100644
--- a/src/Lucene.Net.Core/Util/OpenBitSet.cs
+++ b/src/Lucene.Net.Core/Util/OpenBitSet.cs
@@ -344,7 +344,7 @@ namespace Lucene.Net.Util
             int endWord = ExpandingWordNum(endIndex - 1);
 
             long startmask = -1L << (int)startIndex;
-            long endmask = -(int)((uint)1L >> (int)-endIndex); // 64-(endIndex&0x3f)
is the same as -endIndex due to wrap
+            long endmask = (long)(0xffffffffffffffffUL >> (int)-endIndex); // 64-(endIndex&0x3f)
is the same as -endIndex due to wrap
 
             if (startWord == endWord)
             {
@@ -611,6 +611,7 @@ namespace Lucene.Net.Util
             {
                 return;
             }
+
             int startWord = (int)(startIndex >> 6);
 
             // since endIndex is one past the end, this is index of the last
@@ -628,7 +629,7 @@ namespace Lucene.Net.Util
 
             //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
+            long endmask = (long)(0xffffffffffffffffUL >> (int)-endIndex); // 64-(endIndex&0x3f)
is the same as -endIndex due to wrap
 
             if (startWord == endWord)
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2603ae8b/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 03959df..db033a1 100644
--- a/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs
@@ -267,7 +267,7 @@ namespace Lucene.Net.Util
 
                 if (a0 != null)
                 {
-                    Assert.AreEqual(a.Equals(a0), b.Equals(b0));
+                    Assert.AreEqual(a.BitWiseEquals(a0), b.Equals(b0));
 
                     Assert.AreEqual(a.Cardinality(), b.Cardinality());
 


Mime
View raw message