You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by cc...@apache.org on 2011/11/18 18:54:16 UTC
[Lucene.Net] svn commit: r1203769 [3/4] - in
/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk: src/core/
src/core/Analysis/ src/core/Document/ src/core/Messages/
src/core/QueryParser/ src/core/Search/ src/core/Search/Function/
src/core/Search/Payloads/ src/cor...
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/PrefixQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/PrefixQuery.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/PrefixQuery.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/PrefixQuery.cs Fri Nov 18 17:54:13 2011
@@ -37,7 +37,7 @@ namespace Lucene.Net.Search
private Term prefix;
/// <summary>Constructs a query for terms starting with <c>prefix</c>. </summary>
- public PrefixQuery(Term prefix):base(prefix)
+ public PrefixQuery(Term prefix)
{ //will be removed in 3.0
this.prefix = prefix;
}
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/Query.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/Query.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/Query.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/Query.cs Fri Nov 18 17:54:13 2011
@@ -16,6 +16,7 @@
*/
using System;
+using System.Linq;
using Lucene.Net.Index;
using IndexReader = Lucene.Net.Index.IndexReader;
@@ -34,7 +35,7 @@ namespace Lucene.Net.Search
/// <item> <see cref="MultiPhraseQuery" /> </item>
/// <item> <see cref="FuzzyQuery" /> </item>
/// <item> <see cref="TermRangeQuery" /> </item>
- /// <item> <see cref="NumericRangeQuery" /> </item>
+ /// <item> <see cref="NumericRangeQuery{T}" /> </item>
/// <item> <see cref="Lucene.Net.Search.Spans.SpanQuery" /> </item>
/// </list>
/// <p/>A parser for queries is contained in:
@@ -166,10 +167,7 @@ namespace Lucene.Net.Search
// optimization: if we have just one query, just return it
if (uniques.Count == 1)
{
- foreach (Query key in uniques)
- {
- return key;
- }
+ return uniques.First();
}
BooleanQuery result = new BooleanQuery(true);
foreach (Query key in uniques)
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/QueryWrapperFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/QueryWrapperFilter.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/QueryWrapperFilter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/QueryWrapperFilter.cs Fri Nov 18 17:54:13 2011
@@ -37,49 +37,6 @@ namespace Lucene.Net.Search
[Serializable]
public class QueryWrapperFilter:Filter
{
- private class AnonymousClassCollector:Collector
- {
- public AnonymousClassCollector(System.Collections.BitArray bits, QueryWrapperFilter enclosingInstance)
- {
- InitBlock(bits, enclosingInstance);
- }
- private void InitBlock(System.Collections.BitArray bits, QueryWrapperFilter enclosingInstance)
- {
- this.bits = bits;
- this.enclosingInstance = enclosingInstance;
- }
- private System.Collections.BitArray bits;
- private QueryWrapperFilter enclosingInstance;
- public QueryWrapperFilter Enclosing_Instance
- {
- get
- {
- return enclosingInstance;
- }
-
- }
- private int base_Renamed = 0;
- public override void SetScorer(Scorer scorer)
- {
- // score is not needed by this collector
- }
- public override void Collect(int doc)
- {
- for (int i = 0; doc + base_Renamed >= bits.Length; i =+ 64)
- {
- bits.Length += i;
- }
- bits.Set(doc + base_Renamed, true); // set bit for hit
- }
- public override void SetNextReader(IndexReader reader, int docBase)
- {
- base_Renamed = docBase;
- }
- public override bool AcceptsDocsOutOfOrder()
- {
- return true;
- }
- }
private class AnonymousClassDocIdSet:DocIdSet
{
public AnonymousClassDocIdSet(Lucene.Net.Search.Weight weight, Lucene.Net.Index.IndexReader reader, QueryWrapperFilter enclosingInstance)
@@ -122,17 +79,6 @@ namespace Lucene.Net.Search
this.query = query;
}
- /// <deprecated> Use <see cref="GetDocIdSet(IndexReader)" /> instead.
- /// </deprecated>
- [Obsolete("Use GetDocIdSet(IndexReader) instead.")]
- public override System.Collections.BitArray Bits(IndexReader reader)
- {
- System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64);
-
- new IndexSearcher(reader).Search(query, new AnonymousClassCollector(bits, this));
- return bits;
- }
-
public override DocIdSet GetDocIdSet(IndexReader reader)
{
Weight weight = query.Weight(new IndexSearcher(reader));
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/Spans/NearSpansUnordered.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/Spans/NearSpansUnordered.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/Spans/NearSpansUnordered.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/Spans/NearSpansUnordered.cs Fri Nov 18 17:54:13 2011
@@ -16,6 +16,7 @@
*/
using System;
+using System.Linq;
using Lucene.Net.Util;
using IndexReader = Lucene.Net.Index.IndexReader;
@@ -154,7 +155,7 @@ namespace Lucene.Net.Search.Spans
// TODO: Remove warning after API has been finalized
public override System.Collections.Generic.ICollection<byte[]> GetPayload()
{
- return spans.GetPayload();
+ return spans.GetPayload().ToArray();
}
// TODO: Remove warning after API has been finalized
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/TermRangeFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/TermRangeFilter.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/TermRangeFilter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/TermRangeFilter.cs Fri Nov 18 17:54:13 2011
@@ -25,7 +25,7 @@ namespace Lucene.Net.Search
///
/// <p/>This filter matches the documents looking for terms that fall into the
/// supplied range according to <see cref="String.CompareTo(String)" />. It is not intended
- /// for numerical ranges, use <see cref="NumericRangeFilter" /> instead.
+ /// for numerical ranges, use <see cref="NumericRangeFilter{T}" /> instead.
///
/// <p/>If you construct a large number of range filters with different ranges but on the
/// same field, <see cref="FieldCacheRangeFilter" /> may have significantly better performance.
@@ -33,7 +33,7 @@ namespace Lucene.Net.Search
/// <since> 2.9
/// </since>
[Serializable]
- public class TermRangeFilter:MultiTermQueryWrapperFilter
+ public class TermRangeFilter:MultiTermQueryWrapperFilter<TermRangeQuery>
{
/// <param name="fieldName">The field this range applies to
@@ -100,37 +100,37 @@ namespace Lucene.Net.Search
/// <summary>Returns the field name for this filter </summary>
public virtual System.String GetField()
{
- return ((TermRangeQuery) query).GetField();
+ return query.GetField();
}
/// <summary>Returns the lower value of this range filter </summary>
public virtual System.String GetLowerTerm()
{
- return ((TermRangeQuery) query).GetLowerTerm();
+ return query.GetLowerTerm();
}
/// <summary>Returns the upper value of this range filter </summary>
public virtual System.String GetUpperTerm()
{
- return ((TermRangeQuery) query).GetUpperTerm();
+ return query.GetUpperTerm();
}
/// <summary>Returns <c>true</c> if the lower endpoint is inclusive </summary>
public virtual bool IncludesLower()
{
- return ((TermRangeQuery) query).IncludesLower();
+ return query.IncludesLower();
}
/// <summary>Returns <c>true</c> if the upper endpoint is inclusive </summary>
public virtual bool IncludesUpper()
{
- return ((TermRangeQuery) query).IncludesUpper();
+ return query.IncludesUpper();
}
/// <summary>Returns the collator used to determine range inclusion, if any. </summary>
public virtual System.Globalization.CompareInfo GetCollator()
{
- return ((TermRangeQuery) query).GetCollator();
+ return query.GetCollator();
}
}
}
\ No newline at end of file
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/TermRangeQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/TermRangeQuery.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/TermRangeQuery.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/TermRangeQuery.cs Fri Nov 18 17:54:13 2011
@@ -27,7 +27,7 @@ namespace Lucene.Net.Search
///
/// <p/>This query matches the documents looking for terms that fall into the
/// supplied range according to <see cref="String.CompareTo(String)" />. It is not intended
- /// for numerical ranges, use <see cref="NumericRangeQuery" /> instead.
+ /// for numerical ranges, use <see cref="NumericRangeQuery{T}" /> instead.
///
/// <p/>This query uses the <see cref="MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT" />
///
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Support/HashMap.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Support/HashMap.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Support/HashMap.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Support/HashMap.cs Fri Nov 18 17:54:13 2011
@@ -13,13 +13,15 @@ namespace Lucene.Net.Support
/// only supports null values not keys. Also, <c>V Get(TKey)</c>
/// method in Java returns null if the key doesn't exist, instead of throwing
/// an exception. This implementation doesn't throw an exception when a key
- /// doesn't exist, it will return null.
+ /// doesn't exist, it will return null. This class is slower than using a
+ /// <see cref="Dictionary{TKey, TValue}"/>, because of extra checks that have to be
+ /// done on each access, to check for null.
/// </para>
/// <para>
- /// <b>NOTE:</b> This class shouldn't be used with non-nullable value types.
- /// Using them will cause unexpected behavior, because of comparisons to default(T)
- /// which, Nullable<T> returns as null, and any other value types will not. A
- /// Dictionary would work fine in that use case.
+ /// <b>NOTE:</b> This class works best with nullable types. default(T) is returned
+ /// when a key doesn't exist in the collection (this being similar to how Java returns
+ /// null). Therefore, if the expected behavior of the java code is to execute code
+ /// based on if the key exists, when the key is an integer type, it will return 0 instead of null.
/// </para>
/// <remaks>
/// Consider also implementing IDictionary, IEnumerable, and ICollection
@@ -32,13 +34,15 @@ namespace Lucene.Net.Support
[Serializable]
public class HashMap<TKey, TValue> : IDictionary<TKey, TValue>
{
- private EqualityComparer<TKey> _comparer;
- private Dictionary<TKey, TValue> _dict;
+ internal EqualityComparer<TKey> _comparer;
+ internal Dictionary<TKey, TValue> _dict;
// Indicates if a null key has been assigned, used for iteration
private bool _hasNullValue;
// stores the value for the null key
private TValue _nullValue;
+ // Indicates the type of key is a non-nullable valuetype
+ private bool _isValueType;
public HashMap()
: this(0)
@@ -49,6 +53,11 @@ namespace Lucene.Net.Support
_dict = new Dictionary<TKey, TValue>(initialCapacity);
_comparer = EqualityComparer<TKey>.Default;
_hasNullValue = false;
+
+ if (typeof(TKey).IsValueType)
+ {
+ _isValueType = Nullable.GetUnderlyingType(typeof(TKey)) == null;
+ }
}
public HashMap(IEnumerable<KeyValuePair<TKey, TValue>> other)
@@ -62,7 +71,7 @@ namespace Lucene.Net.Support
public bool ContainsValue(TValue value)
{
- if (_hasNullValue && _nullValue.Equals(value))
+ if (!_isValueType && _hasNullValue && _nullValue.Equals(value))
return true;
return _dict.ContainsValue(value);
@@ -72,7 +81,7 @@ namespace Lucene.Net.Support
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
- if (_hasNullValue)
+ if (!_isValueType && _hasNullValue)
{
yield return new KeyValuePair<TKey, TValue>(default(TKey), _nullValue);
}
@@ -93,15 +102,7 @@ namespace Lucene.Net.Support
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
{
- if (_comparer.Equals(item.Key, default(TKey)))
- {
- _hasNullValue = true;
- _nullValue = item.Value;
- }
- else
- {
- _dict.Add(item.Key, item.Value);
- }
+ Add(item.Key, item.Value);
}
public void Clear()
@@ -113,7 +114,7 @@ namespace Lucene.Net.Support
bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item)
{
- if (_comparer.Equals(item.Key, default(TKey)))
+ if (!_isValueType && _comparer.Equals(item.Key, default(TKey)))
{
return _hasNullValue && EqualityComparer<TValue>.Default.Equals(item.Value, _nullValue);
}
@@ -128,7 +129,7 @@ namespace Lucene.Net.Support
public bool Remove(KeyValuePair<TKey, TValue> item)
{
- if (_comparer.Equals(item.Key, default(TKey)))
+ if (!_isValueType && _comparer.Equals(item.Key, default(TKey)))
{
if (!_hasNullValue)
return false;
@@ -157,7 +158,7 @@ namespace Lucene.Net.Support
public bool ContainsKey(TKey key)
{
- if (_comparer.Equals(key, default(TKey)))
+ if (!_isValueType && _comparer.Equals(key, default(TKey)))
{
if (_hasNullValue)
{
@@ -171,27 +172,20 @@ namespace Lucene.Net.Support
public void Add(TKey key, TValue value)
{
- if (_comparer.Equals(key, default(TKey)))
+ if (!_isValueType && _comparer.Equals(key, default(TKey)))
{
_hasNullValue = true;
_nullValue = value;
}
else
{
- if (_dict.ContainsKey(key))
- {
- _dict[key] = value;
- }
- else
- {
- _dict.Add(key, value);
- }
+ _dict[key] = value;
}
}
public bool Remove(TKey key)
{
- if (_comparer.Equals(key, default(TKey)))
+ if (!_isValueType && _comparer.Equals(key, default(TKey)))
{
_hasNullValue = false;
_nullValue = default(TValue);
@@ -205,7 +199,7 @@ namespace Lucene.Net.Support
public bool TryGetValue(TKey key, out TValue value)
{
- if (_comparer.Equals(key, default(TKey)))
+ if (!_isValueType && _comparer.Equals(key, default(TKey)))
{
if (_hasNullValue)
{
@@ -226,7 +220,7 @@ namespace Lucene.Net.Support
{
get
{
- if (_comparer.Equals(key, default(TKey)))
+ if (!_isValueType && _comparer.Equals(key, default(TKey)))
{
if (!_hasNullValue)
{
@@ -236,17 +230,7 @@ namespace Lucene.Net.Support
}
return _dict.ContainsKey(key) ? _dict[key] : default(TValue);
}
- set
- {
- if (_comparer.Equals(key, default(TKey)))
- {
- _nullValue = value;
- }
- else
- {
- _dict[key] = value;
- }
- }
+ set { Add(key, value); }
}
public ICollection<TKey> Keys
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Util/NumericUtils.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Util/NumericUtils.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Util/NumericUtils.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Util/NumericUtils.cs Fri Nov 18 17:54:13 2011
@@ -16,11 +16,10 @@
*/
using System;
+using Lucene.Net.Documents;
+using Lucene.Net.Search;
using Lucene.Net.Support;
using NumericTokenStream = Lucene.Net.Analysis.NumericTokenStream;
-using NumericField = Lucene.Net.Documents.NumericField;
-using NumericRangeFilter = Lucene.Net.Search.NumericRangeFilter;
-using NumericRangeQuery = Lucene.Net.Search.NumericRangeQuery;
namespace Lucene.Net.Util
{
@@ -50,7 +49,7 @@ namespace Lucene.Net.Util
/// <p/>For easy usage, the trie algorithm is implemented for indexing inside
/// <see cref="NumericTokenStream" /> that can index <c>int</c>, <c>long</c>,
/// <c>float</c>, and <c>double</c>. For querying,
- /// <see cref="NumericRangeQuery" /> and <see cref="NumericRangeFilter" /> implement the query part
+ /// <see cref="NumericRangeQuery{T}" /> and <see cref="NumericRangeFilter{T}" /> implement the query part
/// for the same data types.
///
/// <p/>This class can also be used, to generate lexicographically sortable (according
@@ -71,7 +70,7 @@ namespace Lucene.Net.Util
} // no instance!
/// <summary> The default precision step used by <see cref="NumericField" />, <see cref="NumericTokenStream" />,
- /// <see cref="NumericRangeQuery" />, and <see cref="NumericRangeFilter" /> as default
+ /// <see cref="NumericRangeQuery{T}" />, and <see cref="NumericRangeFilter{T}" /> as default
/// </summary>
public const int PRECISION_STEP_DEFAULT = 4;
@@ -352,7 +351,7 @@ namespace Lucene.Net.Util
/// <see cref="Lucene.Net.Search.BooleanQuery" /> for each call to its
/// <see cref="LongRangeBuilder.AddRange(String,String)" />
/// method.
- /// <p/>This method is used by <see cref="NumericRangeQuery" />.
+ /// <p/>This method is used by <see cref="NumericRangeQuery{T}" />.
/// </summary>
public static void SplitLongRange(LongRangeBuilder builder, int precisionStep, long minBound, long maxBound)
{
@@ -364,7 +363,7 @@ namespace Lucene.Net.Util
/// <see cref="Lucene.Net.Search.BooleanQuery" /> for each call to its
/// <see cref="IntRangeBuilder.AddRange(String,String)" />
/// method.
- /// <p/>This method is used by <see cref="NumericRangeQuery" />.
+ /// <p/>This method is used by <see cref="NumericRangeQuery{T}" />.
/// </summary>
public static void SplitIntRange(IntRangeBuilder builder, int precisionStep, int minBound, int maxBound)
{
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Index/TestPositionBasedTermVectorMapper.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Index/TestPositionBasedTermVectorMapper.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Index/TestPositionBasedTermVectorMapper.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Index/TestPositionBasedTermVectorMapper.cs Fri Nov 18 17:54:13 2011
@@ -84,17 +84,17 @@ namespace Lucene.Net.Index
var map = mapper.GetFieldToTerms();
Assert.IsTrue(map != null, "map is null and it shouldn't be");
Assert.IsTrue(map.Count == 1, "map Size: " + map.Count + " is not: " + 1);
- System.Collections.IDictionary positions = (System.Collections.IDictionary) map["test"];
- Assert.IsTrue(positions != null, "thePositions is null and it shouldn't be");
-
- Assert.IsTrue(positions.Count == numPositions, "thePositions Size: " + positions.Count + " is not: " + numPositions);
+ var positions = map["test"];
+ Assert.IsNotNull(positions, "thePositions is null and it shouldn't be");
+
+ Assert.AreEqual(numPositions, positions.Count, "thePositions Size: " + positions.Count + " is not: " + numPositions);
System.Collections.BitArray bits = new System.Collections.BitArray((numPositions % 64 == 0?numPositions / 64:numPositions / 64 + 1) * 64);
- for (System.Collections.IEnumerator iterator = positions.GetEnumerator(); iterator.MoveNext(); )
+ for (var iterator = positions.GetEnumerator(); iterator.MoveNext(); )
{
- System.Collections.DictionaryEntry entry = (System.Collections.DictionaryEntry) iterator.Current;
- PositionBasedTermVectorMapper.TVPositionInfo info = (PositionBasedTermVectorMapper.TVPositionInfo) entry.Value;
+ var entry = iterator.Current;
+ PositionBasedTermVectorMapper.TVPositionInfo info = entry.Value;
Assert.IsTrue(info != null, "info is null and it shouldn't be");
- int pos = ((System.Int32) entry.Key);
+ int pos = (int)entry.Key;
bits.Set(pos, true);
Assert.IsTrue(info.Position == pos, info.Position + " does not equal: " + pos);
Assert.IsTrue(info.Offsets != null, "info.getOffsets() is null and it shouldn't be");
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Lucene.Net.Test.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Lucene.Net.Test.csproj?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Lucene.Net.Test.csproj (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Lucene.Net.Test.csproj Fri Nov 18 17:54:13 2011
@@ -445,6 +445,23 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="SupportClassException.cs" />
+ <Compile Include="Support\BigObject.cs" />
+ <Compile Include="Support\CollisionTester.cs" />
+ <Compile Include="Support\SmallObject.cs" />
+ <Compile Include="Support\TestCase.cs" />
+ <Compile Include="Support\TestCloseableThreadLocal.cs" />
+ <Compile Include="Support\TestEquatableList.cs" />
+ <Compile Include="Support\TestHashMap.cs" />
+ <Compile Include="Support\TestIDisposable.cs" />
+ <Compile Include="Support\TestLRUCache.cs" />
+ <Compile Include="Support\TestOldPatches.cs" />
+ <Compile Include="Support\TestOSClass.cs" />
+ <Compile Include="Support\TestSerialization.cs" />
+ <Compile Include="Support\TestThreadClass.cs" />
+ <Compile Include="Support\TestWeakHashTable.cs" />
+ <Compile Include="Support\TestWeakHashTableBehavior.cs" />
+ <Compile Include="Support\TestWeakHashTableMultiThreadAccess.cs" />
+ <Compile Include="Support\TestWeakHashTablePerformance.cs" />
<Compile Include="TestDemo.cs">
<SubType>Code</SubType>
</Compile>
@@ -455,7 +472,7 @@
<Compile Include="TestSearchForDuplicates.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="TestSupportClass.cs" />
+ <Compile Include="Support\TestSupportClass.cs" />
<Compile Include="Util\ArrayUtilTest.cs" />
<Compile Include="Util\Cache\TestSimpleLRUCache.cs" />
<Compile Include="Util\English.cs">
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Messages/MessagesTestBundle.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Messages/MessagesTestBundle.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Messages/MessagesTestBundle.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Messages/MessagesTestBundle.cs Fri Nov 18 17:54:13 2011
@@ -42,7 +42,7 @@ namespace Lucene.Net.Messages
{
// register all string ids with NLS class and initialize static string
// values
- NLS.InitializeMessages(BUNDLE_NAME, typeof(MessagesTestBundle));
+ NLS.InitializeMessages<MessagesTestBundle>(BUNDLE_NAME);
}
}
}
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestMultiValuedNumericRangeQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestMultiValuedNumericRangeQuery.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestMultiValuedNumericRangeQuery.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestMultiValuedNumericRangeQuery.cs Fri Nov 18 17:54:13 2011
@@ -76,7 +76,7 @@ namespace Lucene.Net.Search
TermRangeQuery cq = new TermRangeQuery("asc", lower.ToString().PadLeft(11, '0'), upper.ToString().PadLeft(11, '0'), true, true);
System.Int32 tempAux = (System.Int32) lower;
System.Int32 tempAux2 = (System.Int32) upper;
- NumericRangeQuery tq = NumericRangeQuery.NewIntRange("trie", tempAux, tempAux2, true, true);
+ NumericRangeQuery<int> tq = NumericRangeQuery.NewIntRange("trie", tempAux, tempAux2, true, true);
TopDocs trTopDocs = searcher.Search(cq, 1);
TopDocs nrTopDocs = searcher.Search(tq, 1);
Assert.AreEqual(trTopDocs.TotalHits, nrTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestNumericRangeQuery32.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestNumericRangeQuery32.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestNumericRangeQuery32.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestNumericRangeQuery32.cs Fri Nov 18 17:54:13 2011
@@ -16,7 +16,7 @@
*/
using System;
-
+using Lucene.Net.Index;
using NUnit.Framework;
using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
@@ -53,10 +53,10 @@ namespace Lucene.Net.Search
int lower = (distance * 3 / 2) + startOffset, upper = lower + count * distance + (distance / 3);
System.Int32 tempAux = (System.Int32) lower;
System.Int32 tempAux2 = (System.Int32) upper;
- NumericRangeQuery q = NumericRangeQuery.NewIntRange(field, precisionStep, tempAux, tempAux2, true, true);
+ NumericRangeQuery<int> q = NumericRangeQuery.NewIntRange(field, precisionStep, tempAux, tempAux2, true, true);
System.Int32 tempAux3 = (System.Int32) lower;
System.Int32 tempAux4 = (System.Int32) upper;
- NumericRangeFilter f = NumericRangeFilter.NewIntRange(field, precisionStep, tempAux3, tempAux4, true, true);
+ NumericRangeFilter<int> f = NumericRangeFilter.NewIntRange(field, precisionStep, tempAux3, tempAux4, true, true);
int lastTerms = 0;
for (sbyte i = 0; i < 3; i++)
{
@@ -131,7 +131,7 @@ namespace Lucene.Net.Search
{
System.Int32 tempAux = 1000;
System.Int32 tempAux2 = - 1000;
- NumericRangeFilter f = NumericRangeFilter.NewIntRange("field8", 8, tempAux, tempAux2, true, true);
+ NumericRangeFilter<int> f = NumericRangeFilter.NewIntRange("field8", 8, tempAux, tempAux2, true, true);
Assert.AreSame(DocIdSet.EMPTY_DOCIDSET, f.GetDocIdSet(searcher.GetIndexReader()), "A inverse range should return the EMPTY_DOCIDSET instance");
//UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
System.Int32 tempAux3 = (System.Int32) System.Int32.MaxValue;
@@ -148,7 +148,7 @@ namespace Lucene.Net.Search
{
System.Int32 tempAux = 1000;
System.Int32 tempAux2 = 1000;
- NumericRangeQuery q = NumericRangeQuery.NewIntRange("ascfield8", 8, tempAux, tempAux2, true, true);
+ NumericRangeQuery<int> q = NumericRangeQuery.NewIntRange("ascfield8", 8, tempAux, tempAux2, true, true);
Assert.AreSame(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE, q.GetRewriteMethod());
TopDocs topDocs = searcher.Search(q, noDocs);
ScoreDoc[] sd = topDocs.ScoreDocs;
@@ -163,7 +163,7 @@ namespace Lucene.Net.Search
int upper = (count - 1) * distance + (distance / 3) + startOffset;
//UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
System.Int32 tempAux = (System.Int32) upper;
- NumericRangeQuery q = NumericRangeQuery.NewIntRange(field, precisionStep, null, tempAux, true, true);
+ NumericRangeQuery<int> q = NumericRangeQuery.NewIntRange(field, precisionStep, null, tempAux, true, true);
TopDocs topDocs = searcher.Search(q, null, noDocs, Sort.INDEXORDER);
System.Console.Out.WriteLine("Found " + q.GetTotalNumberOfTerms() + " distinct terms in left open range for field '" + field + "'.");
ScoreDoc[] sd = topDocs.ScoreDocs;
@@ -198,9 +198,7 @@ namespace Lucene.Net.Search
System.String field = "field" + precisionStep;
int count = 3000;
int lower = (count - 1) * distance + (distance / 3) + startOffset;
- //UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
- System.Int32 tempAux = (System.Int32) lower;
- NumericRangeQuery q = NumericRangeQuery.NewIntRange(field, precisionStep, tempAux, null, true, true);
+ NumericRangeQuery<int> q = NumericRangeQuery.NewIntRange(field, precisionStep, lower, null, true, true);
TopDocs topDocs = searcher.Search(q, null, noDocs, Sort.INDEXORDER);
System.Console.Out.WriteLine("Found " + q.GetTotalNumberOfTerms() + " distinct terms in right open range for field '" + field + "'.");
ScoreDoc[] sd = topDocs.ScoreDocs;
@@ -246,7 +244,7 @@ namespace Lucene.Net.Search
// test inclusive range
System.Int32 tempAux = (System.Int32) lower;
System.Int32 tempAux2 = (System.Int32) upper;
- NumericRangeQuery tq = NumericRangeQuery.NewIntRange(field, precisionStep, tempAux, tempAux2, true, true);
+ NumericRangeQuery<int> tq = NumericRangeQuery.NewIntRange(field, precisionStep, tempAux, tempAux2, true, true);
TermRangeQuery cq = new TermRangeQuery(field, NumericUtils.IntToPrefixCoded(lower), NumericUtils.IntToPrefixCoded(upper), true, true);
TopDocs tTopDocs = searcher.Search(tq, 1);
TopDocs cTopDocs = searcher.Search(cq, 1);
@@ -469,67 +467,82 @@ namespace Lucene.Net.Search
[Test]
public virtual void TestEqualsAndHash()
{
- System.Int32 tempAux = 10;
- System.Int32 tempAux2 = 20;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test1", 4, tempAux, tempAux2, true, true));
- System.Int32 tempAux3 = 10;
- System.Int32 tempAux4 = 20;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test2", 4, tempAux3, tempAux4, false, true));
- System.Int32 tempAux5 = 10;
- System.Int32 tempAux6 = 20;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test3", 4, tempAux5, tempAux6, true, false));
- System.Int32 tempAux7 = 10;
- System.Int32 tempAux8 = 20;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test4", 4, tempAux7, tempAux8, false, false));
- //UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
- System.Int32 tempAux9 = 10;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test5", 4, tempAux9, null, true, true));
- //UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
- System.Int32 tempAux10 = 20;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test6", 4, null, tempAux10, true, true));
- //UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test1", 4, 10, 20, true, true));
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test2", 4, 10, 20, false, true));
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test3", 4, 10, 20, true, false));
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test4", 4, 10, 20, false, false));
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test5", 4, 10, null, true, true));
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test6", 4, null, 20, true, true));
QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test7", 4, null, null, true, true));
- System.Int32 tempAux11 = 10;
- System.Int32 tempAux12 = 20;
- System.Int32 tempAux13 = 10;
- System.Int32 tempAux14 = 20;
- QueryUtils.CheckEqual(NumericRangeQuery.NewIntRange("test8", 4, tempAux11, tempAux12, true, true), NumericRangeQuery.NewIntRange("test8", 4, tempAux13, tempAux14, true, true));
- System.Int32 tempAux15 = 10;
- System.Int32 tempAux16 = 20;
- System.Int32 tempAux17 = 10;
- System.Int32 tempAux18 = 20;
- QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test9", 4, tempAux15, tempAux16, true, true), NumericRangeQuery.NewIntRange("test9", 8, tempAux17, tempAux18, true, true));
- System.Int32 tempAux19 = 10;
- System.Int32 tempAux20 = 20;
- System.Int32 tempAux21 = 10;
- System.Int32 tempAux22 = 20;
- QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test10a", 4, tempAux19, tempAux20, true, true), NumericRangeQuery.NewIntRange("test10b", 4, tempAux21, tempAux22, true, true));
- System.Int32 tempAux23 = 10;
- System.Int32 tempAux24 = 20;
- System.Int32 tempAux25 = 20;
- System.Int32 tempAux26 = 10;
- QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test11", 4, tempAux23, tempAux24, true, true), NumericRangeQuery.NewIntRange("test11", 4, tempAux25, tempAux26, true, true));
- System.Int32 tempAux27 = 10;
- System.Int32 tempAux28 = 20;
- System.Int32 tempAux29 = 10;
- System.Int32 tempAux30 = 20;
- QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test12", 4, tempAux27, tempAux28, true, true), NumericRangeQuery.NewIntRange("test12", 4, tempAux29, tempAux30, false, true));
- System.Int32 tempAux31 = 10;
- System.Int32 tempAux32 = 20;
- System.Single tempAux33 = (float) 10f;
- System.Single tempAux34 = (float) 20f;
- QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test13", 4, tempAux31, tempAux32, true, true), NumericRangeQuery.NewFloatRange("test13", 4, tempAux33, tempAux34, true, true));
+ QueryUtils.CheckEqual(NumericRangeQuery.NewIntRange("test8", 4, 10, 20, true, true),
+ NumericRangeQuery.NewIntRange("test8", 4, 10, 20, true, true));
+
+ QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test9", 4, 10, 20, true, true),
+ NumericRangeQuery.NewIntRange("test9", 8, 10, 20, true, true));
+
+ QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test10a", 4, 10, 20, true, true),
+ NumericRangeQuery.NewIntRange("test10b", 4, 10, 20, true, true));
+
+ QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test11", 4, 10, 20, true, true),
+ NumericRangeQuery.NewIntRange("test11", 4, 20, 10, true, true));
+
+ QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test12", 4, 10, 20, true, true),
+ NumericRangeQuery.NewIntRange("test12", 4, 10, 20, false, true));
+
+ QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test13", 4, 10, 20, true, true),
+ NumericRangeQuery.NewFloatRange("test13", 4, 10f, 20f, true, true));
// the following produces a hash collision, because Long and Integer have the same hashcode, so only test equality:
- System.Int32 tempAux35 = 10;
- System.Int32 tempAux36 = 20;
- Query q1 = NumericRangeQuery.NewIntRange("test14", 4, tempAux35, tempAux36, true, true);
- System.Int64 tempAux37 = 10L;
- System.Int64 tempAux38 = 20L;
- Query q2 = NumericRangeQuery.NewLongRange("test14", 4, tempAux37, tempAux38, true, true);
+
+ Query q1 = NumericRangeQuery.NewIntRange("test14", 4, 10, 20, true, true);
+ Query q2 = NumericRangeQuery.NewLongRange("test14", 4, 10L, 20L, true, true);
Assert.IsFalse(q1.Equals(q2));
Assert.IsFalse(q2.Equals(q1));
}
- static TestNumericRangeQuery32()
+
+
+ private void testEnum(int lower, int upper)
+ {
+ NumericRangeQuery<int> q = NumericRangeQuery.NewIntRange("field4", 4, lower, upper, true, true);
+ FilteredTermEnum termEnum = q.GetEnum(searcher.GetIndexReader());
+ try
+ {
+ int count = 0;
+ do
+ {
+ Term t = termEnum.Term();
+ if (t != null)
+ {
+ int val = NumericUtils.PrefixCodedToInt(t.Text());
+ Assert.True(val >= lower && val <= upper, "value not in bounds");
+ count++;
+ }
+ else break;
+ } while (termEnum.Next());
+ Assert.False(termEnum.Next());
+ Console.WriteLine("TermEnum on 'field4' for range [" + lower + "," + upper + "] contained " + count +
+ " terms.");
+ }
+ finally
+ {
+ termEnum.Close();
+ }
+ }
+
+ public void testEnum()
+ {
+ int count = 3000;
+ int lower = (distance*3/2) + startOffset, upper = lower + count*distance + (distance/3);
+ // test enum with values
+ testEnum(lower, upper);
+ // test empty enum
+ testEnum(upper, lower);
+ // test empty enum outside of bounds
+ lower = distance*noDocs + startOffset;
+ upper = 2*lower;
+ testEnum(lower, upper);
+ }
+
+ static TestNumericRangeQuery32()
{
{
try
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestNumericRangeQuery64.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestNumericRangeQuery64.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestNumericRangeQuery64.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestNumericRangeQuery64.cs Fri Nov 18 17:54:13 2011
@@ -53,10 +53,10 @@ namespace Lucene.Net.Search
long lower = (distance * 3 / 2) + startOffset, upper = lower + count * distance + (distance / 3);
System.Int64 tempAux = (long) lower;
System.Int64 tempAux2 = (long) upper;
- NumericRangeQuery q = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, tempAux2, true, true);
+ NumericRangeQuery<long> q = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, tempAux2, true, true);
System.Int64 tempAux3 = (long) lower;
System.Int64 tempAux4 = (long) upper;
- NumericRangeFilter f = NumericRangeFilter.NewLongRange(field, precisionStep, tempAux3, tempAux4, true, true);
+ NumericRangeFilter<long> f = NumericRangeFilter.NewLongRange(field, precisionStep, tempAux3, tempAux4, true, true);
int lastTerms = 0;
for (sbyte i = 0; i < 3; i++)
{
@@ -137,7 +137,7 @@ namespace Lucene.Net.Search
{
System.Int64 tempAux = 1000L;
System.Int64 tempAux2 = - 1000L;
- NumericRangeFilter f = NumericRangeFilter.NewLongRange("field8", 8, tempAux, tempAux2, true, true);
+ NumericRangeFilter<long> f = NumericRangeFilter.NewLongRange("field8", 8, tempAux, tempAux2, true, true);
Assert.AreSame(DocIdSet.EMPTY_DOCIDSET, f.GetDocIdSet(searcher.GetIndexReader()), "A inverse range should return the EMPTY_DOCIDSET instance");
//UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
System.Int64 tempAux3 = (long) System.Int64.MaxValue;
@@ -155,7 +155,7 @@ namespace Lucene.Net.Search
System.Int64 tempAux = 1000L;
//UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
System.Int64 tempAux2 = 1000L;
- NumericRangeQuery q = NumericRangeQuery.NewLongRange("ascfield8", 8, tempAux, tempAux2, true, true);
+ NumericRangeQuery<long> q = NumericRangeQuery.NewLongRange("ascfield8", 8, tempAux, tempAux2, true, true);
Assert.AreSame(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE, q.GetRewriteMethod());
TopDocs topDocs = searcher.Search(q, noDocs);
ScoreDoc[] sd = topDocs.ScoreDocs;
@@ -170,7 +170,7 @@ namespace Lucene.Net.Search
long upper = (count - 1) * distance + (distance / 3) + startOffset;
//UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
System.Int64 tempAux = (long) upper;
- NumericRangeQuery q = NumericRangeQuery.NewLongRange(field, precisionStep, null, tempAux, true, true);
+ NumericRangeQuery<long> q = NumericRangeQuery.NewLongRange(field, precisionStep, null, tempAux, true, true);
TopDocs topDocs = searcher.Search(q, null, noDocs, Sort.INDEXORDER);
System.Console.Out.WriteLine("Found " + q.GetTotalNumberOfTerms() + " distinct terms in left open range for field '" + field + "'.");
ScoreDoc[] sd = topDocs.ScoreDocs;
@@ -213,7 +213,7 @@ namespace Lucene.Net.Search
long lower = (count - 1) * distance + (distance / 3) + startOffset;
//UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
System.Int64 tempAux = (long) lower;
- NumericRangeQuery q = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, null, true, true);
+ NumericRangeQuery<long> q = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, null, true, true);
TopDocs topDocs = searcher.Search(q, null, noDocs, Sort.INDEXORDER);
System.Console.Out.WriteLine("Found " + q.GetTotalNumberOfTerms() + " distinct terms in right open range for field '" + field + "'.");
ScoreDoc[] sd = topDocs.ScoreDocs;
@@ -265,7 +265,7 @@ namespace Lucene.Net.Search
// test inclusive range
System.Int64 tempAux = (long) lower;
System.Int64 tempAux2 = (long) upper;
- NumericRangeQuery tq = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, tempAux2, true, true);
+ NumericRangeQuery<long> tq = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, tempAux2, true, true);
TermRangeQuery cq = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), true, true);
TopDocs tTopDocs = searcher.Search(tq, 1);
TopDocs cTopDocs = searcher.Search(cq, 1);
@@ -512,57 +512,32 @@ namespace Lucene.Net.Search
[Test]
public virtual void TestEqualsAndHash()
{
- System.Int64 tempAux = 10L;
- System.Int64 tempAux2 = 20L;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test1", 4, tempAux, tempAux2, true, true));
- System.Int64 tempAux3 = 10L;
- System.Int64 tempAux4 = 20L;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test2", 4, tempAux3, tempAux4, false, true));
- System.Int64 tempAux5 = 10L;
- System.Int64 tempAux6 = 20L;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test3", 4, tempAux5, tempAux6, true, false));
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test1", 4, 10L, 20L, true, true));
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test2", 4, 10L, 20L, false, true));
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test3", 4, 10L, 20L, true, false));
System.Int64 tempAux7 = 10L;
- System.Int64 tempAux8 = 20L;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test4", 4, tempAux7, tempAux8, false, false));
- //UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
- System.Int64 tempAux9 = 10L;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test5", 4, tempAux9, null, true, true));
- //UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
- System.Int64 tempAux10 = 20L;
- QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test6", 4, null, tempAux10, true, true));
- //UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test4", 4, 10L, 20L, false, false));
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test5", 4, 10L, null, true, true));
+ QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test6", 4, null, 20L, true, true));
QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test7", 4, null, null, true, true));
- System.Int64 tempAux11 = 10L;
- System.Int64 tempAux12 = 20L;
- System.Int64 tempAux13 = 10L;
- System.Int64 tempAux14 = 20L;
- QueryUtils.CheckEqual(NumericRangeQuery.NewLongRange("test8", 4, tempAux11, tempAux12, true, true), NumericRangeQuery.NewLongRange("test8", 4, tempAux13, tempAux14, true, true));
- System.Int64 tempAux15 = 10L;
- System.Int64 tempAux16 = 20L;
- System.Int64 tempAux17 = 10L;
- System.Int64 tempAux18 = 20L;
- QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test9", 4, tempAux15, tempAux16, true, true), NumericRangeQuery.NewLongRange("test9", 8, tempAux17, tempAux18, true, true));
- System.Int64 tempAux19 = 10L;
- System.Int64 tempAux20 = 20L;
- System.Int64 tempAux21 = 10L;
- System.Int64 tempAux22 = 20L;
- QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test10a", 4, tempAux19, tempAux20, true, true), NumericRangeQuery.NewLongRange("test10b", 4, tempAux21, tempAux22, true, true));
- System.Int64 tempAux23 = 10L;
- System.Int64 tempAux24 = 20L;
- System.Int64 tempAux25 = 20L;
- System.Int64 tempAux26 = 10L;
- QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test11", 4, tempAux23, tempAux24, true, true), NumericRangeQuery.NewLongRange("test11", 4, tempAux25, tempAux26, true, true));
- System.Int64 tempAux27 = 10L;
- System.Int64 tempAux28 = 20L;
- System.Int64 tempAux29 = 10L;
- System.Int64 tempAux30 = 20L;
- QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test12", 4, tempAux27, tempAux28, true, true), NumericRangeQuery.NewLongRange("test12", 4, tempAux29, tempAux30, false, true));
- System.Int64 tempAux31 = 10L;
- System.Int64 tempAux32 = 20L;
- System.Single tempAux33 = (float) 10f;
- System.Single tempAux34 = (float) 20f;
- QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test13", 4, tempAux31, tempAux32, true, true), NumericRangeQuery.NewFloatRange("test13", 4, tempAux33, tempAux34, true, true));
- // difference to int range is tested in TestNumericRangeQuery32
+ QueryUtils.CheckEqual(NumericRangeQuery.NewLongRange("test8", 4, 10L, 20L, true, true),
+ NumericRangeQuery.NewLongRange("test8", 4, 10L, 20L, true, true));
+
+ QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test9", 4, 10L, 20L, true, true),
+ NumericRangeQuery.NewLongRange("test9", 8, 10L, 20L, true, true));
+
+ QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test10a", 4, 10L, 20L, true, true),
+ NumericRangeQuery.NewLongRange("test10b", 4, 10L, 20L, true, true));
+
+ QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test11", 4, 10L, 20L, true, true),
+ NumericRangeQuery.NewLongRange("test11", 4, 20L, 10L, true, true));
+
+ QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test12", 4, 10L, 20L, true, true),
+ NumericRangeQuery.NewLongRange("test12", 4, 10L, 20L, false, true));
+
+ QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test13", 4, 10L, 20L, true, true),
+ NumericRangeQuery.NewFloatRange("test13", 4, 10f, 20f, true, true));
+ // difference to int range is tested in TestNumericRangeQuery32
}
static TestNumericRangeQuery64()
{
Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Store/TestMultiMMap.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Store/TestMultiMMap.cs?rev=1203769&r1=1203768&r2=1203769&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Store/TestMultiMMap.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Store/TestMultiMMap.cs Fri Nov 18 17:54:13 2011
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using NUnit.Framework;
-namespace Lucene.Net.Test.Store
+namespace Lucene.Net.Store
{
[TestFixture]
class TestMultiMMap
@@ -12,7 +12,7 @@ namespace Lucene.Net.Test.Store
[Test]
public void TestDoesntExist()
{
- Assert.Fail("Need to port tests");
+ Assert.Ignore("Need to port tests, but we don't really support MMapDirectories anyway");
}
}
}
Added: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/BigObject.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/BigObject.cs?rev=1203769&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/BigObject.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/BigObject.cs Fri Nov 18 17:54:13 2011
@@ -0,0 +1,14 @@
+namespace Lucene.Net.Support
+{
+ internal class BigObject
+ {
+ public int i = 0;
+ public byte[] buf = null;
+
+ public BigObject(int i)
+ {
+ this.i = i;
+ buf = new byte[1024 * 1024]; //1MB
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/CollisionTester.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/CollisionTester.cs?rev=1203769&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/CollisionTester.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/CollisionTester.cs Fri Nov 18 17:54:13 2011
@@ -0,0 +1,29 @@
+namespace Lucene.Net.Support
+{
+ class CollisionTester
+ {
+ int id;
+ int hashCode;
+
+ public CollisionTester(int id, int hashCode)
+ {
+ this.id = id;
+ this.hashCode = hashCode;
+ }
+
+ public override int GetHashCode()
+ {
+ return hashCode;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (obj is CollisionTester)
+ {
+ return this.id == ((CollisionTester)obj).id;
+ }
+ else
+ return base.Equals(obj);
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/SmallObject.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/SmallObject.cs?rev=1203769&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/SmallObject.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/SmallObject.cs Fri Nov 18 17:54:13 2011
@@ -0,0 +1,12 @@
+namespace Lucene.Net.Support
+{
+ internal class SmallObject
+ {
+ public int i = 0;
+
+ public SmallObject(int i)
+ {
+ this.i = i;
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestCase.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestCase.cs?rev=1203769&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestCase.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestCase.cs Fri Nov 18 17:54:13 2011
@@ -0,0 +1,33 @@
+namespace Lucene.Net
+{
+ /// <summary>
+ /// Support for junit.framework.TestCase.getName().
+ /// {{Lucene.Net-2.9.1}} Move to another location after LUCENENET-266
+ /// </summary>
+ public class TestCase
+ {
+ public static string GetName()
+ {
+ return GetTestCaseName(false);
+ }
+
+ public static string GetFullName()
+ {
+ return GetTestCaseName(true);
+ }
+
+ static string GetTestCaseName(bool fullName)
+ {
+ System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();
+ for (int i = 0; i < stackTrace.FrameCount; i++)
+ {
+ System.Reflection.MethodBase method = stackTrace.GetFrame(i).GetMethod();
+ object[] testAttrs = method.GetCustomAttributes(typeof(NUnit.Framework.TestAttribute), false);
+ if (testAttrs != null && testAttrs.Length > 0)
+ if (fullName) return method.DeclaringType.FullName + "." + method.Name;
+ else return method.Name;
+ }
+ return "GetTestCaseName[UnknownTestMethod]";
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestCloseableThreadLocal.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestCloseableThreadLocal.cs?rev=1203769&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestCloseableThreadLocal.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestCloseableThreadLocal.cs Fri Nov 18 17:54:13 2011
@@ -0,0 +1,69 @@
+using System;
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Store;
+using NUnit.Framework;
+using Version = Lucene.Net.Util.Version;
+
+namespace Lucene.Net.Support
+{
+ [TestFixture]
+ public class TestCloseableThreadLocal
+ {
+ [Test]
+ public void TestMemLeakage()
+ {
+ CloseableThreadLocalProfiler.EnableCloseableThreadLocalProfiler = true;
+
+ int LoopCount = 100;
+ Analyzer[] analyzers = new Analyzer[LoopCount];
+ RAMDirectory[] dirs = new RAMDirectory[LoopCount];
+ IndexWriter[] indexWriters = new IndexWriter[LoopCount];
+
+ System.Threading.Tasks.Parallel.For(0, LoopCount, (i) =>
+ {
+ analyzers[i] = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Version.LUCENE_CURRENT);
+ dirs[i] = new RAMDirectory();
+ indexWriters[i] = new IndexWriter(dirs[i], analyzers[i], true, IndexWriter.MaxFieldLength.UNLIMITED);
+ });
+
+ System.Threading.Tasks.Parallel.For(0, LoopCount, (i) =>
+ {
+ Document document = new Document();
+ document.Add(new Field("field", "some test", Field.Store.NO, Field.Index.ANALYZED));
+ indexWriters[i].AddDocument(document);
+ });
+
+ System.Threading.Tasks.Parallel.For(0, LoopCount, (i) =>
+ {
+ analyzers[i].Close();
+ indexWriters[i].Close();
+ });
+
+ System.Threading.Tasks.Parallel.For(0, LoopCount, (i) =>
+ {
+ IndexSearcher searcher = new IndexSearcher(dirs[i]);
+ TopDocs d = searcher.Search(new TermQuery(new Term("field", "test")), 10);
+ searcher.Close();
+ });
+
+ System.Threading.Tasks.Parallel.For(0, LoopCount, (i) => dirs[i].Close());
+
+ GC.Collect(GC.MaxGeneration);
+ GC.WaitForPendingFinalizers();
+
+ int aliveObjects = 0;
+ foreach (WeakReference w in CloseableThreadLocalProfiler.Instances)
+ {
+ object o = w.Target;
+ if (o != null) aliveObjects++;
+ }
+
+ CloseableThreadLocalProfiler.EnableCloseableThreadLocalProfiler = false;
+
+ Assert.AreEqual(0, aliveObjects);
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestEquatableList.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestEquatableList.cs?rev=1203769&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestEquatableList.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestEquatableList.cs Fri Nov 18 17:54:13 2011
@@ -0,0 +1,146 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using NUnit.Framework;
+
+namespace Lucene.Net.Support
+{
+ [TestFixture]
+ public class TestEquatableList
+ {
+ /// <summary>
+ /// This test shows that System.Collections.Generic.List is not suitable for determining uniqueness
+ /// when used in a HashSet. This is a difference between the Java and .NET BCL Lists. Since the equatable
+ /// behaviour of java.util.List.hashCode() in Java is relied upon for the the Java Lucene implementation,
+ /// a correct port must use an equatable list with the same behaviour.
+ ///
+ /// We include this unit test here, to prove the problem with the .NET List type. If this test fails, we
+ /// can remove the SupportClass.EquatableList class, and replace it with System.Collection.Generic.List.
+ /// </summary>
+ [Test]
+ public void System_Collections_Generic_List_Not_Suitable_For_Determining_Uniqueness_In_HashSet()
+ {
+ // reference equality
+ var foo = new Object();
+ var bar = new Object();
+
+ var list1 = new List<Object> {foo, bar};
+ var list2 = new List<Object> {foo, bar};
+
+ var hashSet = new HashSet<List<Object>>();
+
+ Assert.IsTrue(hashSet.Add(list1));
+
+ // note: compare this assertion to the assertion in Suitable_For_Determining_Uniqueness_In_HashSet
+ Assert.IsTrue(hashSet.Add(list2),
+ "BCL List changed equality behaviour and is now suitable for use in HashSet! Yay!");
+ }
+
+ /// <summary>
+ /// This test shows that System.Collections.Generic.List is not suitable for determining uniqueness
+ /// when used in a Hashtable. This is a difference between the Java and .NET BCL Lists. Since the equatable
+ /// behaviour of java.util.List.hashCode() in Java is relied upon for the the Java Lucene implementation,
+ /// a correct port must use an equatable list with the same behaviour.
+ ///
+ /// We include this unit test here, to prove the problem with the .NET List type. If this test fails, we
+ /// can remove the SupportClass.EquatableList class, and replace it with System.Collection.Generic.List.
+ /// </summary>
+ [Test]
+ public void System_Collections_Generic_List_Not_Suitable_For_Determining_Uniqueness_In_Hashtable()
+ {
+ // reference equality
+ var foo = new Object();
+ var bar = new Object();
+
+ var list1 = new List<Object> {foo, bar};
+ var list2 = new List<Object> {foo, bar};
+
+ var hashTable = new Hashtable();
+
+ Assert.IsFalse(hashTable.ContainsKey(list1));
+ hashTable.Add(list1, list1);
+
+ // note: compare this assertion to the assertion in Suitable_For_Determining_Uniqueness_In_Hashtable
+ Assert.IsFalse(
+ hashTable.ContainsKey(list2),
+ "BCL List changed behaviour and is now suitable for use as a replacement for Java's List! Yay!");
+ }
+
+ /// <summary>
+ /// There is a interesting problem with .NET's String.GetHashCode() for certain strings.
+ /// This unit test displays the problem, and in the event that this is changed in the
+ /// .NET runtime, the test will fail.
+ ///
+ /// This is one of the reasons that the EquatableList implementation does not use GetHashCode()
+ /// (which is a divergence from the List.equals implementation in Java). EquatableList should have
+ /// the same overall results as Java's List however.
+ ///
+ /// For an explanation of this issue see:
+ /// http://blogs.msdn.com/b/ericlippert/archive/2011/07/12/what-curious-property-does-this-string-have.aspx
+ /// For a description of the GetHashCode implementation see:
+ /// http://www.dotnetperls.com/gethashcode
+ /// For documentation on List.getHashCode(), see:
+ /// http://download.oracle.com/javase/6/docs/api/java/util/List.html#hashCode()
+ /// And in the general case, see:
+ /// http://download.oracle.com/javase/6/docs/api/java/lang/Object.html#hashCode()
+ /// </summary>
+ [Test]
+ public void System_String_GetHashCode_Exhibits_Inconsistent_Inequality_For_Some_Values()
+ {
+ var val1 = "\uA0A2\uA0A2";
+ var val2 = string.Empty;
+
+ Assert.IsFalse(val1.Equals(val2));
+
+ var hash1 = val1.GetHashCode();
+ var hash2 = val2.GetHashCode();
+
+ // note: this is counter-intuative, but technically allowed by the contract for GetHashCode()
+ // this only works in 32 bit processes.
+
+ // if 32 bit process
+ if (IntPtr.Size == 4)
+ {
+ // TODO: determine if there is an similar issue when in a 64 bit process.
+ Assert.IsTrue(
+ hash1.Equals(hash2),
+ "BCL string.GetHashCode() no longer exhibits inconsistent inequality for certain strings."
+ );
+ }
+ }
+
+ [Test]
+ public void Suitable_For_Determining_Uniqueness_In_HashSet()
+ {
+ var foo = new Object();
+ var bar = new Object();
+
+ var list1 = new EquatableList<Object> {foo, bar};
+ var list2 = new EquatableList<Object> {foo, bar};
+
+ Assert.AreEqual(list1, list2);
+
+ var hashSet = new HashSet<List<Object>>();
+
+ Assert.IsTrue(hashSet.Add(list1));
+ Assert.IsFalse(hashSet.Add(list2));
+ }
+
+ [Test]
+ public void Suitable_For_Determining_Uniqueness_In_Hashtable()
+ {
+ var foo = new Object();
+ var bar = new Object();
+
+ var list1 = new EquatableList<Object> { foo, bar };
+ var list2 = new EquatableList<Object> { foo, bar };
+
+ var hashTable = new Hashtable();
+
+ Assert.IsFalse(hashTable.ContainsKey(list1));
+ hashTable.Add(list1, list1);
+
+ Assert.IsTrue(hashTable.ContainsKey(list2));
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestHashMap.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestHashMap.cs?rev=1203769&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestHashMap.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestHashMap.cs Fri Nov 18 17:54:13 2011
@@ -0,0 +1,192 @@
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+
+namespace Lucene.Net.Support
+{
+ [TestFixture]
+ public class TestHashMap
+ {
+ private static HashMap<TKey, TValue> GetNewHashMap<TKey, TValue>()
+ {
+ return new HashMap<TKey, TValue>();
+ }
+
+ private static HashMap<string,string> GetDefaultHashMap1()
+ {
+ var hm = GetNewHashMap<string, string>();
+ hm.Add("key1", "value1");
+ hm.Add("key2", "value2");
+ return hm;
+ }
+
+ [Test]
+ public void TestKeyEnumeration()
+ {
+ var keys = new List<string> {"key1", "key2"};
+ var dict = GetDefaultHashMap1();
+ foreach (var key in dict.Keys)
+ {
+ Assert.IsTrue(keys.Contains(key));
+ }
+
+ keys.Add(null);
+ dict[null] = "nullvalue";
+ foreach (var key in dict.Keys)
+ {
+ Assert.IsTrue(keys.Contains(key));
+ }
+ }
+
+ [Test]
+ public void TestValueEnumeration()
+ {
+ var values = new List<string> { "value1", "value2" };
+ var dict = GetDefaultHashMap1();
+ foreach (var value in dict.Values)
+ {
+ Assert.IsTrue(values.Contains(value));
+ }
+
+ values.Add("nullvalue");
+ dict[null] = "nullvalue";
+ foreach (var value in dict.Values)
+ {
+ Assert.IsTrue(values.Contains(value));
+ }
+ }
+
+ [Test]
+ public void TestKeyValuePairEnumeration()
+ {
+ var dict = GetDefaultHashMap1();
+ Action<KeyValuePair<string, string>> act = kvp =>
+ {
+ Assert.IsNotNull(kvp);
+ if (kvp.Key == "key1")
+ {
+ Assert.AreEqual("value1", kvp.Value);
+ }
+ else if (kvp.Key == "key2")
+ {
+ Assert.AreEqual("value2", kvp.Value);
+ }
+ else if (kvp.Key == null)
+ {
+ Assert.AreEqual("nullval", kvp.Value);
+ }
+ };
+
+ foreach (var kvp in dict)
+ {
+ act.Invoke(kvp);
+ }
+
+ dict.Add(null, "nullval");
+ foreach (var kvp in dict)
+ {
+ act.Invoke(kvp);
+ }
+ }
+
+ [Test]
+ public void TestContainsNullKey()
+ {
+ var dict = GetDefaultHashMap1();
+ Assert.IsFalse(dict.ContainsKey(null));
+ Assert.IsNull(dict[null]);
+
+ dict.Add(null, "value");
+ Assert.IsTrue(dict.ContainsKey(null));
+ Assert.AreEqual("value", dict[null]);
+ }
+
+ [Test]
+ public void TestContainsKey()
+ {
+ var dict = GetDefaultHashMap1();
+ Assert.IsTrue(dict.ContainsKey("key1"));
+ Assert.IsTrue(dict.ContainsKey("key2"));
+ }
+
+ [Test]
+ public void TestAdd_NoNullKeys_NullValues()
+ {
+ var dict = GetNewHashMap<string, string>();
+ dict.Add("key1", null);
+ dict.Add("key2", "value2");
+
+ Assert.AreEqual(2, dict.Count);
+ }
+
+ [Test]
+ public void TestAdd_WithNullKeys_NoNullValues()
+ {
+ var dict = GetNewHashMap<string, string>();
+ dict.Add("key1", "value1");
+ dict.Add(null, "nullValue");
+
+ Assert.AreEqual(2, dict.Count);
+ }
+
+ [Test]
+ public void TestGetWithNonExistantKey_EmptyCollection()
+ {
+ var dict = GetNewHashMap<string, string>();
+ Assert.IsNull(dict["nothing"]);
+ Assert.IsNull(dict[null]);
+ }
+
+ [Test]
+ public void TestGetWithNonExistantKey()
+ {
+ var dict = GetDefaultHashMap1();
+ Assert.IsNull(dict["nothing"]);
+ Assert.IsNull(dict[null]);
+ }
+
+ [Test]
+ public void TestAddsUpdate_NotThrowException()
+ {
+ var dict = GetNewHashMap<string, string>();
+
+ dict.Add("key1", "value1");
+ Assert.AreEqual("value1", dict["key1"]);
+ Assert.AreEqual(1, dict.Count);
+
+ dict.Add("key1", "value2");
+ Assert.AreEqual("value2", dict["key1"], "Value was not updated by Add!");
+ Assert.AreEqual(1, dict.Count);
+ }
+
+ [Test]
+ public void TestIndexersUpdate_NotThrowException()
+ {
+ var dict = GetNewHashMap<string, string>();
+
+ dict["key1"] = "value1";
+ Assert.AreEqual("value1", dict["key1"]);
+ Assert.AreEqual(1, dict.Count);
+
+ dict["key1"] = "value2";
+ Assert.AreEqual("value2", dict["key1"], "Value was not updated by Add!");
+ Assert.AreEqual(1, dict.Count);
+ }
+
+ [Test]
+ public void TestWithValueType()
+ {
+ // Make sure default value types are stored in the internal dictionary
+ // and not the _nullValue variable
+ var dict = GetNewHashMap<int, string>();
+
+ dict[2] = "MyString";
+ dict[0] = "OtherString";
+
+ Assert.AreEqual("MyString", dict[2]);
+ Assert.AreEqual("OtherString", dict[0]);
+ Assert.AreEqual(2, dict.Count);
+ Assert.AreEqual(2, dict._dict.Count, "0 (default(int)) was not stored in internal dict!");
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestIDisposable.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestIDisposable.cs?rev=1203769&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestIDisposable.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestIDisposable.cs Fri Nov 18 17:54:13 2011
@@ -0,0 +1,59 @@
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+using NUnit.Framework;
+
+namespace Lucene.Net.Support
+{
+ [TestFixture]
+ public class TestIDisposable
+ {
+ [Test]
+ public void TestReadersWriters()
+ {
+ Directory dir;
+
+ using(dir = new RAMDirectory())
+ {
+ Document doc;
+ IndexWriter writer;
+ IndexReader reader;
+
+ using (writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED))
+ {
+ Field field = new Field("name", "value", Field.Store.YES,Field.Index.ANALYZED);
+ doc = new Document();
+ doc.Add(field);
+ writer.AddDocument(doc);
+ writer.Commit();
+
+ using (reader = writer.GetReader())
+ {
+ IndexReader r1 = reader.Reopen();
+ }
+
+ try
+ {
+ IndexReader r2 = reader.Reopen();
+ Assert.Fail("IndexReader shouldn't be open here");
+ }
+ catch (AlreadyClosedException)
+ {
+ }
+ }
+ try
+ {
+ writer.AddDocument(doc);
+ Assert.Fail("IndexWriter shouldn't be open here");
+ }
+ catch (AlreadyClosedException)
+ {
+ }
+
+ Assert.IsTrue(dir.isOpen_ForNUnit, "RAMDirectory");
+ }
+ Assert.IsFalse(dir.isOpen_ForNUnit, "RAMDirectory");
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestLRUCache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestLRUCache.cs?rev=1203769&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestLRUCache.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestLRUCache.cs Fri Nov 18 17:54:13 2011
@@ -0,0 +1,26 @@
+using NUnit.Framework;
+
+namespace Lucene.Net.Support
+{
+ [TestFixture]
+ public class TestLRUCache
+ {
+ [Test]
+ public void Test()
+ {
+ Lucene.Net.Util.Cache.SimpleLRUCache<string, string> cache = new Lucene.Net.Util.Cache.SimpleLRUCache<string, string>(3);
+ cache.Put("a", "a");
+ cache.Put("b", "b");
+ cache.Put("c", "c");
+ Assert.IsNotNull(cache.Get("a"));
+ Assert.IsNotNull(cache.Get("b"));
+ Assert.IsNotNull(cache.Get("c"));
+ cache.Put("d", "d");
+ Assert.IsNull(cache.Get("a"));
+ Assert.IsNotNull(cache.Get("c"));
+ cache.Put("e", "e");
+ cache.Put("f", "f");
+ Assert.IsNotNull(cache.Get("c"));
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestOSClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestOSClass.cs?rev=1203769&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestOSClass.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Support/TestOSClass.cs Fri Nov 18 17:54:13 2011
@@ -0,0 +1,27 @@
+using NUnit.Framework;
+
+namespace Lucene.Net.Support
+{
+ [TestFixture]
+ public class TestOSClass
+ {
+ // LUCENENET-216
+ [Test]
+ public void TestFSDirectorySync()
+ {
+ System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(System.IO.Path.Combine(AppSettings.Get("tempDir", ""), "testsync"));
+ Lucene.Net.Store.Directory directory = new Lucene.Net.Store.SimpleFSDirectory(path, null);
+ try
+ {
+ Lucene.Net.Store.IndexOutput io = directory.CreateOutput("syncfile");
+ io.Close();
+ directory.Sync("syncfile");
+ }
+ finally
+ {
+ directory.Close();
+ Lucene.Net.Util._TestUtil.RmDir(path);
+ }
+ }
+ }
+}
\ No newline at end of file