lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [2/4] git commit: More tests work
Date Tue, 05 Aug 2014 00:29:01 GMT
More tests work


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

Branch: refs/heads/branch_4x
Commit: bd24ffc4f3fed7d456b76c65c5e967a26f4936ce
Parents: 1af114f
Author: Itamar Syn-Hershko <itamar@code972.com>
Authored: Tue Aug 5 03:22:21 2014 +0300
Committer: Itamar Syn-Hershko <itamar@code972.com>
Committed: Tue Aug 5 03:22:21 2014 +0300

----------------------------------------------------------------------
 src/core/Lucene.Net.csproj                      |   1 +
 src/core/Support/Arrays.cs                      |  11 +-
 src/core/Support/Collections.cs                 |  10 +
 src/core/Support/ReverseComparer.cs             |  27 ++
 test/core/Lucene.Net.Test.csproj                |   1 +
 test/core/Util/Fst/TestBytesStore.cs            |   1 -
 test/core/Util/TestArrayUtil.cs                 | 343 +++++++++----------
 test/core/Util/TestBytesRef.cs                  |   7 +
 .../JavaCompatibility/LuceneTestCase.cs         |   8 +
 .../JavaCompatibility/SystemTypesHelpers.cs     |   5 +
 10 files changed, 232 insertions(+), 182 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd24ffc4/src/core/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/core/Lucene.Net.csproj b/src/core/Lucene.Net.csproj
index c754a84..f94c3e2 100644
--- a/src/core/Lucene.Net.csproj
+++ b/src/core/Lucene.Net.csproj
@@ -925,6 +925,7 @@
     <Compile Include="Support\OS.cs" />
     <Compile Include="Support\PriorityQueue.cs" />
     <Compile Include="Support\ReentrantLock.cs" />
