lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject git commit: Working on tests
Date Mon, 04 Aug 2014 23:45:58 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/branch_4x 23d1c0ac8 -> e83a5d617


Working on tests


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

Branch: refs/heads/branch_4x
Commit: e83a5d617345ebdae390d596e25c674d03d1df87
Parents: 23d1c0a
Author: Itamar Syn-Hershko <itamar@code972.com>
Authored: Tue Aug 5 02:45:25 2014 +0300
Committer: Itamar Syn-Hershko <itamar@code972.com>
Committed: Tue Aug 5 02:45:25 2014 +0300

----------------------------------------------------------------------
 src/core/Util/ArrayUtil.cs                      |  2 +-
 test/core/Lucene.Net.Test.csproj                |  1 +
 test/core/Util/TestBytesRef.cs                  | 71 ++++++++---------
 .../JavaCompatibility/LuceneTestCase.cs         |  8 +-
 .../JavaCompatibility/RandomHelpers.cs          | 12 +++
 .../JavaCompatibility/SystemTypesHelpers.cs     |  7 +-
 .../Lucene.Net.TestFramework.csproj             |  1 +
 .../Randomized/Generators/RandomInts.cs         |  8 +-
 test/test-framework/Support/RandomizedTest.cs   |  6 +-
 test/test-framework/Support/SystemProperties.cs |  6 +-
 test/test-framework/Util/_TestUtil.cs           | 81 +++++++++++++++++---
 11 files changed, 139 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/src/core/Util/ArrayUtil.cs
----------------------------------------------------------------------
diff --git a/src/core/Util/ArrayUtil.cs b/src/core/Util/ArrayUtil.cs
index 2737e66..f650893 100644
--- a/src/core/Util/ArrayUtil.cs
+++ b/src/core/Util/ArrayUtil.cs
@@ -45,7 +45,7 @@ namespace Lucene.Net.Util
         /// </param>
         /// <returns> int the value represented by the argument
         /// </returns>
