You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2015/02/05 18:10:28 UTC
[1/2] lucenenet git commit: Another LongRunningTest backed by a
shorter one
Repository: lucenenet
Updated Branches:
refs/heads/master 086ef2e02 -> 5e9250f84
Another LongRunningTest backed by a shorter one
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/903d8857
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/903d8857
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/903d8857
Branch: refs/heads/master
Commit: 903d88578b2ffbcc40c203d7673881005f92db5a
Parents: 086ef2e
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Thu Feb 5 18:17:37 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Thu Feb 5 18:17:37 2015 +0200
----------------------------------------------------------------------
.../core/Util/Packed/TestEliasFanoSequence.cs | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/903d8857/src/Lucene.Net.Tests/core/Util/Packed/TestEliasFanoSequence.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/Packed/TestEliasFanoSequence.cs b/src/Lucene.Net.Tests/core/Util/Packed/TestEliasFanoSequence.cs
index a34d321..3fc1717 100644
--- a/src/Lucene.Net.Tests/core/Util/Packed/TestEliasFanoSequence.cs
+++ b/src/Lucene.Net.Tests/core/Util/Packed/TestEliasFanoSequence.cs
@@ -1,3 +1,4 @@
+using Lucene.Net.Attributes;
using NUnit.Framework;
using System;
using System.Diagnostics;
@@ -307,10 +308,25 @@ namespace Lucene.Net.Util.Packed
[Test]
public virtual void TestStrictMonotoneSequences()
{
- // for (int s = 2; s < 1222; s++) {
+ for (int s = 2; s < 1222; s++)
+ {
+ var values = new long[s];
+ for (int i = 0; i < s; i++)
+ {
+ values[i] = i * ((long)i - 1) / 2; // Add a gap of (s-1) to previous
+ // s = (s*(s+1) - (s-1)*s)/2
+ }
+ TstEFS2(values);
+ }
+ }
+
+ [Test]
+ [LongRunningTest]
+ public virtual void TestStrictMonotoneSequencesLonger()
+ {
for (int s = 2; s < 4422; s++)
{
- long[] values = new long[s];
+ var values = new long[s];
for (int i = 0; i < s; i++)
{
values[i] = i * ((long)i - 1) / 2; // Add a gap of (s-1) to previous
[2/2] lucenenet git commit: Fixing another reflection test
Posted by sy...@apache.org.
Fixing another reflection test
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/5e9250f8
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/5e9250f8
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/5e9250f8
Branch: refs/heads/master
Commit: 5e9250f84a8598c9ed570dc3da23517cd5a5c7e6
Parents: 903d885
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Thu Feb 5 19:10:12 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Thu Feb 5 19:10:12 2015 +0200
----------------------------------------------------------------------
src/Lucene.Net.Core/Analysis/TokenStream.cs | 42 +++++++++++++-----------
src/Lucene.Net.Tests/core/TestAssertions.cs | 18 ++++++----
2 files changed, 34 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5e9250f8/src/Lucene.Net.Core/Analysis/TokenStream.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Analysis/TokenStream.cs b/src/Lucene.Net.Core/Analysis/TokenStream.cs
index c1c9d98..5f2aebb 100644
--- a/src/Lucene.Net.Core/Analysis/TokenStream.cs
+++ b/src/Lucene.Net.Core/Analysis/TokenStream.cs
@@ -1,4 +1,7 @@
using System.Diagnostics;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
using Lucene.Net.Analysis.Tokenattributes;
using System;
using Lucene.Net.Documents;
@@ -86,48 +89,49 @@ namespace Lucene.Net.Analysis
/// <summary>
/// A TokenStream using the default attribute factory.
/// </summary>
- protected internal TokenStream()
+ protected TokenStream()
{
- //Debug.Assert(AssertFinal());
+ Debug.Assert(AssertFinal());
}
/// <summary>
/// A TokenStream that uses the same attributes as the supplied one.
/// </summary>
- protected internal TokenStream(AttributeSource input)
+ protected TokenStream(AttributeSource input)
: base(input)
{
- //Debug.Assert(AssertFinal());
+ Debug.Assert(AssertFinal());
}
/// <summary>
/// A TokenStream using the supplied AttributeFactory for creating new <seealso cref="Attribute"/> instances.
/// </summary>
- protected internal TokenStream(AttributeFactory factory)
+ protected TokenStream(AttributeFactory factory)
: base(factory)
{
- //Debug.Assert(AssertFinal());
+ Debug.Assert(AssertFinal());
}
- /* LUCENENET TO-DO
private bool AssertFinal()
{
- try
- {
- Type clazz = this.GetType();
- if (!clazz.desiredAssertionStatus())
+ var type = this.GetType();
+
+ //if (!type.desiredAssertionStatus()) return true; // not supported in .NET
+
+ var hasCompilerGeneratedAttribute =
+ type.GetCustomAttributes(typeof (CompilerGeneratedAttribute), false).Any();
+ var isAnonymousType = hasCompilerGeneratedAttribute && type.FullName.Contains("AnonymousType");
+
+ var method = type.GetMethod("IncrementToken", BindingFlags.Public | BindingFlags.Instance);
+
+ if (!(isAnonymousType || type.IsSealed || (method != null && method.IsFinal)))
{
- return true;
+ // Original Java code throws an AssertException via Java's assert, we can't do this here
+ throw new InvalidOperationException("TokenStream implementation classes or at least their IncrementToken() implementation must be marked sealed");
}
- Debug.Assert(clazz.AnonymousClass || (clazz.Modifiers & (Modifier.FINAL | Modifier.PRIVATE)) != 0 || Modifier.isFinal(clazz.GetMethod("incrementToken").Modifiers), "TokenStream implementation classes or at least their IncrementToken() implementation must be final");
+
return true;
- }
- catch (Exception nsme)
- {
- return false;
- }
}
- */
/// <summary>
/// Consumers (i.e., <seealso cref="IndexWriter"/>) use this method to advance the stream to
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5e9250f8/src/Lucene.Net.Tests/core/TestAssertions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/TestAssertions.cs b/src/Lucene.Net.Tests/core/TestAssertions.cs
index 22f9f4e..cf41b27 100644
--- a/src/Lucene.Net.Tests/core/TestAssertions.cs
+++ b/src/Lucene.Net.Tests/core/TestAssertions.cs
@@ -1,3 +1,5 @@
+using System.Diagnostics;
+
namespace Lucene.Net.Tests
{
using NUnit.Framework;
@@ -30,7 +32,7 @@ namespace Lucene.Net.Tests
internal class TestTokenStream1 : TokenStream
{
- public override bool IncrementToken()
+ public sealed override bool IncrementToken()
{
return false;
}
@@ -55,19 +57,21 @@ namespace Lucene.Net.Tests
[Test]
public virtual void TestTokenStreams()
{
- new TestTokenStream1();
- new TestTokenStream2();
- bool doFail = false;
+ // In Java, an AssertionError is expected: TokenStream implementation classes or at least their incrementToken() implementation must be final
+
+ var a = new TestTokenStream1();
+ var b = new TestTokenStream2();
+ var doFail = false;
try
{
- new TestTokenStream3();
+ var c = new TestTokenStream3();
doFail = true;
}
- catch (InvalidOperationException e)
+ catch (InvalidOperationException)
{
// expected
}
- Assert.IsFalse(doFail, "TestTokenStream3 should fail assertion");
+ assertFalse("TestTokenStream3 should fail assertion", doFail);
}
}