+    <Compile Include="Support\ReverseComparer.cs" />
     <Compile Include="Support\SharpZipLib.cs" />
     <Compile Include="Support\Single.cs" />
     <Compile Include="Support\IChecksum.cs">

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd24ffc4/src/core/Support/Arrays.cs
----------------------------------------------------------------------
diff --git a/src/core/Support/Arrays.cs b/src/core/Support/Arrays.cs
index 732f4aa..ab4d541 100644
--- a/src/core/Support/Arrays.cs
+++ b/src/core/Support/Arrays.cs
@@ -1,7 +1,6 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Text;
 
 namespace Lucene.Net.Support
 {
@@ -118,5 +117,15 @@ namespace Lucene.Net.Support
         {
             return objects.ToList();
         }
+
+        public static void Sort<T>(T[] ar)
+        {
+            Array.Sort(ar);
+        }
+
+        public static void Sort<T>(T[] ar, IComparer<T> comparer)
+        {
+            Array.Sort(ar, comparer);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd24ffc4/src/core/Support/Collections.cs
----------------------------------------------------------------------
diff --git a/src/core/Support/Collections.cs b/src/core/Support/Collections.cs
index 0256b73..dabb375 100644
--- a/src/core/Support/Collections.cs
+++ b/src/core/Support/Collections.cs
@@ -368,5 +368,15 @@ namespace Lucene.Net.Support
         {
             return new UnmodifiableDictionary<TKey, TValue>(dict);
         }
+
+        public static IComparer ReverseOrder()
+        {
+            return new ReverseComparer();
+        }
+
+        public static IComparer<T> ReverseOrder<T>()
+        {
+            return new ReverseComparer<T>();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd24ffc4/src/core/Support/ReverseComparer.cs
----------------------------------------------------------------------
diff --git a/src/core/Support/ReverseComparer.cs b/src/core/Support/ReverseComparer.cs
new file mode 100644
index 0000000..90f14ee
--- /dev/null
+++ b/src/core/Support/ReverseComparer.cs
@@ -0,0 +1,27 @@
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Lucene.Net.Support
+{
+    sealed class ReverseComparer<T> : IComparer<T>
+    {
+        private readonly IComparer<T> inner;
+        public ReverseComparer() : this(null) { }
+        public ReverseComparer(IComparer<T> inner)
+        {
+            this.inner = inner ?? Comparer<T>.Default;
+        }
+        int IComparer<T>.Compare(T x, T y) { return inner.Compare(y, x); }
+    }
+
+    sealed class ReverseComparer : IComparer
+    {
+        private readonly IComparer inner;
+        public ReverseComparer() : this(null) { }
+        public ReverseComparer(IComparer inner)
+        {
+            this.inner = inner ?? Comparer.Default;
+        }
+        int IComparer.Compare(object x, object y) { return inner.Compare(y, x); }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd24ffc4/test/core/Lucene.Net.Test.csproj
----------------------------------------------------------------------
diff --git a/test/core/Lucene.Net.Test.csproj b/test/core/Lucene.Net.Test.csproj
index c686cdc..5df9bec 100644
--- a/test/core/Lucene.Net.Test.csproj
+++ b/test/core/Lucene.Net.Test.csproj
@@ -208,6 +208,7 @@
     <Compile Include="SupportClassException.cs" />
     <Compile Include="Util\Fst\TestBytesStore.cs" />
     <Compile Include="Util\LocalizedTestCase.cs" />
+    <Compile Include="Util\TestArrayUtil.cs" />
     <Compile Include="Util\TestBytesRef.cs" />
     <None Include="App.config" />
     <None Include="Index\index.19.cfs.zip" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd24ffc4/test/core/Util/Fst/TestBytesStore.cs
----------------------------------------------------------------------
diff --git a/test/core/Util/Fst/TestBytesStore.cs b/test/core/Util/Fst/TestBytesStore.cs
index 5e39751..9b2aedb 100644
--- a/test/core/Util/Fst/TestBytesStore.cs
+++ b/test/core/Util/Fst/TestBytesStore.cs
@@ -1,7 +1,6 @@
 using System;
 using Lucene.Net.Store;
 using Lucene.Net.Support;
-using Lucene.Net.Util;
 using Lucene.Net.Util.Fst;
 using NUnit.Framework;
 using Lucene.Net.Randomized.Generators;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd24ffc4/test/core/Util/TestArrayUtil.cs
----------------------------------------------------------------------
diff --git a/test/core/Util/TestArrayUtil.cs b/test/core/Util/TestArrayUtil.cs
index 2e1b644..a1168d5 100644
--- a/test/core/Util/TestArrayUtil.cs
+++ b/test/core/Util/TestArrayUtil.cs
@@ -1,6 +1,7 @@
 using System;
+using Lucene.Net.JavaCompatibility;
+using Lucene.Net.Randomized.Generators;
 using Lucene.Net.Support;
-using Lucene.Net.Test.Support;
 using Lucene.Net.Util;
 using NUnit.Framework;
 
@@ -9,33 +10,30 @@ namespace Lucene.Net.Test.Util
     [TestFixture]
     public class TestArrayUtil : LuceneTestCase
     {
-        // Ensure ArrayUtil.getNextSize gives linear amortized cost of realloc/copy
         [Test]
         public void TestGrowth()
         {
             int currentSize = 0;
             long copyCost = 0;
-
-            // Make sure ArrayUtil hits int.MaxValue, if we insist:
             while (currentSize != int.MaxValue)
             {
                 int nextSize = ArrayUtil.Oversize(1 + currentSize, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
-                Assert.IsTrue(nextSize > currentSize);
+                assertTrue(nextSize > currentSize);
                 if (currentSize > 0)
                 {
                     copyCost += currentSize;
-                    var copyCostPerElement = ((double)copyCost) / currentSize;
-                    Assert.IsTrue("cost " + copyCostPerElement, copyCostPerElement < 10.0);
+                    double copyCostPerElement = ((double)copyCost) / currentSize;
+                    assertTrue(@"cost " + copyCostPerElement, copyCostPerElement < 10.0);
                 }
+
                 currentSize = nextSize;
             }
         }
 
         [Test]
-        public void TextMaxSize()
+        public void TestMaxSize()
         {
-            // Intentionally pass invalid elemSizes:
-            for (var elemSize = 0; elemSize < 10; elemSize++)
+            for (int elemSize = 0; elemSize < 10; elemSize++)
             {
                 assertEquals(int.MaxValue, ArrayUtil.Oversize(int.MaxValue, elemSize));
                 assertEquals(int.MaxValue, ArrayUtil.Oversize(int.MaxValue - 1, elemSize));
@@ -45,14 +43,14 @@ namespace Lucene.Net.Test.Util
         [Test]
         public void TestInvalidElementSizes()
         {
-            var rnd = new Random();
+            Random rnd = Random();
             int num = AtLeast(10000);
-            for (var iter = 0; iter < num; iter++)
+            for (int iter = 0; iter < num; iter++)
             {
-                var minTargetSize = rnd.Next(int.MaxValue);
-                var elemSize = rnd.Next(11);
-                var v = ArrayUtil.Oversize(minTargetSize, elemSize);
-                Assert.IsTrue(v >= minTargetSize);
+                int minTargetSize = rnd.nextInt(int.MaxValue);
+                int elemSize = rnd.nextInt(11);
+                int v = ArrayUtil.Oversize(minTargetSize, elemSize);
+                assertTrue(v >= minTargetSize);
             }
         }
 
@@ -62,230 +60,224 @@ namespace Lucene.Net.Test.Util
             int test;
             try
             {
-                test = ArrayUtil.ParseInt("".ToCharArray());
-                Assert.IsTrue(false);
+                test = ArrayUtil.ParseInt(@"".ToCharArray());
+                assertTrue(false);
             }
             catch (FormatException e)
             {
-                //expected
             }
+
             try
             {
-                test = ArrayUtil.ParseInt("foo".ToCharArray());
-                Assert.IsTrue(false);
+                test = ArrayUtil.ParseInt(@"foo".ToCharArray());
+                assertTrue(false);
             }
             catch (FormatException e)
             {
-                //expected
             }
+
             try
             {
                 test = ArrayUtil.ParseInt(long.MaxValue.ToString().ToCharArray());
-                Assert.IsTrue(false);
+                assertTrue(false);
             }
             catch (FormatException e)
             {
-                //expected
             }
+
             try
             {
-                test = ArrayUtil.ParseInt("0.34".ToCharArray());
-                Assert.IsTrue(false);
+                test = ArrayUtil.ParseInt(@"0.34".ToCharArray());
+                assertTrue(false);
             }
             catch (FormatException e)
             {
-                //expected
             }
 
             try
             {
-                test = ArrayUtil.ParseInt("1".ToCharArray());
-                Assert.IsTrue(test == 1, test + " does not equal: " + 1);
-                test = ArrayUtil.ParseInt("-10000".ToCharArray());
-                Assert.IsTrue(test == -10000, test + " does not equal: " + -10000);
-                test = ArrayUtil.ParseInt("1923".ToCharArray());
-                Assert.IsTrue(test == 1923, test + " does not equal: " + 1923);
-                test = ArrayUtil.ParseInt("-1".ToCharArray());
-                Assert.IsTrue(test == -1, test + " does not equal: " + -1);
-                test = ArrayUtil.ParseInt("foo 1923 bar".ToCharArray(), 4, 4);
-                Assert.IsTrue(test == 1923, test + " does not equal: " + 1923);
+                test = ArrayUtil.ParseInt(@"1".ToCharArray());
+                assertTrue(test + @" does not equal: " + 1, test == 1);
+                test = ArrayUtil.ParseInt(@"-10000".ToCharArray());
+                assertTrue(test + @" does not equal: " + -10000, test == -10000);
+                test = ArrayUtil.ParseInt(@"1923".ToCharArray());
+                assertTrue(test + @" does not equal: " + 1923, test == 1923);
+                test = ArrayUtil.ParseInt(@"-1".ToCharArray());
+                assertTrue(test + @" does not equal: " + -1, test == -1);
+                test = ArrayUtil.ParseInt(@"foo 1923 bar".ToCharArray(), 4, 4);
+                assertTrue(test + @" does not equal: " + 1923, test == 1923);
             }
             catch (FormatException e)
             {
-                Console.WriteLine(e.StackTrace);
-                Assert.IsTrue(false);
+                e.printStackTrace();
+                assertTrue(false);
             }
         }
 
         [Test]
         public void TestSliceEquals()
         {
-            var left = "this is equal";
-            var right = left;
-            var leftChars = left.ToCharArray();
-            var rightChars = right.ToCharArray();
-            Assert.IsTrue(ArrayUtil.Equals(leftChars, 0, rightChars, 0, left.Length), left
+ " does not equal: " + right);
-
-            Assert.IsFalse(ArrayUtil.Equals(leftChars, 1, rightChars, 0, left.Length), left
+ " does not equal: " + right);
-            Assert.IsFalse(ArrayUtil.Equals(leftChars, 1, rightChars, 2, left.Length), left
+ " does not equal: " + right);
-
-            Assert.IsFalse(ArrayUtil.Equals(leftChars, 25, rightChars, 0, left.Length), left
+ " does not equal: " + right);
-            Assert.IsFalse(ArrayUtil.Equals(leftChars, 12, rightChars, 0, left.Length), left
+ " does not equal: " + right);
+            string left = @"this is equal";
+            string right = left;
+            char[] leftChars = left.ToCharArray();
+            char[] rightChars = right.ToCharArray();
+            assertTrue(left + @" does not equal: " + right, ArrayUtil.Equals(leftChars, 0,
rightChars, 0, left.Length));
+            assertFalse(left + @" does not equal: " + right, ArrayUtil.Equals(leftChars,
1, rightChars, 0, left.Length));
+            assertFalse(left + @" does not equal: " + right, ArrayUtil.Equals(leftChars,
1, rightChars, 2, left.Length));
+            assertFalse(left + @" does not equal: " + right, ArrayUtil.Equals(leftChars,
25, rightChars, 0, left.Length));
+            assertFalse(left + @" does not equal: " + right, ArrayUtil.Equals(leftChars,
12, rightChars, 0, left.Length));
         }
 
         private int[] CreateRandomArray(int maxSize)
         {
-            var rnd = new Random();
-            var a = new int[rnd.Next(maxSize) + 1];
-            for (var i = 0; i < a.Length; i++)
+            Random rnd = Random();
+            var a = new int[rnd.nextInt(maxSize) + 1];
+            for (int i = 0; i < a.Length; i++)
             {
-                a[i] = rnd.Next(a.Length);
+                a[i] = rnd.nextInt(a.Length);
             }
+
             return a;
         }
 
         [Test]
-        public virtual void TestQuickSort()
+        public void TestQuickSort()
         {
             int num = AtLeast(50);
-            for (var i = 0; i < num; i++)
+            for (int i = 0; i < num; i++)
             {
-                int[] a1 = CreateRandomArray(2000), a2 = (int[])a1.Clone();
+                var a1 = CreateRandomArray(2000);
+                var a2 = a1.clone();
                 ArrayUtil.QuickSort(a1);
-                Array.Sort(a2);
-                Assert.IsTrue(a2.Equals(a1));
-
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
                 a1 = CreateRandomArray(2000);
-                a2 = (int[])a1.Clone();
-                ArrayUtil.QuickSort(a1, Collections.ReverseOrder());
-                Array.Sort(a2, Collections.ReverseOrder());
-                Assert.Equals(a1, a2);
-                // reverse back, so we can test that completely backwards sorted array (worst
case) is working:
+                a2 = a1.clone();
+                ArrayUtil.QuickSort(a1, Collections.ReverseOrder<int>());
+                Arrays.Sort(a2, Collections.ReverseOrder<int>());
+                assertArrayEquals(a2, a1);
                 ArrayUtil.QuickSort(a1);
-                Array.Sort(a2);
-                Assert.Equals(a2, a1);
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
             }
         }
 
         private int[] CreateSparseRandomArray(int maxSize)
         {
-            var rnd = new Random();
-            var a = new int[rnd.Next(maxSize) + 1];
-            for (var i = 0; i < a.Length; i++)
+            Random rnd = Random();
+            var a = new int[rnd.nextInt(maxSize) + 1];
+            for (int i = 0; i < a.Length; i++)
             {
-                a[i] = rnd.Next(2);
+                a[i] = rnd.nextInt(2);
             }
+
             return a;
         }
 
         [Test]
-        public virtual void TestQuickToMergeSortFallback()
+        public void TestQuickToMergeSortFallback()
         {
             int num = AtLeast(50);
-            for (var i = 0; i < num; i++)
+            for (int i = 0; i < num; i++)
             {
-                int[] a1 = CreateSparseRandomArray(40000), a2 = (int[])a1.Clone();
+                var a1 = CreateSparseRandomArray(40000);
+                var a2 = a1.clone();
                 ArrayUtil.QuickSort(a1);
-                Array.Sort(a2);
-                Assert.Equals(a2, a1);
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
             }
         }
 
         [Test]
-        public virtual void TestMergeSort()
+        public void TestMergeSort()
         {
             int num = AtLeast(50);
-            for (var i = 0; i < num; i++)
+            for (int i = 0; i < num; i++)
             {
-                int[] a1 = CreateRandomArray(2000), a2 = (int[])a1.Clone();
+                var a1 = CreateRandomArray(2000);
+                var a2 = a1.clone();
                 ArrayUtil.MergeSort(a1);
-                Array.Sort(a2);
-                Assert.Equals(a2, a1);
-
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
                 a1 = CreateRandomArray(2000);
-                a2 = (int[])a1.Clone();
-                ArrayUtil.MergeSort(a1, Collections.ReverseOrder());
-                Array.Sort(a2, Collections.ReverseOrder());
-                Assert.Equals(a2, a1);
-                // reverse back, so we can test that completely backwards sorted array (worst
case) is working:
+                a2 = a1.clone();
+                ArrayUtil.MergeSort(a1, Collections.ReverseOrder<int>());
+                Arrays.Sort(a2, Collections.ReverseOrder<int>());
+                assertArrayEquals(a2, a1);
                 ArrayUtil.MergeSort(a1);
-                Array.Sort(a2);
-                Assert.Equals(a2, a1);
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
             }
         }
 
         [Test]
-        public virtual void TestTimSort()
+        public void TestTimSort()
         {
             int num = AtLeast(65);
-            for (var i = 0; i < num; i++)
+            for (int i = 0; i < num; i++)
             {
-                int[] a1 = CreateRandomArray(2000), a2 = (int[])a1.Clone();
+                var a1 = CreateRandomArray(2000);
+                var a2 = a1.clone();
                 ArrayUtil.TimSort(a1);
-                Array.Sort(a2);
-                Assert.Equals(a2, a1);
-
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
                 a1 = CreateRandomArray(2000);
-                a2 = (int[])a1.Clone();
-                ArrayUtil.TimSort(a1, Collections.ReverseOrder());
-                Array.Sort(a2, Collections.ReverseOrder());
-                Assert.Equals(a2, a1);
-                // reverse back, so we can test that completely backwards sorted array (worst
case) is working:
+                a2 = a1.clone();
+                ArrayUtil.TimSort(a1, Collections.ReverseOrder<int>());
+                Arrays.Sort(a2, Collections.ReverseOrder<int>());
+                assertArrayEquals(a2, a1);
                 ArrayUtil.TimSort(a1);
-                Array.Sort(a2);
-                Assert.Equals(a2, a1);
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
             }
         }
 
         [Test]
-        public virtual void TestInsertionSort()
+        public void TestInsertionSort()
         {
             for (int i = 0, c = AtLeast(500); i < c; i++)
             {
-                int[] a1 = CreateRandomArray(30), a2 = (int[])a1.Clone();
+                var a1 = CreateRandomArray(30);
+                var a2 = a1.clone();
                 ArrayUtil.InsertionSort(a1);
-                Array.Sort(a2);
-                Assert.Equals(a2, a1);
-
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
                 a1 = CreateRandomArray(30);
-                a2 = (int[])a1.Clone();
-                ArrayUtil.InsertionSort(a1, Collections.ReverseOrder());
-                Array.Sort(a2, Collections.ReverseOrder());
-                Assert.Equals(a2, a1);
-                // reverse back, so we can test that completely backwards sorted array (worst
case) is working:
+                a2 = a1.clone();
+                ArrayUtil.InsertionSort(a1, Collections.ReverseOrder<int>());
+                Arrays.Sort(a2, Collections.ReverseOrder<int>());
+                assertArrayEquals(a2, a1);
                 ArrayUtil.InsertionSort(a1);
-                Array.Sort(a2);
-                Assert.Equals(a2, a1);
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
             }
         }
 
         [Test]
-        public virtual void TestBinarySort()
+        public void TestBinarySort()
         {
             for (int i = 0, c = AtLeast(500); i < c; i++)
             {
-                int[] a1 = CreateRandomArray(30), a2 = (int[])a1.Clone();
+                var a1 = CreateRandomArray(30);
+                var a2 = a1.clone();
                 ArrayUtil.BinarySort(a1);
-                Array.Sort(a2);
-                Assert.Equals(a2, a1);
-
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
                 a1 = CreateRandomArray(30);
-                a2 = (int[])a1.Clone();
-                ArrayUtil.BinarySort(a1, Collections.ReverseOrder());
-                Array.Sort(a2, Collections.ReverseOrder());
-                Assert.Equals(a2, a1);
-                // reverse back, so we can test that completely backwards sorted array (worst
case) is working:
+                a2 = a1.clone();
+                ArrayUtil.BinarySort(a1, Collections.ReverseOrder<int>());
+                Arrays.Sort(a2, Collections.ReverseOrder<int>());
+                assertArrayEquals(a2, a1);
                 ArrayUtil.BinarySort(a1);
-                Array.Sort(a2);
-                Assert.Equals(a2, a1);
+                Arrays.Sort(a2);
+                assertArrayEquals(a2, a1);
             }
         }
 
-        internal class Item : IComparable<Item>
+        class Item : IComparable<Item>
         {
-            int val, order;
-
-            internal Item(int val, int order)
+            public readonly int val, order;
+            public Item(int val, int order)
             {
                 this.val = val;
                 this.order = order;
@@ -303,76 +295,67 @@ namespace Lucene.Net.Test.Util
         }
 
         [Test]
-        public virtual void TestMergeSortStability()
+        public void TestMergeSortStability()
         {
-            var rnd = new Random();
-            var items = new Item[100];
-            for (var i = 0; i < items.Length; i++)
+            Random rnd = Random();
+            Item[] items = new Item[100];
+            for (int i = 0; i < items.Length; i++)
             {
-                // half of the items have value but same order. The value of this items is
sorted,
-                // so they should always be in order after sorting.
-                // The other half has defined order, but no (-1) value (they should appear
after
-                // all above, when sorted).
-                var equal = rnd.NextBool();
-                items[i] = new Item(equal ? (i + 1) : -1, equal ? 0 : (rnd.Next(1000) + 1));
+                bool equal = rnd.NextBoolean();
+                items[i] = new Item(equal ? (i + 1) : -1, equal ? 0 : (rnd.nextInt(1000)
+ 1));
             }
 
-            if (VERBOSE) Console.WriteLine("Before: " + Arrays.ToString(items));
-            // if you replace this with ArrayUtil.quickSort(), test should fail:
+            if (VERBOSE)
+                Console.WriteLine(@"Before: " + Arrays.ToString(items));
             ArrayUtil.MergeSort(items);
-            if (VERBOSE) Console.WriteLine("Sorted: " + Arrays.ToString(items));
-
-            var last = items[0];
-            for (var i = 1; i < items.Length; i++)
+            if (VERBOSE)
+                Console.WriteLine(@"Sorted: " + Arrays.ToString(items));
+            Item last = items[0];
+            for (int i = 1; i < items.Length; i++)
             {
-                var act = items[i];
-                if (act.Order == 0)
+                Item act = items[i];
+                if (act.order == 0)
                 {
-                    // order of "equal" items should be not mixed up
-                    Assert.IsTrue(act.Val > last.Val);
+                    assertTrue(act.val > last.val);
                 }
-                Assert.IsTrue(act.Order >= last.Order);
+
+                assertTrue(act.order >= last.order);
                 last = act;
             }
         }
 
         [Test]
-        public virtual void TestTimSortStability()
+        public void TestTimSortStability()
         {
-            var rnd = new Random();
-            var items = new Item[100];
-            for (var i = 0; i < items.Length; i++)
+            Random rnd = Random();
+            Item[] items = new Item[100];
+            for (int i = 0; i < items.Length; i++)
             {
-                // half of the items have value but same order. The value of this items is
sorted,
-                // so they should always be in order after sorting.
-                // The other half has defined order, but no (-1) value (they should appear
after
-                // all above, when sorted).
-                var equal = rnd.NextBool();
-                items[i] = new Item(equal ? (i + 1) : -1, equal ? 0 : (rnd.Next(1000) + 1));
+                bool equal = rnd.NextBoolean();
+                items[i] = new Item(equal ? (i + 1) : -1, equal ? 0 : (rnd.nextInt(1000)
+ 1));
             }
 
-            if (VERBOSE) Console.WriteLine("Before: " + Arrays.ToString(items));
-            // if you replace this with ArrayUtil.quickSort(), test should fail:
+            if (VERBOSE)
+                Console.WriteLine(@"Before: " + Arrays.ToString(items));
             ArrayUtil.TimSort(items);
-            if (VERBOSE) Console.WriteLine("Sorted: " + Arrays.ToString(items));
-
-            var last = items[0];
-            for (var i = 1; i < items.Length; i++)
+            if (VERBOSE)
+                Console.WriteLine(@"Sorted: " + Arrays.ToString(items));
+            Item last = items[0];
+            for (int i = 1; i < items.Length; i++)
             {
-                var act = items[i];
-                if (act.Order == 0)
+                Item act = items[i];
+                if (act.order == 0)
                 {
-                    // order of "equal" items should be not mixed up
-                    Assert.IsTrue(act.Val > last.Val);
+                    assertTrue(act.val > last.val);
                 }
-                Assert.IsTrue(act.Order >= last.Order);
+
+                assertTrue(act.order >= last.order);
                 last = act;
             }
         }
 
-        // Should produce no excepetions
         [Test]
-        public virtual void TestEmptyArraySort()
+        public void TestEmptyArraySort()
         {
             var a = new int[0];
             ArrayUtil.QuickSort(a);
@@ -380,11 +363,11 @@ namespace Lucene.Net.Test.Util
             ArrayUtil.InsertionSort(a);
             ArrayUtil.BinarySort(a);
             ArrayUtil.TimSort(a);
-            ArrayUtil.QuickSort(a, Collections.ReverseOrder());
-            ArrayUtil.MergeSort(a, Collections.ReverseOrder());
-            ArrayUtil.TimSort(a, Collections.ReverseOrder());
-            ArrayUtil.InsertionSort(a, Collections.ReverseOrder());
-            ArrayUtil.BinarySort(a, Collections.ReverseOrder());
+            ArrayUtil.QuickSort(a, Collections.ReverseOrder<int>());
+            ArrayUtil.MergeSort(a, Collections.ReverseOrder<int>());
+            ArrayUtil.TimSort(a, Collections.ReverseOrder<int>());
+            ArrayUtil.InsertionSort(a, Collections.ReverseOrder<int>());
+            ArrayUtil.BinarySort(a, Collections.ReverseOrder<int>());
         }
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd24ffc4/test/core/Util/TestBytesRef.cs
----------------------------------------------------------------------
diff --git a/test/core/Util/TestBytesRef.cs b/test/core/Util/TestBytesRef.cs
index 6706c89..47f57b8 100644
--- a/test/core/Util/TestBytesRef.cs
+++ b/test/core/Util/TestBytesRef.cs
@@ -1,10 +1,13 @@
 using System;
 using Lucene.Net.Util;
+using NUnit.Framework;
 
 namespace Lucene.Net.Test.Util
 {
+    [TestFixture]
     public class TestBytesRef : LuceneTestCase
     {
+        [Test]
         public void TestEmpty()
         {
             BytesRef b = new BytesRef();
@@ -13,6 +16,7 @@ namespace Lucene.Net.Test.Util
             assertEquals(0, b.length);
         }
 
+        [Test]
         public void TestFromBytes()
         {
             var bytes = new[]
@@ -30,6 +34,7 @@ namespace Lucene.Net.Test.Util
             assertFalse(b.Equals(b2));
         }
 
+        [Test]
         public void TestFromChars()
         {
             for (int i = 0; i < 100; i++)
@@ -42,6 +47,7 @@ namespace Lucene.Net.Test.Util
             assertEquals(@"?", new BytesRef(@"?").Utf8ToString());
         }
 
+        [Test]
         public void TestAppend()
         {
             var bytes = new[]
@@ -54,6 +60,7 @@ namespace Lucene.Net.Test.Util
             assertEquals(@"bcde", b.Utf8ToString());
         }
 
+        [Test]
         public void TestCopyBytes()
         {
             var bytes = new[]

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd24ffc4/test/test-framework/JavaCompatibility/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/JavaCompatibility/LuceneTestCase.cs b/test/test-framework/JavaCompatibility/LuceneTestCase.cs
index 4f8e95a..57c3818 100644
--- a/test/test-framework/JavaCompatibility/LuceneTestCase.cs
+++ b/test/test-framework/JavaCompatibility/LuceneTestCase.cs
@@ -1,4 +1,6 @@
 using System;
+using System.Collections;
+using System.Linq;
 using NUnit.Framework;
 
 namespace Lucene.Net
@@ -85,6 +87,12 @@ namespace Lucene.Net
             Assert.Null(o, msg);
         }
 
+        protected static void assertArrayEquals(IEnumerable a1, IEnumerable a2)
+        {
+            if (!a1.Equals(a2))
+                Fail();
+        }
+
         protected static void fail()
         {
             Fail();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd24ffc4/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs b/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
index 00f1711..9c3fcea 100644
--- a/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
+++ b/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
@@ -43,6 +43,11 @@ namespace Lucene.Net
             return list.Count;
         }
 
+        public static T[] clone<T>(this T[] e)
+        {
+            return (T[]) e.Clone();
+        }
+
         public static void printStackTrace(this Exception e)
         {
             Console.WriteLine(e.StackTrace);


Mime
View raw message