-        /// <throws>  NumberFormatException if the argument could not be parsed as
an int quantity. </throws>
+        /// <throws>FormatException if the argument could not be parsed as an int quantity.
</throws>
         public static int ParseInt(char[] chars)
         {
             return ParseInt(chars, 0, chars.Length, 10);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/test/core/Lucene.Net.Test.csproj
----------------------------------------------------------------------
diff --git a/test/core/Lucene.Net.Test.csproj b/test/core/Lucene.Net.Test.csproj
index 34c4c30..a8f6c9a 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\TestBytesRef.cs" />
     <None Include="App.config" />
     <None Include="Index\index.19.cfs.zip" />
     <None Include="Index\index.19.nocfs.zip" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/test/core/Util/TestBytesRef.cs
----------------------------------------------------------------------
diff --git a/test/core/Util/TestBytesRef.cs b/test/core/Util/TestBytesRef.cs
index 4e8b0b9..6706c89 100644
--- a/test/core/Util/TestBytesRef.cs
+++ b/test/core/Util/TestBytesRef.cs
@@ -1,68 +1,69 @@
 using System;
 using Lucene.Net.Util;
-using NUnit.Framework;
 
 namespace Lucene.Net.Test.Util
 {
-    [TestFixture]
     public class TestBytesRef : LuceneTestCase
     {
-        [Test]
         public void TestEmpty()
         {
-            var b = new BytesRef();
-            Assert.Equals(BytesRef.EMPTY_BYTES, b.bytes);
-            Assert.Equals(0, b.offset);
-            Assert.Equals(0, b.length);
+            BytesRef b = new BytesRef();
+            assertEquals(BytesRef.EMPTY_BYTES, b.bytes);
+            assertEquals(0, b.offset);
+            assertEquals(0, b.length);
         }
 
-        [Test]
         public void TestFromBytes()
         {
-            var bytes = new sbyte[] { (sbyte)'a', (sbyte)'b', (sbyte)'c', (sbyte)'d' };
-            var b = new BytesRef(bytes);
-            Assert.Equals(bytes, b.bytes);
-            Assert.Equals(0, b.offset);
-            Assert.Equals(4, b.length);
+            var bytes = new[]
+            {
+                (sbyte) 'a', (sbyte) 'b', (sbyte) 'c', (sbyte) 'd'
+            };
 
-            var b2 = new BytesRef(bytes, 1, 3);
-            Assert.Equals("bcd", b2.Utf8ToString());
 
-            Assert.IsFalse(b.Equals(b2));
+            BytesRef b = new BytesRef(bytes);
+            assertEquals(bytes, b.bytes);
+            assertEquals(0, b.offset);
+            assertEquals(4, b.length);
+            BytesRef b2 = new BytesRef(bytes, 1, 3);
+            assertEquals(@"bcd", b2.Utf8ToString());
+            assertFalse(b.Equals(b2));
         }
 
-        [Test]
         public void TestFromChars()
         {
-            for (var i = 0; i < 100; i++)
+            for (int i = 0; i < 100; i++)
             {
-                string s = _TestUtil.RandomUnicodeString(new Random());
+                string s = _TestUtil.randomUnicodeString(new Random());
                 string s2 = new BytesRef(s).Utf8ToString();
-                Assert.Equals(s, s2);
+                assertEquals(s, s2);
             }
 
-            // only for 4.x
-            Assert.Equals("\uFFFF", new BytesRef("\uFFFF").Utf8ToString());
+            assertEquals(@"?", new BytesRef(@"?").Utf8ToString());
         }
 
-        // LUCENE-3590, AIOOBE if you append to a bytesref with offset != 0
-        [Test]
         public void TestAppend()
         {
-            var bytes = new sbyte[] { (sbyte)'a', (sbyte)'b', (sbyte)'c', (sbyte)'d' };
-            var b = new BytesRef(bytes, 1, 3); // bcd
-            b.Append(new BytesRef("e"));
-            Assert.Equals("bcde", b.Utf8ToString());
+            var bytes = new[]
+            {
+            (sbyte)'a', (sbyte)'b', (sbyte)'c', (sbyte)'d'
+            };
+
+            BytesRef b = new BytesRef(bytes, 1, 3);
+            b.Append(new BytesRef(@"e"));
+            assertEquals(@"bcde", b.Utf8ToString());
         }
 
-        // LUCENE-3590, AIOOBE if you copy to a bytesref with offset != 0
-        [Test]
         public void TestCopyBytes()
         {
-            var bytes = new sbyte[] { (sbyte)'a', (sbyte)'b', (sbyte)'c', (sbyte)'d' };
-            var b = new BytesRef(bytes, 1, 3); // bcd
-            b.CopyBytes(new BytesRef("bcde"));
-            Assert.Equals("bcde", b.Utf8ToString());
+            var bytes = new[]
+            {
+                (sbyte) 'a', (sbyte) 'b', (sbyte) 'c', (sbyte) 'd'
+            };
+
+            BytesRef b = new BytesRef(bytes, 1, 3);
+            b.CopyBytes(new BytesRef(@"bcde"));
+            assertEquals(@"bcde", b.Utf8ToString());
         }
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/test/test-framework/JavaCompatibility/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/JavaCompatibility/LuceneTestCase.cs b/test/test-framework/JavaCompatibility/LuceneTestCase.cs
index 17ca894..4f8e95a 100644
--- a/test/test-framework/JavaCompatibility/LuceneTestCase.cs
+++ b/test/test-framework/JavaCompatibility/LuceneTestCase.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using System;
+using NUnit.Framework;
 
 namespace Lucene.Net
 {
@@ -93,5 +94,10 @@ namespace Lucene.Net
         {
             Fail(message);
         }
+
+        protected Random Random()
+        {
+            return new Random();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/test/test-framework/JavaCompatibility/RandomHelpers.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/JavaCompatibility/RandomHelpers.cs b/test/test-framework/JavaCompatibility/RandomHelpers.cs
new file mode 100644
index 0000000..bc49963
--- /dev/null
+++ b/test/test-framework/JavaCompatibility/RandomHelpers.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace Lucene.Net.JavaCompatibility
+{
+    public static class RandomHelpers
+    {
+        public static int nextInt(this Random random, int maxValue)
+        {
+            return random.Next(maxValue);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs b/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
index 7e00d1f..00f1711 100644
--- a/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
+++ b/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
@@ -1,7 +1,5 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
-using System.Linq;
 using System.Text;
 
 namespace Lucene.Net
@@ -44,5 +42,10 @@ namespace Lucene.Net
         {
             return list.Count;
         }
+
+        public static void printStackTrace(this Exception e)
+        {
+            Console.WriteLine(e.StackTrace);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/test/test-framework/Lucene.Net.TestFramework.csproj
----------------------------------------------------------------------
diff --git a/test/test-framework/Lucene.Net.TestFramework.csproj b/test/test-framework/Lucene.Net.TestFramework.csproj
index 0e56061..187667b 100644
--- a/test/test-framework/Lucene.Net.TestFramework.csproj
+++ b/test/test-framework/Lucene.Net.TestFramework.csproj
@@ -56,6 +56,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="JavaCompatibility\RandomHelpers.cs" />
     <Compile Include="Randomized\Attributes\SeedAttribute.cs" />
     <Compile Include="Analysis\MockFixedLengthPayloadFilter.cs" />
     <Compile Include="Analysis\MockTokenFilter.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/test/test-framework/Randomized/Generators/RandomInts.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/Randomized/Generators/RandomInts.cs b/test/test-framework/Randomized/Generators/RandomInts.cs
index 9b88257..2af6bcd 100644
--- a/test/test-framework/Randomized/Generators/RandomInts.cs
+++ b/test/test-framework/Randomized/Generators/RandomInts.cs
@@ -1,13 +1,15 @@
 using System;
-using System.Collections.Generic;
 using System.Diagnostics;
-using System.Linq;
-using System.Text;
 
 namespace Lucene.Net.Randomized.Generators
 {
     public static class RandomInts
     {
+        public static int randomIntBetween(Random random, int start, int end)
+        {
+            return random.NextIntBetween(start, end);
+        }
+
         public static int NextIntBetween(this Random random, int min, int max)
         {
             Debug.Assert(min <= max, String.Format("Min must be less than or equal max
int. min: {0}, max: {1}", min, max));

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/test/test-framework/Support/RandomizedTest.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/Support/RandomizedTest.cs b/test/test-framework/Support/RandomizedTest.cs
index 41485b9..87de4bd 100644
--- a/test/test-framework/Support/RandomizedTest.cs
+++ b/test/test-framework/Support/RandomizedTest.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Linq;
-using System.Text;
+using System.Configuration;
 
 namespace Lucene.Net.TestFramework.Support
 {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/test/test-framework/Support/SystemProperties.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/Support/SystemProperties.cs b/test/test-framework/Support/SystemProperties.cs
index eadd831..d851878 100644
--- a/test/test-framework/Support/SystemProperties.cs
+++ b/test/test-framework/Support/SystemProperties.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Linq;
-using System.Text;
+using System.Configuration;
 
 namespace Lucene.Net.TestFramework.Support
 {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e83a5d61/test/test-framework/Util/_TestUtil.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/Util/_TestUtil.cs b/test/test-framework/Util/_TestUtil.cs
index ed019ab..c3d67d4 100644
--- a/test/test-framework/Util/_TestUtil.cs
+++ b/test/test-framework/Util/_TestUtil.cs
@@ -1,24 +1,81 @@
 using System;
-using Lucene.Net.Support;
-using NUnit.Framework;
+using Lucene.Net.JavaCompatibility;
+using Lucene.Net.Randomized.Generators;
 
 namespace Lucene.Net.Util
 {
     public class _TestUtil
     {
-//        public static void assertAttributeReflection<T>(AttributeImpl att, HashMap<String,T>
reflectedValues) {
-//    var map = new HashMap<String,Object>();
-//    att.reflectWith(new AttributeReflector() {
-//      @Override
-//      public void reflect(Class<? extends Attribute> attClass, String key, Object
value) {
-//        map.put(attClass.getName() + '#' + key, value);
-//      }
-//    });
-//    Assert.AreEqual(reflectedValues, map, "Reflection does not produce same map");
-//  }
         internal static void CheckIndex(Store.BaseDirectoryWrapper baseDirectoryWrapper,
bool p)
         {
             throw new NotImplementedException();
         }
+
+        public static int nextInt(Random r, int start, int end)
+        {
+            return RandomInts.randomIntBetween(r, start, end);
+        }
+
+        /** Returns random string, including full unicode range. */
+        public static String randomUnicodeString(Random r)
+        {
+            return randomUnicodeString(r, 20);
+        }
+
+        /**
+         * Returns a random string up to a certain length.
+         */
+        public static String randomUnicodeString(Random r, int maxLength)
+        {
+            int end = nextInt(r, 0, maxLength);
+            if (end == 0)
+            {
+                // allow 0 length
+                return "";
+            }
+            char[] buffer = new char[end];
+            randomFixedLengthUnicodeString(r, buffer, 0, buffer.Length);
+            return new String(buffer, 0, end);
+        }
+
+
+        /**
+         * Fills provided char[] with valid random unicode code
+         * unit sequence.
+         */
+
+        public static void randomFixedLengthUnicodeString(Random random, char[] chars, int
offset, int length)
+        {
+            int i = offset;
+            int end = offset + length;
+            while (i < end)
+            {
+                int t = random.nextInt(5);
+                if (0 == t && i < length - 1)
+                {
+                    // Make a surrogate pair
+                    // High surrogate
+                    chars[i++] = (char)nextInt(random, 0xd800, 0xdbff);
+                    // Low surrogate
+                    chars[i++] = (char)nextInt(random, 0xdc00, 0xdfff);
+                }
+                else if (t <= 1)
+                {
+                    chars[i++] = (char)random.nextInt(0x80);
+                }
+                else if (2 == t)
+                {
+                    chars[i++] = (char)nextInt(random, 0x80, 0x7ff);
+                }
+                else if (3 == t)
+                {
+                    chars[i++] = (char)nextInt(random, 0x800, 0xd7ff);
+                }
+                else if (4 == t)
+                {
+                    chars[i++] = (char)nextInt(random, 0xe000, 0xffff);
+                }
+            }
+        }
     }
 }


Mime
View raw message