From 9c58a074d0157f32837c0228bff4c674836ddf8a Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Thu, 4 Feb 2021 20:45:38 +0700 Subject: [PATCH] Lucene.Net.Tests.Facet: Fixed formatting, member ordering, assert method calls, marked fields readonly on anonymous classes (#259) --- .../AssertingSubDocsAtOnceCollector.cs | 9 +- src/Lucene.Net.Tests.Facet/FacetTestCase.cs | 21 ++- .../Range/TestRangeFacetCounts.cs | 105 ++++++++--- .../SlowRAMDirectory.cs | 50 +++--- .../SortedSet/TestSortedSetDocValuesFacets.cs | 4 +- .../Taxonomy/Directory/TestAddTaxonomy.cs | 19 +- .../TestConcurrentFacetedIndexing.cs | 16 +- .../Directory/TestDirectoryTaxonomyReader.cs | 63 ++++--- .../Directory/TestDirectoryTaxonomyWriter.cs | 41 ++--- .../Taxonomy/TestCachedOrdinalsReader.cs | 10 +- .../Taxonomy/TestFacetLabel.cs | 113 ++++++------ .../Taxonomy/TestLRUHashMap.cs | 31 ++-- .../Taxonomy/TestSearcherTaxonomyManager.cs | 24 ++- .../Taxonomy/TestTaxonomyCombined.cs | 170 +++++++++++------- .../Taxonomy/TestTaxonomyFacetAssociations.cs | 4 - .../Taxonomy/TestTaxonomyFacetCounts.cs | 18 +- .../Taxonomy/TestTaxonomyFacetCounts2.cs | 38 ++-- .../TestTaxonomyFacetSumValueSource.cs | 7 +- .../WriterCache/TestCompactLabelToOrdinal.cs | 4 +- .../TestDrillDownQuery.cs | 10 +- .../TestDrillSideways.cs | 54 +++--- .../TestFacetsConfig.cs | 4 +- .../TestMultipleIndexFields.cs | 51 +++--- .../TestRandomSamplingFacetsCollector.cs | 46 +++-- 24 files changed, 476 insertions(+), 436 deletions(-) diff --git a/src/Lucene.Net.Tests.Facet/AssertingSubDocsAtOnceCollector.cs b/src/Lucene.Net.Tests.Facet/AssertingSubDocsAtOnceCollector.cs index a81f7e19ae..2ae8c03924 100644 --- a/src/Lucene.Net.Tests.Facet/AssertingSubDocsAtOnceCollector.cs +++ b/src/Lucene.Net.Tests.Facet/AssertingSubDocsAtOnceCollector.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,19 +20,17 @@ namespace Lucene.Net.Facet * limitations under the License. */ - using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; using ICollector = Lucene.Net.Search.ICollector; using ChildScorer = Lucene.Net.Search.Scorer.ChildScorer; using Scorer = Lucene.Net.Search.Scorer; - using System; + /// /// Verifies in collect() that all child subScorers are on /// the collected doc. /// internal class AssertingSubDocsAtOnceCollector : ICollector { - // TODO: allow wrapping another Collector internal IList allScorers; @@ -70,5 +68,4 @@ public virtual void SetNextReader(AtomicReaderContext context) public virtual bool AcceptsDocsOutOfOrder => false; } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/FacetTestCase.cs b/src/Lucene.Net.Tests.Facet/FacetTestCase.cs index b0d4a31be5..2c2cccda1e 100644 --- a/src/Lucene.Net.Tests.Facet/FacetTestCase.cs +++ b/src/Lucene.Net.Tests.Facet/FacetTestCase.cs @@ -8,7 +8,6 @@ namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -45,6 +44,7 @@ public virtual Facets GetTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsCo { return GetTaxonomyFacetCounts(taxoReader, config, c, FacetsConfig.DEFAULT_INDEX_FIELD_NAME); } + public virtual Facets GetTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector c, string indexFieldName) { Facets facets; @@ -153,9 +153,9 @@ protected internal virtual void SortTies(LabelAndValue[] labelValues) { if (numInRow > 1) { - Array.Sort(labelValues, i - numInRow, i - (i - numInRow), Comparer.Create((a,b)=> { + Array.Sort(labelValues, i - numInRow, i - (i - numInRow), Comparer.Create((a,b) => { if (Debugging.AssertsEnabled) Debugging.Assert((double)a.Value == (double)b.Value); - return (new BytesRef(a.Label)).CompareTo(new BytesRef(b.Label)); + return new BytesRef(a.Label).CompareTo(new BytesRef(b.Label)); })); } numInRow = 1; @@ -170,7 +170,7 @@ protected internal virtual void SortTies(LabelAndValue[] labelValues) protected internal virtual void SortLabelValues(List labelValues) { - labelValues.Sort(Comparer.Create((a,b)=> { + labelValues.Sort(Comparer.Create((a,b) => { if ((double)a.Value > (double)b.Value) { return -1; @@ -181,7 +181,7 @@ protected internal virtual void SortLabelValues(List labelValues) } else { - return (new BytesRef(a.Label)).CompareTo(new BytesRef(b.Label)); + return new BytesRef(a.Label).CompareTo(new BytesRef(b.Label)); } })); } @@ -206,14 +206,14 @@ protected internal virtual void SortFacetResults(List results) })); } - protected internal virtual void AssertFloatValuesEquals(IList a, IList b) + protected virtual void AssertFloatValuesEquals(IList a, IList b) { Assert.AreEqual(a.Count, b.Count); float lastValue = float.PositiveInfinity; IDictionary aByDim = new Dictionary(); for (int i = 0; i < a.Count; i++) { - Assert.True((float)a[i].Value <= lastValue); + Assert.IsTrue((float)a[i].Value <= lastValue); lastValue = (float)a[i].Value; aByDim[a[i].Dim] = a[i]; } @@ -222,7 +222,7 @@ protected internal virtual void AssertFloatValuesEquals(IList a, IL for (int i = 0; i < b.Count; i++) { bByDim[b[i].Dim] = b[i]; - Assert.True((float)b[i].Value <= lastValue); + Assert.IsTrue((float)b[i].Value <= lastValue); lastValue = (float)b[i].Value; } foreach (string dim in aByDim.Keys) @@ -231,10 +231,10 @@ protected internal virtual void AssertFloatValuesEquals(IList a, IL } } - protected internal virtual void AssertFloatValuesEquals(FacetResult a, FacetResult b) + protected virtual void AssertFloatValuesEquals(FacetResult a, FacetResult b) { Assert.AreEqual(a.Dim, b.Dim); - Assert.True(Arrays.Equals(a.Path, b.Path)); + Assert.IsTrue(Arrays.Equals(a.Path, b.Path)); Assert.AreEqual(a.ChildCount, b.ChildCount); Assert.AreEqual((float)a.Value, (float)b.Value, (float)a.Value / 1e5); Assert.AreEqual(a.LabelValues.Length, b.LabelValues.Length); @@ -245,5 +245,4 @@ protected internal virtual void AssertFloatValuesEquals(FacetResult a, FacetResu } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs b/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs index 537dada313..627e156d78 100644 --- a/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs +++ b/src/Lucene.Net.Tests.Facet/Range/TestRangeFacetCounts.cs @@ -96,7 +96,12 @@ public virtual void TestBasicLong() IndexSearcher s = NewSearcher(r); s.Search(new MatchAllDocsQuery(), fc); - Facets facets = new Int64RangeFacetCounts("field", fc, new Int64Range("less than 10", 0L, true, 10L, false), new Int64Range("less than or equal to 10", 0L, true, 10L, true), new Int64Range("over 90", 90L, false, 100L, false), new Int64Range("90 or above", 90L, true, 100L, false), new Int64Range("over 1000", 1000L, false, long.MaxValue, true)); + Facets facets = new Int64RangeFacetCounts("field", fc, + new Int64Range("less than 10", 0L, true, 10L, false), + new Int64Range("less than or equal to 10", 0L, true, 10L, true), + new Int64Range("over 90", 90L, false, 100L, false), + new Int64Range("90 or above", 90L, true, 100L, false), + new Int64Range("over 1000", 1000L, false, long.MaxValue, true)); FacetResult result = facets.GetTopChildren(10, "field"); @@ -111,7 +116,7 @@ public virtual void TestUselessRange() { try { - new Int64Range("useless", 7, true, 6, true); + _ = new Int64Range("useless", 7, true, 6, true); fail("did not hit expected exception"); } catch (ArgumentException) @@ -120,7 +125,7 @@ public virtual void TestUselessRange() } try { - new Int64Range("useless", 7, true, 7, false); + _ = new Int64Range("useless", 7, true, 7, false); fail("did not hit expected exception"); } catch (ArgumentException) @@ -129,7 +134,7 @@ public virtual void TestUselessRange() } try { - new DoubleRange("useless", 7.0, true, 6.0, true); + _ = new DoubleRange("useless", 7.0, true, 6.0, true); fail("did not hit expected exception"); } catch (ArgumentException) @@ -138,7 +143,7 @@ public virtual void TestUselessRange() } try { - new DoubleRange("useless", 7.0, true, 7.0, false); + _ = new DoubleRange("useless", 7.0, true, 7.0, false); fail("did not hit expected exception"); } catch (ArgumentException) @@ -174,7 +179,13 @@ public virtual void TestLongMinMax() IndexSearcher s = NewSearcher(r); s.Search(new MatchAllDocsQuery(), fc); - Facets facets = new Int64RangeFacetCounts("field", fc, new Int64Range("min", long.MinValue, true, long.MinValue, true), new Int64Range("max", long.MaxValue, true, long.MaxValue, true), new Int64Range("all0", long.MinValue, true, long.MaxValue, true), new Int64Range("all1", long.MinValue, false, long.MaxValue, true), new Int64Range("all2", long.MinValue, true, long.MaxValue, false), new Int64Range("all3", long.MinValue, false, long.MaxValue, false)); + Facets facets = new Int64RangeFacetCounts("field", fc, + new Int64Range("min", long.MinValue, true, long.MinValue, true), + new Int64Range("max", long.MaxValue, true, long.MaxValue, true), + new Int64Range("all0", long.MinValue, true, long.MaxValue, true), + new Int64Range("all1", long.MinValue, false, long.MaxValue, true), + new Int64Range("all2", long.MinValue, true, long.MaxValue, false), + new Int64Range("all3", long.MinValue, false, long.MaxValue, false)); FacetResult result = facets.GetTopChildren(10, "field"); Assert.AreEqual("dim=field path=[] value=3 childCount=6\n min (1)\n max (1)\n all0 (3)\n all1 (2)\n all2 (2)\n all3 (1)\n", result.ToString()); @@ -210,7 +221,11 @@ public virtual void TestOverlappedEndStart() IndexSearcher s = NewSearcher(r); s.Search(new MatchAllDocsQuery(), fc); - Facets facets = new Int64RangeFacetCounts("field", fc, new Int64Range("0-10", 0L, true, 10L, true), new Int64Range("10-20", 10L, true, 20L, true), new Int64Range("20-30", 20L, true, 30L, true), new Int64Range("30-40", 30L, true, 40L, true)); + Facets facets = new Int64RangeFacetCounts("field", fc, + new Int64Range("0-10", 0L, true, 10L, true), + new Int64Range("10-20", 10L, true, 20L, true), + new Int64Range("20-30", 20L, true, 30L, true), + new Int64Range("30-40", 30L, true, 40L, true)); FacetResult result = facets.GetTopChildren(10, "field"); Assert.AreEqual("dim=field path=[] value=41 childCount=4\n 0-10 (11)\n 10-20 (11)\n 20-30 (11)\n 30-40 (11)\n", result.ToString()); @@ -221,7 +236,7 @@ public virtual void TestOverlappedEndStart() /// /// Tests single request that mixes Range and non-Range - /// faceting, with DrillSideways and taxonomy. + /// faceting, with and taxonomy. /// [Test] public virtual void TestMixedRangeAndNonRangeTaxonomy() @@ -275,7 +290,8 @@ public virtual void TestMixedRangeAndNonRangeTaxonomy() Assert.AreEqual(100, dsr.Hits.TotalHits); Assert.AreEqual("dim=dim path=[] value=100 childCount=2\n b (75)\n a (25)\n", dsr.Facets.GetTopChildren(10, "dim").ToString()); - Assert.AreEqual("dim=field path=[] value=21 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", dsr.Facets.GetTopChildren(10, "field").ToString()); + Assert.AreEqual("dim=field path=[] value=21 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", + dsr.Facets.GetTopChildren(10, "field").ToString()); // Second search, drill down on dim=b: ddq = new DrillDownQuery(config); @@ -284,7 +300,8 @@ public virtual void TestMixedRangeAndNonRangeTaxonomy() Assert.AreEqual(75, dsr.Hits.TotalHits); Assert.AreEqual("dim=dim path=[] value=100 childCount=2\n b (75)\n a (25)\n", dsr.Facets.GetTopChildren(10, "dim").ToString()); - Assert.AreEqual("dim=field path=[] value=16 childCount=5\n less than 10 (7)\n less than or equal to 10 (8)\n over 90 (7)\n 90 or above (8)\n over 1000 (0)\n", dsr.Facets.GetTopChildren(10, "field").ToString()); + Assert.AreEqual("dim=field path=[] value=16 childCount=5\n less than 10 (7)\n less than or equal to 10 (8)\n over 90 (7)\n 90 or above (8)\n over 1000 (0)\n", + dsr.Facets.GetTopChildren(10, "field").ToString()); // Third search, drill down on "less than or equal to 10": ddq = new DrillDownQuery(config); @@ -293,7 +310,8 @@ public virtual void TestMixedRangeAndNonRangeTaxonomy() Assert.AreEqual(11, dsr.Hits.TotalHits); Assert.AreEqual("dim=dim path=[] value=11 childCount=2\n b (8)\n a (3)\n", dsr.Facets.GetTopChildren(10, "dim").ToString()); - Assert.AreEqual("dim=field path=[] value=21 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", dsr.Facets.GetTopChildren(10, "field").ToString()); + Assert.AreEqual("dim=field path=[] value=21 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", + dsr.Facets.GetTopChildren(10, "field").ToString()); IOUtils.Dispose(tw, tr, td, w, r, d); } @@ -328,7 +346,12 @@ protected override Facets BuildFacetsResult(FacetsCollector drillDowns, FacetsCo } IDictionary byDim = new Dictionary(); - byDim["field"] = new Int64RangeFacetCounts("field", fieldFC, new Int64Range("less than 10", 0L, true, 10L, false), new Int64Range("less than or equal to 10", 0L, true, 10L, true), new Int64Range("over 90", 90L, false, 100L, false), new Int64Range("90 or above", 90L, true, 100L, false), new Int64Range("over 1000", 1000L, false, long.MaxValue, false)); + byDim["field"] = new Int64RangeFacetCounts("field", fieldFC, + new Int64Range("less than 10", 0L, true, 10L, false), + new Int64Range("less than or equal to 10", 0L, true, 10L, true), + new Int64Range("over 90", 90L, false, 100L, false), + new Int64Range("90 or above", 90L, true, 100L, false), + new Int64Range("over 1000", 1000L, false, long.MaxValue, false)); byDim["dim"] = outerInstance.GetTaxonomyFacetCounts(m_taxoReader, m_config, dimFC); return new MultiFacets(byDim, null); } @@ -360,9 +383,15 @@ public virtual void TestBasicDouble() IndexSearcher s = NewSearcher(r); s.Search(new MatchAllDocsQuery(), fc); - Facets facets = new DoubleRangeFacetCounts("field", fc, new DoubleRange("less than 10", 0.0, true, 10.0, false), new DoubleRange("less than or equal to 10", 0.0, true, 10.0, true), new DoubleRange("over 90", 90.0, false, 100.0, false), new DoubleRange("90 or above", 90.0, true, 100.0, false), new DoubleRange("over 1000", 1000.0, false, double.PositiveInfinity, false)); + Facets facets = new DoubleRangeFacetCounts("field", fc, + new DoubleRange("less than 10", 0.0, true, 10.0, false), + new DoubleRange("less than or equal to 10", 0.0, true, 10.0, true), + new DoubleRange("over 90", 90.0, false, 100.0, false), + new DoubleRange("90 or above", 90.0, true, 100.0, false), + new DoubleRange("over 1000", 1000.0, false, double.PositiveInfinity, false)); - Assert.AreEqual("dim=field path=[] value=21 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", facets.GetTopChildren(10, "field").ToString()); + Assert.AreEqual("dim=field path=[] value=21 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", + facets.GetTopChildren(10, "field").ToString()); IOUtils.Dispose(w, r, d); } @@ -392,9 +421,15 @@ public virtual void TestBasicFloat() IndexSearcher s = NewSearcher(r); s.Search(new MatchAllDocsQuery(), fc); - Facets facets = new DoubleRangeFacetCounts("field", new SingleFieldSource("field"), fc, new DoubleRange("less than 10", 0.0f, true, 10.0f, false), new DoubleRange("less than or equal to 10", 0.0f, true, 10.0f, true), new DoubleRange("over 90", 90.0f, false, 100.0f, false), new DoubleRange("90 or above", 90.0f, true, 100.0f, false), new DoubleRange("over 1000", 1000.0f, false, double.PositiveInfinity, false)); + Facets facets = new DoubleRangeFacetCounts("field", new SingleFieldSource("field"), fc, + new DoubleRange("less than 10", 0.0f, true, 10.0f, false), + new DoubleRange("less than or equal to 10", 0.0f, true, 10.0f, true), + new DoubleRange("over 90", 90.0f, false, 100.0f, false), + new DoubleRange("90 or above", 90.0f, true, 100.0f, false), + new DoubleRange("over 1000", 1000.0f, false, double.PositiveInfinity, false)); - Assert.AreEqual("dim=field path=[] value=21 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", facets.GetTopChildren(10, "field").ToString()); + Assert.AreEqual("dim=field path=[] value=21 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", + facets.GetTopChildren(10, "field").ToString()); IOUtils.Dispose(w, r, d); } @@ -1028,9 +1063,15 @@ public virtual void TestMissingValues() IndexSearcher s = NewSearcher(r); s.Search(new MatchAllDocsQuery(), fc); - Facets facets = new Int64RangeFacetCounts("field", fc, new Int64Range("less than 10", 0L, true, 10L, false), new Int64Range("less than or equal to 10", 0L, true, 10L, true), new Int64Range("over 90", 90L, false, 100L, false), new Int64Range("90 or above", 90L, true, 100L, false), new Int64Range("over 1000", 1000L, false, long.MaxValue, false)); + Facets facets = new Int64RangeFacetCounts("field", fc, + new Int64Range("less than 10", 0L, true, 10L, false), + new Int64Range("less than or equal to 10", 0L, true, 10L, true), + new Int64Range("over 90", 90L, false, 100L, false), + new Int64Range("90 or above", 90L, true, 100L, false), + new Int64Range("over 1000", 1000L, false, long.MaxValue, false)); - Assert.AreEqual("dim=field path=[] value=16 childCount=5\n less than 10 (8)\n less than or equal to 10 (8)\n over 90 (8)\n 90 or above (8)\n over 1000 (0)\n", facets.GetTopChildren(10, "field").ToString()); + Assert.AreEqual("dim=field path=[] value=16 childCount=5\n less than 10 (8)\n less than or equal to 10 (8)\n over 90 (8)\n 90 or above (8)\n over 1000 (0)\n", + facets.GetTopChildren(10, "field").ToString()); IOUtils.Dispose(w, r, d); } @@ -1063,7 +1104,14 @@ public virtual void TestCustomDoublesValueSource() IndexSearcher s = NewSearcher(r); s.Search(new MatchAllDocsQuery(), fc); - DoubleRange[] ranges = new DoubleRange[] { new DoubleRange("< 1", 0.0, true, 1.0, false), new DoubleRange("< 2", 0.0, true, 2.0, false), new DoubleRange("< 5", 0.0, true, 5.0, false), new DoubleRange("< 10", 0.0, true, 10.0, false), new DoubleRange("< 20", 0.0, true, 20.0, false), new DoubleRange("< 50", 0.0, true, 50.0, false) }; + DoubleRange[] ranges = new DoubleRange[] { + new DoubleRange("< 1", 0.0, true, 1.0, false), + new DoubleRange("< 2", 0.0, true, 2.0, false), + new DoubleRange("< 5", 0.0, true, 5.0, false), + new DoubleRange("< 10", 0.0, true, 10.0, false), + new DoubleRange("< 20", 0.0, true, 20.0, false), + new DoubleRange("< 50", 0.0, true, 50.0, false) + }; Filter fastMatchFilter; AtomicBoolean filterWasUsed = new AtomicBoolean(); @@ -1084,8 +1132,9 @@ public virtual void TestCustomDoublesValueSource() Facets facets = new DoubleRangeFacetCounts("field", vs, fc, fastMatchFilter, ranges); - Assert.AreEqual("dim=field path=[] value=3 childCount=6\n < 1 (0)\n < 2 (1)\n < 5 (3)\n < 10 (3)\n < 20 (3)\n < 50 (3)\n", facets.GetTopChildren(10, "field").ToString()); - Assert.True(fastMatchFilter == null || filterWasUsed); + Assert.AreEqual("dim=field path=[] value=3 childCount=6\n < 1 (0)\n < 2 (1)\n < 5 (3)\n < 10 (3)\n < 20 (3)\n < 50 (3)\n", + facets.GetTopChildren(10, "field").ToString()); + Assert.IsTrue(fastMatchFilter == null || filterWasUsed); DrillDownQuery ddq = new DrillDownQuery(config); ddq.Add("field", ranges[1].GetFilter(fastMatchFilter, vs)); @@ -1099,7 +1148,8 @@ public virtual void TestCustomDoublesValueSource() DrillSidewaysResult dsr = ds.Search(ddq, 10); Assert.AreEqual(1, dsr.Hits.TotalHits); - Assert.AreEqual("dim=field path=[] value=3 childCount=6\n < 1 (0)\n < 2 (1)\n < 5 (3)\n < 10 (3)\n < 20 (3)\n < 50 (3)\n", dsr.Facets.GetTopChildren(10, "field").ToString()); + Assert.AreEqual("dim=field path=[] value=3 childCount=6\n < 1 (0)\n < 2 (1)\n < 5 (3)\n < 10 (3)\n < 20 (3)\n < 50 (3)\n", + dsr.Facets.GetTopChildren(10, "field").ToString()); IOUtils.Dispose(r, writer, dir); } @@ -1108,7 +1158,7 @@ private class ValueSourceAnonymousInnerClassHelper : ValueSource { private readonly TestRangeFacetCounts outerInstance; - private Document doc; + private readonly Document doc; public ValueSourceAnonymousInnerClassHelper(TestRangeFacetCounts outerInstance, Document doc) { @@ -1158,7 +1208,7 @@ private class CachingWrapperFilterAnonymousInnerClassHelper : CachingWrapperFilt { private readonly TestRangeFacetCounts outerInstance; - private AtomicBoolean filterWasUsed; + private readonly AtomicBoolean filterWasUsed; public CachingWrapperFilterAnonymousInnerClassHelper(TestRangeFacetCounts outerInstance, QueryWrapperFilter org, AtomicBoolean filterWasUsed) : base(org) @@ -1180,9 +1230,9 @@ private class DrillSidewaysAnonymousInnerClassHelper2 : DrillSideways { private readonly TestRangeFacetCounts outerInstance; - private ValueSource vs; - private Lucene.Net.Facet.Range.DoubleRange[] ranges; - private Filter fastMatchFilter; + private readonly ValueSource vs; + private readonly DoubleRange[] ranges; + private readonly Filter fastMatchFilter; public DrillSidewaysAnonymousInnerClassHelper2(TestRangeFacetCounts outerInstance, IndexSearcher indexSearcher, FacetsConfig facetsConfig, TaxonomyReader org, ValueSource valueSource, DoubleRange[] doubleRanges, Filter filter) @@ -1204,5 +1254,4 @@ protected override Facets BuildFacetsResult(FacetsCollector drillDowns, FacetsCo protected override bool ScoreSubDocsAtOnce => Random.NextBoolean(); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs b/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs index b9631eec6e..7efe8b9b1d 100644 --- a/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs +++ b/src/Lucene.Net.Tests.Facet/SlowRAMDirectory.cs @@ -1,10 +1,8 @@ using System; using System.Threading; -using Lucene.Net.Randomized.Generators; namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,9 +21,9 @@ namespace Lucene.Net.Facet */ - using IOContext = Lucene.Net.Store.IOContext; using IndexInput = Lucene.Net.Store.IndexInput; using IndexOutput = Lucene.Net.Store.IndexOutput; + using IOContext = Lucene.Net.Store.IOContext; using RAMDirectory = Lucene.Net.Store.RAMDirectory; /// @@ -34,15 +32,14 @@ namespace Lucene.Net.Facet // TODO: move to test-framework and sometimes use in tests? public class SlowRAMDirectory : RAMDirectory { - private const int IO_SLEEP_THRESHOLD = 50; internal Random random; private int sleepMillis; - public virtual int SleepMillis + public virtual void SetSleepMillis(int sleepMillis) { - set => this.sleepMillis = value; + this.sleepMillis = sleepMillis; } public SlowRAMDirectory(int sleepMillis, Random random) @@ -110,9 +107,9 @@ private class SlowIndexInput : IndexInput { private readonly SlowRAMDirectory outerInstance; - internal IndexInput ii; - internal int numRead = 0; - internal Random rand; + private readonly IndexInput ii; + private int numRead = 0; + private readonly Random rand; public SlowIndexInput(SlowRAMDirectory outerInstance, IndexInput ii) : base("SlowIndexInput(" + ii + ")") @@ -159,26 +156,28 @@ protected override void Dispose(bool disposing) ii.Dispose(); } } + public override bool Equals(object o) { return ii.Equals(o); } + public override long GetFilePointer() { return ii.GetFilePointer(); } - public override void Seek(long pos) + public override int GetHashCode() { - ii.Seek(pos); + return ii.GetHashCode(); } + public override long Length => ii.Length; - public override int GetHashCode() + public override void Seek(long pos) { - return ii.GetHashCode(); + ii.Seek(pos); } - public override long Length => ii.Length; } /// @@ -189,10 +188,9 @@ private class SlowIndexOutput : IndexOutput { private readonly SlowRAMDirectory outerInstance; - - internal IndexOutput io; - internal int numWrote; - internal readonly Random rand; + private readonly IndexOutput io; + private int numWrote; + private readonly Random rand; public SlowIndexOutput(SlowRAMDirectory outerInstance, IndexOutput io) { @@ -223,6 +221,12 @@ public override void WriteBytes(byte[] b, int offset, int length) io.WriteBytes(b, offset, length); } + [Obsolete] + public override void Seek(long pos) + { + io.Seek(pos); + } + protected override void Dispose(bool disposing) { if (disposing) @@ -230,24 +234,24 @@ protected override void Dispose(bool disposing) io.Dispose(); } } + public override void Flush() { io.Flush(); } + public override long GetFilePointer() { return io.GetFilePointer(); } - [Obsolete] - public override void Seek(long pos) + public override long Length { - io.Seek(pos); + get => io.Length; + set => throw new InvalidOperationException("Length is readonly"); } public override long Checksum => io.Checksum; } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs b/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs index b235b471f9..1d4f5b3321 100644 --- a/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs +++ b/src/Lucene.Net.Tests.Facet/SortedSet/TestSortedSetDocValuesFacets.cs @@ -48,7 +48,6 @@ public class TestSortedSetDocValuesFacets : FacetTestCase [Test] public virtual void TestBasic() { - AssumeTrue("Test requires SortedSetDV support", DefaultCodecSupportsSortedSet); Directory dir = NewDirectory(); @@ -138,7 +137,7 @@ public virtual void TestStaleState() try { - new SortedSetDocValuesFacetCounts(state, c); + _ = new SortedSetDocValuesFacetCounts(state, c); fail("did not hit expected exception"); } catch (InvalidOperationException) @@ -410,5 +409,4 @@ public virtual void TestRandom() IOUtils.Dispose(w, searcher.IndexReader, indexDir, taxoDir); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs index 18c7b05c77..793d2ed1b5 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs @@ -127,7 +127,7 @@ private void validate(Directory dest, Directory src, IOrdinalMap ordMap) // validate taxo sizes int srcSize = srcTR.Count; - Assert.True(destSize >= srcSize, "destination taxonomy expected to be larger than source; dest=" + destSize + " src=" + srcSize); + Assert.IsTrue(destSize >= srcSize, "destination taxonomy expected to be larger than source; dest=" + destSize + " src=" + srcSize); // validate that all source categories exist in destination, and their // ordinals are as expected. @@ -135,7 +135,7 @@ private void validate(Directory dest, Directory src, IOrdinalMap ordMap) { FacetLabel cp = srcTR.GetPath(j); int destOrdinal = destTr.GetOrdinal(cp); - Assert.True(destOrdinal > 0, cp + " not found in destination"); + Assert.IsTrue(destOrdinal > 0, cp + " not found in destination"); Assert.AreEqual(destOrdinal, map[j]); } } @@ -150,7 +150,7 @@ public virtual void TestAddEmpty() destTW.Commit(); Directory src = NewDirectory(); - (new DirectoryTaxonomyWriter(src)).Dispose(); // create an empty taxonomy + new DirectoryTaxonomyWriter(src).Dispose(); // create an empty taxonomy IOrdinalMap map = randomOrdinalMap(); destTW.AddTaxonomy(src, map); @@ -200,7 +200,8 @@ public virtual void TestMedium() int numTests = AtLeast(3); for (int i = 0; i < numTests; i++) { - Dotest(TestUtil.NextInt32(random, 2, 100), TestUtil.NextInt32(random, 100, 1000)); + Dotest(TestUtil.NextInt32(random, 2, 100), + TestUtil.NextInt32(random, 100, 1000)); } } @@ -265,7 +266,7 @@ public virtual void TestConcurrency() for (int i = 1; i < dtr.Count; i++) { FacetLabel cat = dtr.GetPath(i); - Assert.True(categories.Add(cat), "category " + cat + " already existed"); + Assert.IsTrue(categories.Add(cat), "category " + cat + " already existed"); } dtr.Dispose(); @@ -276,10 +277,10 @@ private class ThreadAnonymousInnerClassHelper2 : ThreadJob { private readonly TestAddTaxonomy outerInstance; - private int numCategories; - private Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter destTW; + private readonly int numCategories; + private readonly DirectoryTaxonomyWriter destTW; - public ThreadAnonymousInnerClassHelper2(TestAddTaxonomy outerInstance, int numCategories, Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter destTW) + public ThreadAnonymousInnerClassHelper2(TestAddTaxonomy outerInstance, int numCategories, DirectoryTaxonomyWriter destTW) { this.outerInstance = outerInstance; this.numCategories = numCategories; @@ -302,7 +303,5 @@ public override void Run() } } } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs index e19446814e..162ca8962b 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestConcurrentFacetedIndexing.cs @@ -148,7 +148,7 @@ public virtual void TestConcurrency() foreach (string cat in values.Keys) { FacetLabel cp = new FacetLabel(FacetsConfig.StringToPath(cat)); - Assert.True(tr.GetOrdinal(cp) > 0, "category not found " + cp); + Assert.IsTrue(tr.GetOrdinal(cp) > 0, "category not found " + cp); int level = cp.Length; int parentOrd = 0; // for root, parent is always virtual ROOT (ord=0) FacetLabel path = null; @@ -168,13 +168,13 @@ private class ThreadAnonymousInnerClassHelper : ThreadJob { private readonly TestConcurrentFacetedIndexing outerInstance; - private AtomicInt32 numDocs; - private ConcurrentDictionary values; - private IndexWriter iw; - private Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter tw; - private FacetsConfig config; + private readonly AtomicInt32 numDocs; + private readonly ConcurrentDictionary values; + private readonly IndexWriter iw; + private readonly DirectoryTaxonomyWriter tw; + private readonly FacetsConfig config; - public ThreadAnonymousInnerClassHelper(TestConcurrentFacetedIndexing outerInstance, AtomicInt32 numDocs, ConcurrentDictionary values, IndexWriter iw, Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter tw, FacetsConfig config) + public ThreadAnonymousInnerClassHelper(TestConcurrentFacetedIndexing outerInstance, AtomicInt32 numDocs, ConcurrentDictionary values, IndexWriter iw, DirectoryTaxonomyWriter tw, FacetsConfig config) { this.outerInstance = outerInstance; this.numDocs = numDocs; @@ -218,7 +218,5 @@ public override void Run() } } } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs index 61df17424d..3db3e42559 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs @@ -50,7 +50,7 @@ public virtual void TestCloseAfterIncRef() ltr.Dispose(); // should not fail as we IncRef() before close - var tmpSie = ltr.Count; + var _ = ltr.Count; ltr.DecRef(); dir.Dispose(); @@ -65,8 +65,8 @@ public virtual void TestCloseTwice() ltw.Dispose(); var ltr = new DirectoryTaxonomyReader(dir); - (ltr).Dispose(); - (ltr).Dispose(); // no exception should be thrown + ltr.Dispose(); + ltr.Dispose(); // no exception should be thrown dir.Dispose(); } @@ -87,15 +87,15 @@ public virtual void TestOpenIfChangedResult() ltw.Commit(); ltr = new DirectoryTaxonomyReader(dir); - Assert.Null(TaxonomyReader.OpenIfChanged(ltr), "Nothing has changed"); + Assert.IsNull(TaxonomyReader.OpenIfChanged(ltr), "Nothing has changed"); ltw.AddCategory(new FacetLabel("b")); ltw.Commit(); DirectoryTaxonomyReader newtr = TaxonomyReader.OpenIfChanged(ltr); - Assert.NotNull(newtr, "changes were committed"); - Assert.Null(TaxonomyReader.OpenIfChanged(newtr), "Nothing has changed"); - (newtr).Dispose(); + Assert.IsNotNull(newtr, "changes were committed"); + Assert.IsNull(TaxonomyReader.OpenIfChanged(newtr), "Nothing has changed"); + newtr.Dispose(); } finally { @@ -115,7 +115,7 @@ public virtual void TestAlreadyClosed() ltr.Dispose(); try { - var tmpSize = ltr.Count; + var _ = ltr.Count; fail("An ObjectDisposedException should have been thrown here"); } catch (ObjectDisposedException) @@ -139,7 +139,7 @@ public virtual void TestOpenIfChangedReadRecreatedTaxonomy() { doTestReadRecreatedTaxonomy(Random, false); } - + private void doTestReadRecreatedTaxonomy(Random random, bool closeReader) { Directory dir = null; @@ -182,7 +182,7 @@ private void doTestReadRecreatedTaxonomy(Random random, bool closeReader) else { var newtr = TaxonomyReader.OpenIfChanged(tr); - Assert.NotNull(newtr); + Assert.IsNotNull(newtr); tr.Dispose(); tr = newtr; } @@ -191,7 +191,7 @@ private void doTestReadRecreatedTaxonomy(Random random, bool closeReader) } finally { - IOUtils.Dispose(tr as DirectoryTaxonomyReader, tw, dir); + IOUtils.Dispose(tr, tw, dir); } } @@ -213,7 +213,7 @@ public virtual void TestOpenIfChangedAndRefCount() taxoWriter.AddCategory(new FacetLabel("a", "b")); taxoWriter.Commit(); var newtr = TaxonomyReader.OpenIfChanged(taxoReader); - Assert.NotNull(newtr); + Assert.IsNotNull(newtr); taxoReader.Dispose(); taxoReader = newtr; Assert.AreEqual(1, taxoReader.RefCount, "wrong refCount"); @@ -243,7 +243,7 @@ public virtual void TestOpenIfChangedManySegments() } numCategories += numCats + 1; // one for round-parent var newtr = TaxonomyReader.OpenIfChanged(reader); - Assert.NotNull(newtr); + Assert.IsNotNull(newtr); reader.Dispose(); reader = newtr; @@ -293,7 +293,8 @@ public virtual void TestOpenIfChangedMergedSegment() // hold onto IW to forceMerge // note how we don't close it, since DTW will close it. - IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(new LogByteSizeMergePolicy())); + IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)) + .SetMergePolicy(new LogByteSizeMergePolicy())); // LUCENENET: We need to set the index writer before the constructor of the base class is called // because the DirectoryTaxonomyWriter class constructor is the consumer of the OpenIndexWriter method. @@ -312,7 +313,7 @@ public virtual void TestOpenIfChangedMergedSegment() // now calling openIfChanged should trip on the bug var newtr = TaxonomyReader.OpenIfChanged(reader); - Assert.NotNull(newtr); + Assert.IsNotNull(newtr); reader.Dispose(); reader = newtr; Assert.AreEqual(2, reader.Count); @@ -327,13 +328,13 @@ private class DirectoryTaxonomyWriterAnonymousInnerClassHelper2 : DirectoryTaxon { internal static IndexWriter iw = null; - public DirectoryTaxonomyWriterAnonymousInnerClassHelper2(Directory dir) + public DirectoryTaxonomyWriterAnonymousInnerClassHelper2(Directory dir) : base(dir) { } - protected override IndexWriter OpenIndexWriter(Directory directory, IndexWriterConfig config) - { + protected override IndexWriter OpenIndexWriter(Directory directory, IndexWriterConfig config) + { return iw; } } @@ -371,7 +372,7 @@ public virtual void TestOpenIfChangedNoChangesButSegmentMerges() // now calling openIfChanged should trip on the wrong assert in ParetArray's ctor var newtr = TaxonomyReader.OpenIfChanged(reader); - Assert.NotNull(newtr); + Assert.IsNotNull(newtr); reader.Dispose(); reader = newtr; Assert.AreEqual(2, reader.Count); @@ -419,7 +420,7 @@ public virtual void TestOpenIfChangedReuseAfterRecreate() writer.Dispose(); DirectoryTaxonomyReader r2 = TaxonomyReader.OpenIfChanged(r1); - Assert.NotNull(r2); + Assert.IsNotNull(r2); // fill r2's caches Assert.AreEqual(1, r2.GetOrdinal(cp_b)); @@ -433,8 +434,8 @@ public virtual void TestOpenIfChangedReuseAfterRecreate() Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, r2.GetOrdinal(cp_a)); Assert.AreEqual(cp_b, r2.GetPath(1)); - (r2).Dispose(); - (r1).Dispose(); + r2.Dispose(); + r1.Dispose(); dir.Dispose(); } @@ -467,7 +468,7 @@ public virtual void TestOpenIfChangedReuse() } DirectoryTaxonomyReader r2 = TaxonomyReader.OpenIfChanged(r1); - Assert.NotNull(r2); + Assert.IsNotNull(r2); // add r2's categories to the caches Assert.AreEqual(2, r2.GetOrdinal(cp_b)); @@ -475,10 +476,10 @@ public virtual void TestOpenIfChangedReuse() // check that r1 doesn't see cp_b Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, r1.GetOrdinal(cp_b)); - Assert.Null(r1.GetPath(2)); + Assert.IsNull(r1.GetPath(2)); - (r1).Dispose(); - (r2).Dispose(); + r1.Dispose(); + r2.Dispose(); writer.Dispose(); dir.Dispose(); } @@ -520,7 +521,7 @@ public virtual void TestOpenIfChangedReplaceTaxonomy() } DirectoryTaxonomyReader r2 = TaxonomyReader.OpenIfChanged(r1); - Assert.NotNull(r2); + Assert.IsNotNull(r2); // fill r2's caches Assert.AreEqual(1, r2.GetOrdinal(cp_b)); @@ -534,8 +535,8 @@ public virtual void TestOpenIfChangedReplaceTaxonomy() Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, r2.GetOrdinal(cp_a)); Assert.AreEqual(cp_b, r2.GetPath(1)); - (r2).Dispose(); - (r1).Dispose(); + r2.Dispose(); + r1.Dispose(); writer.Dispose(); dir.Dispose(); } @@ -594,7 +595,7 @@ public virtual void TestGetChildren() it.MoveNext(); FacetLabel root = taxoReader.GetPath(it.Current); Assert.AreEqual(1, root.Length); - Assert.True(roots.Remove(root.Components[0])); + Assert.IsTrue(roots.Remove(root.Components[0])); } Assert.AreEqual(false, it.MoveNext()); @@ -620,7 +621,5 @@ public virtual void TestGetChildren() dir.Dispose(); } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs index 1cf30066fa..a33b6bd2e6 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyWriter.cs @@ -81,7 +81,7 @@ public virtual void TestCommit() // commit() wasn't called. Directory dir = NewDirectory(); var ltw = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, NO_OP_CACHE); - Assert.False(DirectoryReader.IndexExists(dir)); + Assert.IsFalse(DirectoryReader.IndexExists(dir)); ltw.Commit(); // first commit, so that an index will be created ltw.AddCategory(new FacetLabel("a")); @@ -107,8 +107,8 @@ public virtual void TestCommitUserData() var r = DirectoryReader.Open(dir); Assert.AreEqual(3, r.NumDocs, "2 categories plus root should have been committed to the underlying directory"); var readUserCommitData = r.IndexCommit.UserData; - Assert.True("1 2 3".Equals(readUserCommitData["testing"], StringComparison.Ordinal), "wrong value extracted from commit data"); - Assert.NotNull(DirectoryTaxonomyWriter.INDEX_EPOCH + " not found in commitData", readUserCommitData[DirectoryTaxonomyWriter.INDEX_EPOCH]); + Assert.IsTrue("1 2 3".Equals(readUserCommitData["testing"], StringComparison.Ordinal), "wrong value extracted from commit data"); + Assert.IsNotNull(DirectoryTaxonomyWriter.INDEX_EPOCH + " not found in commitData", readUserCommitData[DirectoryTaxonomyWriter.INDEX_EPOCH]); r.Dispose(); // open DirTaxoWriter again and commit, INDEX_EPOCH should still exist @@ -116,8 +116,6 @@ public virtual void TestCommitUserData() // that the taxonomy index has been recreated. taxoWriter = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, NO_OP_CACHE); taxoWriter.AddCategory(new FacetLabel("c")); // add a category so that commit will happen - - taxoWriter.SetCommitData(new Dictionary() { {"just", "data"} @@ -162,9 +160,9 @@ public virtual void TestRecreateRollback() { // Tests rollback with OpenMode.CREATE Directory dir = NewDirectory(); - (new DirectoryTaxonomyWriter(dir)).Dispose(); + new DirectoryTaxonomyWriter(dir).Dispose(); Assert.AreEqual(1, getEpoch(dir)); - (new DirectoryTaxonomyWriter(dir, OpenMode.CREATE)).Rollback(); + new DirectoryTaxonomyWriter(dir, OpenMode.CREATE).Rollback(); Assert.AreEqual(1, getEpoch(dir)); dir.Dispose(); @@ -217,7 +215,7 @@ public virtual void TestRecreateAndRefresh() var newtr = TaxonomyReader.OpenIfChanged(taxoReader); taxoReader.Dispose(); taxoReader = newtr; - Assert.AreEqual(1, Convert.ToInt32(taxoReader.CommitUserData[DirectoryTaxonomyWriter.INDEX_EPOCH])); + Assert.AreEqual(1, Convert.ToInt32(taxoReader.CommitUserData[DirectoryTaxonomyWriter.INDEX_EPOCH], CultureInfo.InvariantCulture)); // now recreate the taxonomy, and check that the epoch is preserved after opening DirTW again. taxoWriter.Dispose(); @@ -232,7 +230,7 @@ public virtual void TestRecreateAndRefresh() newtr = TaxonomyReader.OpenIfChanged(taxoReader); taxoReader.Dispose(); taxoReader = newtr; - Assert.AreEqual(2, Convert.ToInt32(taxoReader.CommitUserData[DirectoryTaxonomyWriter.INDEX_EPOCH])); + Assert.AreEqual(2, Convert.ToInt32(taxoReader.CommitUserData[DirectoryTaxonomyWriter.INDEX_EPOCH], CultureInfo.InvariantCulture)); taxoReader.Dispose(); dir.Dispose(); @@ -246,22 +244,23 @@ public virtual void TestBackwardsCompatibility() Directory dir = NewDirectory(); // create an empty index first, so that DirTaxoWriter initializes indexEpoch to 1. - (new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null))).Dispose(); + new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).Dispose(); var taxoWriter = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, NO_OP_CACHE); taxoWriter.Dispose(); var taxoReader = new DirectoryTaxonomyReader(dir); - Assert.AreEqual(1, Convert.ToInt32(taxoReader.CommitUserData[DirectoryTaxonomyWriter.INDEX_EPOCH])); - Assert.Null(TaxonomyReader.OpenIfChanged(taxoReader)); - (taxoReader).Dispose(); + Assert.AreEqual(1, Convert.ToInt32(taxoReader.CommitUserData[DirectoryTaxonomyWriter.INDEX_EPOCH], CultureInfo.InvariantCulture)); + Assert.IsNull(TaxonomyReader.OpenIfChanged(taxoReader)); + taxoReader.Dispose(); dir.Dispose(); } [Test] [Slow] - [Deadlock][Timeout(1200000)] + [Deadlock] + [Timeout(1200000)] public virtual void TestConcurrency() { int ncats = AtLeast(100000); // add many categories @@ -328,7 +327,7 @@ public virtual void TestConcurrency() foreach (string cat in values.Keys) { FacetLabel cp = new FacetLabel(FacetsConfig.StringToPath(cat)); - Assert.True(dtr.GetOrdinal(cp) > 0, "category not found " + cp); + Assert.IsTrue(dtr.GetOrdinal(cp) > 0, "category not found " + cp); int level = cp.Length; int parentOrd = 0; // for root, parent is always virtual ROOT (ord=0) FacetLabel path /*= new FacetLabel()*/; @@ -373,7 +372,7 @@ public override void Run() Convert.ToString(value / 100000, CultureInfo.InvariantCulture), Convert.ToString(value, CultureInfo.InvariantCulture)); int ord = tw.AddCategory(cp); - Assert.True(tw.GetParent(ord) != -1, "invalid parent for ordinal " + ord + ", category " + cp); + Assert.IsTrue(tw.GetParent(ord) != -1, "invalid parent for ordinal " + ord + ", category " + cp); string l1 = FacetsConfig.PathToString(cp.Components, 1); string l2 = FacetsConfig.PathToString(cp.Components, 2); string l3 = FacetsConfig.PathToString(cp.Components, 3); @@ -395,7 +394,7 @@ private long getEpoch(Directory taxoDir) { SegmentInfos infos = new SegmentInfos(); infos.Read(taxoDir); - return Convert.ToInt64(infos.UserData[DirectoryTaxonomyWriter.INDEX_EPOCH]); + return Convert.ToInt64(infos.UserData[DirectoryTaxonomyWriter.INDEX_EPOCH], CultureInfo.InvariantCulture); } [Test] @@ -424,13 +423,13 @@ public virtual void TestReplaceTaxonomy() // add the same category again -- it should not receive the same ordinal ! int newOrdB = taxoWriter.AddCategory(new FacetLabel("b")); - Assert.AreNotSame(ordB, newOrdB, "new ordinal cannot be the original ordinal"); + Assert.AreNotEqual(ordB, newOrdB, "new ordinal cannot be the original ordinal"); // LUCENENET specific: Changed to AreNotEqual instead of AreNotSame (boxing) Assert.AreEqual(2, newOrdB, "ordinal should have been 2 since only one category was added by replaceTaxonomy"); taxoWriter.Dispose(); long newEpoch = getEpoch(dir); - Assert.True(origEpoch < newEpoch, "index epoch should have been updated after replaceTaxonomy"); + Assert.IsTrue(origEpoch < newEpoch, "index epoch should have been updated after replaceTaxonomy"); dir.Dispose(); input.Dispose(); @@ -446,7 +445,7 @@ public virtual void TestReaderFreshness() DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE, NO_OP_CACHE); int o1 = taxoWriter.AddCategory(new FacetLabel("a")); int o2 = taxoWriter.AddCategory(new FacetLabel("a")); - Assert.True(o1 == o2, "ordinal for same category that is added twice should be the same !"); + Assert.IsTrue(o1 == o2, "ordinal for same category that is added twice should be the same !"); taxoWriter.Dispose(); dir.Dispose(); } @@ -576,7 +575,5 @@ public virtual void TestReplaceTaxoWithLargeTaxonomy() srcTaxoDir.Dispose(); targetTaxoDir.Dispose(); } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestCachedOrdinalsReader.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestCachedOrdinalsReader.cs index b9d65b99f6..c5911bbacf 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestCachedOrdinalsReader.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestCachedOrdinalsReader.cs @@ -6,7 +6,6 @@ namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -85,11 +84,11 @@ private class ThreadAnonymousInnerClassHelper : ThreadJob { private readonly TestCachedOrdinalsReader outerInstance; - private DirectoryReader reader; - private Lucene.Net.Facet.Taxonomy.CachedOrdinalsReader ordsReader; + private readonly DirectoryReader reader; + private readonly CachedOrdinalsReader ordsReader; - public ThreadAnonymousInnerClassHelper(TestCachedOrdinalsReader outerInstance, string CachedOrdsThread, DirectoryReader reader, Lucene.Net.Facet.Taxonomy.CachedOrdinalsReader ordsReader) - : base("CachedOrdsThread-") + public ThreadAnonymousInnerClassHelper(TestCachedOrdinalsReader outerInstance, string threadName, DirectoryReader reader, CachedOrdinalsReader ordsReader) + : base(threadName) { this.outerInstance = outerInstance; this.reader = reader; @@ -112,5 +111,4 @@ public override void Run() } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestFacetLabel.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestFacetLabel.cs index b47f13ce4d..de7cef35a1 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestFacetLabel.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestFacetLabel.cs @@ -1,15 +1,11 @@ using Lucene.Net.Support; using NUnit.Framework; using System; +using System.Globalization; using Assert = Lucene.Net.TestFramework.Assert; namespace Lucene.Net.Facet.Taxonomy { - - using BytesRef = Lucene.Net.Util.BytesRef; - using SortedSetDocValuesFacetField = Lucene.Net.Facet.SortedSet.SortedSetDocValuesFacetField; - using TestUtil = Lucene.Net.Util.TestUtil; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -26,6 +22,11 @@ namespace Lucene.Net.Facet.Taxonomy * See the License for the specific language governing permissions and * limitations under the License. */ + + using BytesRef = Lucene.Net.Util.BytesRef; + using SortedSetDocValuesFacetField = Lucene.Net.Facet.SortedSet.SortedSetDocValuesFacetField; + using TestUtil = Lucene.Net.Util.TestUtil; + [TestFixture] public class TestFacetLabel : FacetTestCase { @@ -33,20 +34,20 @@ public class TestFacetLabel : FacetTestCase [Test] public virtual void TestBasic() { - Assert.AreEqual(0, (new FacetLabel()).Length); - Assert.AreEqual(1, (new FacetLabel("hello")).Length); - Assert.AreEqual(2, (new FacetLabel("hello", "world")).Length); + Assert.AreEqual(0, new FacetLabel().Length); + Assert.AreEqual(1, new FacetLabel("hello").Length); + Assert.AreEqual(2, new FacetLabel("hello", "world").Length); } [Test] public virtual void TestToString() { // When the category is empty, we expect an empty string - Assert.AreEqual("FacetLabel: []", (new FacetLabel()).ToString()); + Assert.AreEqual("FacetLabel: []", new FacetLabel().ToString()); // one category - Assert.AreEqual("FacetLabel: [hello]", (new FacetLabel("hello")).ToString()); + Assert.AreEqual("FacetLabel: [hello]", new FacetLabel("hello").ToString()); // more than one category - Assert.AreEqual("FacetLabel: [hello, world]", (new FacetLabel("hello", "world")).ToString()); + Assert.AreEqual("FacetLabel: [hello, world]", new FacetLabel("hello", "world").ToString()); } [Test] @@ -55,12 +56,12 @@ public virtual void TestGetComponent() string[] components = new string[AtLeast(10)]; for (int i = 0; i < components.Length; i++) { - components[i] = Convert.ToString(i); + components[i] = Convert.ToString(i, CultureInfo.InvariantCulture); } FacetLabel cp = new FacetLabel(components); for (int i = 0; i < components.Length; i++) { - Assert.AreEqual(i, Convert.ToInt32(cp.Components[i])); + Assert.AreEqual(i, Convert.ToInt32(cp.Components[i], CultureInfo.InvariantCulture)); } } @@ -109,25 +110,25 @@ public virtual void TestSubPath() public virtual void TestEquals() { Assert.AreEqual(new FacetLabel(), new FacetLabel()); - Assert.False((new FacetLabel()).Equals(new FacetLabel("hi"))); - Assert.False((new FacetLabel()).Equals(Convert.ToInt32(3))); + Assert.IsFalse(new FacetLabel().Equals(new FacetLabel("hi"))); + Assert.IsFalse(new FacetLabel().Equals(Convert.ToInt32(3))); Assert.AreEqual(new FacetLabel("hello", "world"), new FacetLabel("hello", "world")); } [Test] public virtual void TestHashCode() { - Assert.AreEqual((new FacetLabel()).GetHashCode(), (new FacetLabel()).GetHashCode()); - Assert.False((new FacetLabel()).GetHashCode() == (new FacetLabel("hi")).GetHashCode()); - Assert.AreEqual((new FacetLabel("hello", "world")).GetHashCode(), (new FacetLabel("hello", "world")).GetHashCode()); + Assert.AreEqual(new FacetLabel().GetHashCode(), new FacetLabel().GetHashCode()); + Assert.IsFalse(new FacetLabel().GetHashCode() == new FacetLabel("hi").GetHashCode()); + Assert.AreEqual(new FacetLabel("hello", "world").GetHashCode(), new FacetLabel("hello", "world").GetHashCode()); } [Test] public virtual void TestLongHashCode() { - Assert.AreEqual((new FacetLabel()).Int64HashCode(), (new FacetLabel()).Int64HashCode()); - Assert.False((new FacetLabel()).Int64HashCode() == (new FacetLabel("hi")).Int64HashCode()); - Assert.AreEqual((new FacetLabel("hello", "world")).Int64HashCode(), (new FacetLabel("hello", "world")).Int64HashCode()); + Assert.AreEqual(new FacetLabel().Int64HashCode(), new FacetLabel().Int64HashCode()); + Assert.IsFalse(new FacetLabel().Int64HashCode() == new FacetLabel("hi").Int64HashCode()); + Assert.AreEqual(new FacetLabel("hello", "world").Int64HashCode(), new FacetLabel("hello", "world").Int64HashCode()); } [Test] @@ -146,38 +147,37 @@ public virtual void TestCompareTo() Assert.AreEqual(0, pother.CompareTo(p)); Assert.AreEqual(0, p.CompareTo(pother)); pother = new FacetLabel(); - Assert.True(pother.CompareTo(p) < 0); - Assert.True(p.CompareTo(pother) > 0); + Assert.IsTrue(pother.CompareTo(p) < 0); + Assert.IsTrue(p.CompareTo(pother) > 0); pother = new FacetLabel("a", "b_", "c", "d"); - Assert.True(pother.CompareTo(p) > 0); - Assert.True(p.CompareTo(pother) < 0); + Assert.IsTrue(pother.CompareTo(p) > 0); + Assert.IsTrue(p.CompareTo(pother) < 0); pother = new FacetLabel("a", "b", "c"); - Assert.True(pother.CompareTo(p) < 0); - Assert.True(p.CompareTo(pother) > 0); + Assert.IsTrue(pother.CompareTo(p) < 0); + Assert.IsTrue(p.CompareTo(pother) > 0); pother = new FacetLabel("a", "b", "c", "e"); - Assert.True(pother.CompareTo(p) > 0); - Assert.True(p.CompareTo(pother) < 0); + Assert.IsTrue(pother.CompareTo(p) > 0); + Assert.IsTrue(p.CompareTo(pother) < 0); } [Test] public virtual void TestEmptyNullComponents() { // LUCENE-4724: CategoryPath should not allow empty or null components - string[][] components_tests = new string[][] - { - new string[] {"", "test"}, - new string[] {"test", ""}, - new string[] {"test", "", "foo"}, - new string[] {null, "test"}, - new string[] {"test", null}, - new string[] {"test", null, "foo"} - }; + string[][] components_tests = new string[][] { + new string[] {"", "test"}, // empty in the beginning + new string[] {"test", ""}, // empty in the end + new string[] {"test", "", "foo"}, // empty in the middle + new string[] {null, "test"}, // null at the beginning + new string[] {"test", null}, // null in the end + new string[] {"test", null, "foo"} // null in the middle + }; foreach (string[] components in components_tests) { try { - Assert.NotNull(new FacetLabel(components)); + Assert.IsNotNull(new FacetLabel(components)); fail("empty or null components should not be allowed: " + Arrays.ToString(components)); } catch (ArgumentException) @@ -186,7 +186,7 @@ public virtual void TestEmptyNullComponents() } try { - new FacetField("dim", components); + _ = new FacetField("dim", components); fail("empty or null components should not be allowed: " + Arrays.ToString(components)); } catch (ArgumentException) @@ -195,7 +195,7 @@ public virtual void TestEmptyNullComponents() } try { - new AssociationFacetField(new BytesRef(), "dim", components); + _ = new AssociationFacetField(new BytesRef(), "dim", components); fail("empty or null components should not be allowed: " + Arrays.ToString(components)); } catch (ArgumentException) @@ -204,7 +204,7 @@ public virtual void TestEmptyNullComponents() } try { - new Int32AssociationFacetField(17, "dim", components); + _ = new Int32AssociationFacetField(17, "dim", components); fail("empty or null components should not be allowed: " + Arrays.ToString(components)); } catch (ArgumentException) @@ -213,7 +213,7 @@ public virtual void TestEmptyNullComponents() } try { - new SingleAssociationFacetField(17.0f, "dim", components); + _ = new SingleAssociationFacetField(17.0f, "dim", components); fail("empty or null components should not be allowed: " + Arrays.ToString(components)); } catch (ArgumentException) @@ -223,7 +223,7 @@ public virtual void TestEmptyNullComponents() } try { - new FacetField(null, new string[] { "abc" }); + _ = new FacetField(null, new string[] { "abc" }); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -232,7 +232,7 @@ public virtual void TestEmptyNullComponents() } try { - new FacetField("", new string[] { "abc" }); + _ = new FacetField("", new string[] { "abc" }); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -241,7 +241,7 @@ public virtual void TestEmptyNullComponents() } try { - new Int32AssociationFacetField(17, null, new string[] { "abc" }); + _ = new Int32AssociationFacetField(17, null, new string[] { "abc" }); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -250,7 +250,7 @@ public virtual void TestEmptyNullComponents() } try { - new Int32AssociationFacetField(17, "", new string[] { "abc" }); + _ = new Int32AssociationFacetField(17, "", new string[] { "abc" }); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -259,7 +259,7 @@ public virtual void TestEmptyNullComponents() } try { - new SingleAssociationFacetField(17.0f, null, new string[] { "abc" }); + _ = new SingleAssociationFacetField(17.0f, null, new string[] { "abc" }); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -268,7 +268,7 @@ public virtual void TestEmptyNullComponents() } try { - new SingleAssociationFacetField(17.0f, "", new string[] { "abc" }); + _ = new SingleAssociationFacetField(17.0f, "", new string[] { "abc" }); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -277,7 +277,7 @@ public virtual void TestEmptyNullComponents() } try { - new AssociationFacetField(new BytesRef(), null, new string[] { "abc" }); + _ = new AssociationFacetField(new BytesRef(), null, new string[] { "abc" }); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -286,7 +286,7 @@ public virtual void TestEmptyNullComponents() } try { - new AssociationFacetField(new BytesRef(), "", new string[] { "abc" }); + _ = new AssociationFacetField(new BytesRef(), "", new string[] { "abc" }); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -295,7 +295,7 @@ public virtual void TestEmptyNullComponents() } try { - new SortedSetDocValuesFacetField(null, "abc"); + _ = new SortedSetDocValuesFacetField(null, "abc"); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -304,7 +304,7 @@ public virtual void TestEmptyNullComponents() } try { - new SortedSetDocValuesFacetField("", "abc"); + _ = new SortedSetDocValuesFacetField("", "abc"); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -313,7 +313,7 @@ public virtual void TestEmptyNullComponents() } try { - new SortedSetDocValuesFacetField("dim", null); + _ = new SortedSetDocValuesFacetField("dim", null); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -322,7 +322,7 @@ public virtual void TestEmptyNullComponents() } try { - new SortedSetDocValuesFacetField("dim", ""); + _ = new SortedSetDocValuesFacetField("dim", ""); fail("empty or null components should not be allowed"); } catch (ArgumentException) @@ -348,7 +348,7 @@ public virtual void TestLongPath() try { - Assert.NotNull(new FacetLabel("dim", bigComp)); + Assert.IsNotNull(new FacetLabel("dim", bigComp)); fail("long paths should not be allowed; len=" + bigComp.Length); } catch (ArgumentException) @@ -357,5 +357,4 @@ public virtual void TestLongPath() } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs index d73c3a230a..e2c37cada0 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs @@ -3,7 +3,6 @@ namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,7 +20,6 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - using Lucene.Net.Facet.Taxonomy; [TestFixture] public class TestLRUHashMap : FacetTestCase { @@ -41,32 +39,31 @@ public virtual void TestLru() Assert.AreEqual(3, lru.Count); lru.Put("four", "Shalom"); Assert.AreEqual(3, lru.Count); - Assert.NotNull(lru.Get("three")); - Assert.NotNull(lru.Get("two")); - Assert.NotNull(lru.Get("four")); - Assert.Null(lru.Get("one")); + Assert.IsNotNull(lru.Get("three")); + Assert.IsNotNull(lru.Get("two")); + Assert.IsNotNull(lru.Get("four")); + Assert.IsNull(lru.Get("one")); lru.Put("five", "Yo!"); Assert.AreEqual(3, lru.Count); - Assert.Null(lru.Get("three")); // three was last used, so it got removed - Assert.NotNull(lru.Get("five")); + Assert.IsNull(lru.Get("three")); // three was last used, so it got removed + Assert.IsNotNull(lru.Get("five")); lru.Get("four"); lru.Put("six", "hi"); lru.Put("seven", "hey dude"); Assert.AreEqual(3, lru.Count); - Assert.Null(lru.Get("one")); - Assert.Null(lru.Get("two")); - Assert.Null(lru.Get("three")); - Assert.NotNull(lru.Get("four")); - Assert.Null(lru.Get("five")); - Assert.NotNull(lru.Get("six")); - Assert.NotNull(lru.Get("seven")); + Assert.IsNull(lru.Get("one")); + Assert.IsNull(lru.Get("two")); + Assert.IsNull(lru.Get("three")); + Assert.IsNotNull(lru.Get("four")); + Assert.IsNull(lru.Get("five")); + Assert.IsNotNull(lru.Get("six")); + Assert.IsNotNull(lru.Get("seven")); // LUCENENET specific tests to ensure Put is implemented correctly - Assert.Null(lru.Put("ten", "oops")); + Assert.IsNull(lru.Put("ten", "oops")); assertEquals("oops", lru.Put("ten", "not oops")); assertEquals("not oops", lru.Put("ten", "new value")); assertEquals("new value", lru.Put("ten", "new value2")); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs index 9717ba550f..ae1d41f4e2 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestSearcherTaxonomyManager.cs @@ -45,16 +45,14 @@ namespace Lucene.Net.Facet.Taxonomy [TestFixture] public class TestSearcherTaxonomyManager : FacetTestCase { - private class IndexerThread : ThreadJob { - - internal IndexWriter w; - internal FacetsConfig config; - internal ITaxonomyWriter tw; - internal ReferenceManager mgr; - internal int ordLimit; - internal AtomicBoolean stop; + private readonly IndexWriter w; + private readonly FacetsConfig config; + private readonly ITaxonomyWriter tw; + private readonly ReferenceManager mgr; + private readonly int ordLimit; + private readonly AtomicBoolean stop; public IndexerThread(IndexWriter w, FacetsConfig config, ITaxonomyWriter tw, ReferenceManager mgr, int ordLimit, AtomicBoolean stop) { @@ -188,8 +186,8 @@ public virtual void TestNrt() if (pair.Searcher.IndexReader.NumDocs > 0) { //System.out.println(pair.taxonomyReader.getSize()); - Assert.True(result.ChildCount > 0); - Assert.True(result.LabelValues.Length > 0); + Assert.IsTrue(result.ChildCount > 0); + Assert.IsTrue(result.LabelValues.Length > 0); } //if (VERBOSE) { @@ -298,8 +296,8 @@ public virtual void Test_Directory() // LUCENENET specific - name collides with if (pair.Searcher.IndexReader.NumDocs > 0) { //System.out.println(pair.taxonomyReader.getSize()); - Assert.True(result.ChildCount > 0); - Assert.True(result.LabelValues.Length > 0); + Assert.IsTrue(result.ChildCount > 0); + Assert.IsTrue(result.LabelValues.Length > 0); } //if (VERBOSE) { @@ -400,7 +398,5 @@ public virtual void TestReplaceTaxonomyDirectory() IOUtils.Dispose(mgr, tw, w, taxoDir, indexDir); } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs index 634bf9799b..a85954d4db 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs @@ -11,11 +11,6 @@ namespace Lucene.Net.Facet.Taxonomy { - using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader; - using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; - using LockObtainFailedException = Lucene.Net.Store.LockObtainFailedException; - using RAMDirectory = Lucene.Net.Store.RAMDirectory; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -33,6 +28,10 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ + using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader; + using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; + using LockObtainFailedException = Lucene.Net.Store.LockObtainFailedException; + using RAMDirectory = Lucene.Net.Store.RAMDirectory; [TestFixture] [SuppressCodecs("SimpleText", "Lucene3x")] @@ -43,21 +42,20 @@ public class TestTaxonomyCombined : FacetTestCase /// The following categories will be added to the taxonomy by /// fillTaxonomy(), and tested by all tests below: /// - private static readonly string[][] categories = new string[][] - { - new string[] {"Author", "Tom Clancy"}, - new string[] {"Author", "Richard Dawkins"}, - new string[] {"Author", "Richard Adams"}, - new string[] {"Price", "10", "11"}, - new string[] {"Price", "10", "12"}, - new string[] {"Price", "20", "27"}, - new string[] {"Date", "2006", "05"}, - new string[] {"Date", "2005"}, - new string[] {"Date", "2006"}, - new string[] {"Subject", "Nonfiction", "Children", "Animals"}, - new string[] {"Author", "Stephen Jay Gould"}, - new string[] {"Author", "\u05e0\u05d3\u05d1\u3042\u0628"} - }; + private static readonly string[][] categories = new string[][] { + new string[] {"Author", "Tom Clancy"}, + new string[] {"Author", "Richard Dawkins"}, + new string[] {"Author", "Richard Adams"}, + new string[] {"Price", "10", "11"}, + new string[] {"Price", "10", "12"}, + new string[] {"Price", "20", "27"}, + new string[] {"Date", "2006", "05"}, + new string[] {"Date", "2005"}, + new string[] {"Date", "2006"}, + new string[] {"Subject", "Nonfiction", "Children", "Animals"}, + new string[] {"Author", "Stephen Jay Gould"}, + new string[] {"Author", "\u05e0\u05d3\u05d1\u3042\u0628"} + }; /// /// When adding the above categories with ITaxonomyWriter.AddCategory(), @@ -66,8 +64,7 @@ public class TestTaxonomyCombined : FacetTestCase /// not tested - rather, just the last component, the ordinal, is returned /// and tested. /// - private static readonly int[][] ExpectedPaths = - { + private static readonly int[][] ExpectedPaths = { new int[] {1, 2}, new int[] {1, 3}, new int[] {1, 4}, @@ -87,7 +84,29 @@ public class TestTaxonomyCombined : FacetTestCase /// generated categories, with increasing ordinals (note how parent /// categories are be added automatically when subcategories are added). /// - private static readonly string[][] ExpectedCategories = new string[][] { new string[] { }, new string[] { "Author" }, new string[] { "Author", "Tom Clancy" }, new string[] { "Author", "Richard Dawkins" }, new string[] { "Author", "Richard Adams" }, new string[] { "Price" }, new string[] { "Price", "10" }, new string[] { "Price", "10", "11" }, new string[] { "Price", "10", "12" }, new string[] { "Price", "20" }, new string[] { "Price", "20", "27" }, new string[] { "Date" }, new string[] { "Date", "2006" }, new string[] { "Date", "2006", "05" }, new string[] { "Date", "2005" }, new string[] { "Subject" }, new string[] { "Subject", "Nonfiction" }, new string[] { "Subject", "Nonfiction", "Children" }, new string[] { "Subject", "Nonfiction", "Children", "Animals" }, new string[] { "Author", "Stephen Jay Gould" }, new string[] { "Author", "\u05e0\u05d3\u05d1\u3042\u0628" } }; + private static readonly string[][] ExpectedCategories = new string[][] { + new string[] { }, + new string[] { "Author" }, + new string[] { "Author", "Tom Clancy" }, + new string[] { "Author", "Richard Dawkins" }, + new string[] { "Author", "Richard Adams" }, + new string[] { "Price" }, + new string[] { "Price", "10" }, + new string[] { "Price", "10", "11" }, + new string[] { "Price", "10", "12" }, + new string[] { "Price", "20" }, + new string[] { "Price", "20", "27" }, + new string[] { "Date" }, + new string[] { "Date", "2006" }, + new string[] { "Date", "2006", "05" }, + new string[] { "Date", "2005" }, + new string[] { "Subject" }, + new string[] { "Subject", "Nonfiction" }, + new string[] { "Subject", "Nonfiction", "Children" }, + new string[] { "Subject", "Nonfiction", "Children", "Animals" }, + new string[] { "Author", "Stephen Jay Gould" }, + new string[] { "Author", "\u05e0\u05d3\u05d1\u3042\u0628" } + }; /// /// fillTaxonomy adds the categories in the categories[] array, and asserts @@ -370,13 +389,14 @@ public virtual void TestReaderBasic() FacetLabel category = tr.GetPath(i); if (!expectedCategory.Equals(category)) { - fail("For ordinal " + i + " expected category " + Showcat(expectedCategory) + ", but got " + Showcat(category)); + fail("For ordinal " + i + " expected category " + + Showcat(expectedCategory) + ", but got " + Showcat(category)); } } // (also test invalid ordinals:) - Assert.Null(tr.GetPath(-1)); - Assert.Null(tr.GetPath(tr.Count)); - Assert.Null(tr.GetPath(TaxonomyReader.INVALID_ORDINAL)); + Assert.IsNull(tr.GetPath(-1)); + Assert.IsNull(tr.GetPath(tr.Count)); + Assert.IsNull(tr.GetPath(TaxonomyReader.INVALID_ORDINAL)); // test TaxonomyReader.GetOrdinal(): for (int i = 1; i < ExpectedCategories.Length; i++) @@ -385,7 +405,8 @@ public virtual void TestReaderBasic() int ordinal = tr.GetOrdinal(new FacetLabel(ExpectedCategories[i])); if (expectedOrdinal != ordinal) { - fail("For category " + Showcat(ExpectedCategories[i]) + " expected ordinal " + expectedOrdinal + ", but got " + ordinal); + fail("For category " + Showcat(ExpectedCategories[i]) + " expected ordinal " + + expectedOrdinal + ", but got " + ordinal); } } // (also test invalid categories:) @@ -430,12 +451,15 @@ public virtual void TestReaderParent() FacetLabel parent = tr.GetPath(parentOrdinal); if (parent is null) { - fail("Parent of " + ordinal + " is " + parentOrdinal + ", but this is not a valid category."); + fail("Parent of " + ordinal + " is " + parentOrdinal + + ", but this is not a valid category."); } // verify that the parent is indeed my parent, according to the strings if (!me.Subpath(me.Length - 1).Equals(parent)) { - fail("Got parent " + parentOrdinal + " for ordinal " + ordinal + " but categories are " + Showcat(parent) + " and " + Showcat(me) + " respectively."); + fail("Got parent " + parentOrdinal + " for ordinal " + ordinal + + " but categories are " + Showcat(parent) + " and " + Showcat(me) + + " respectively."); } } @@ -502,13 +526,16 @@ private void CheckWriterParent(TaxonomyReader tr, ITaxonomyWriter tw) FacetLabel parent = tr.GetPath(parentOrdinal); if (parent is null) { - fail("Parent of " + ordinal + " is " + parentOrdinal + ", but this is not a valid category."); + fail("Parent of " + ordinal + " is " + parentOrdinal + + ", but this is not a valid category."); } // verify that the parent is indeed my parent, according to the // strings if (!me.Subpath(me.Length - 1).Equals(parent)) { - fail("Got parent " + parentOrdinal + " for ordinal " + ordinal + " but categories are " + Showcat(parent) + " and " + Showcat(me) + " respectively."); + fail("Got parent " + parentOrdinal + " for ordinal " + ordinal + + " but categories are " + Showcat(parent) + " and " + + Showcat(me) + " respectively."); } } @@ -649,7 +676,7 @@ public virtual void TestChildrenArraysInvariants() // (it can also be INVALID_ORDINAL, which is lower than any ordinal) for (int i = 0; i < tr.Count; i++) { - Assert.True(olderSiblingArray[i] < i, "olderSiblingArray[" + i + "] should be <" + i); + Assert.IsTrue(olderSiblingArray[i] < i, "olderSiblingArray[" + i + "] should be <" + i); } // test that the "older sibling" of every category is indeed a sibling @@ -727,8 +754,8 @@ public virtual void TestChildrenArraysGrowth() Assert.AreEqual(3, tr.Count); Assert.AreEqual(3, ca.Siblings.Length); Assert.AreEqual(3, ca.Children.Length); - Assert.True(Arrays.Equals(new int[] { 1, 2, -1 }, ca.Children)); - Assert.True(Arrays.Equals(new int[] { -1, -1, -1 }, ca.Siblings)); + Assert.IsTrue(Arrays.Equals(new int[] { 1, 2, -1 }, ca.Children)); + Assert.IsTrue(Arrays.Equals(new int[] { -1, -1, -1 }, ca.Siblings)); tw.AddCategory(new FacetLabel("hi", "ho")); tw.AddCategory(new FacetLabel("hello")); tw.Commit(); @@ -740,15 +767,15 @@ public virtual void TestChildrenArraysGrowth() Assert.AreEqual(3, ca.Children.Length); // After the refresh, things change: var newtr = TaxonomyReader.OpenIfChanged(tr); - Assert.NotNull(newtr); + Assert.IsNotNull(newtr); tr.Dispose(); tr = newtr; ca = tr.ParallelTaxonomyArrays; Assert.AreEqual(5, tr.Count); Assert.AreEqual(5, ca.Siblings.Length); Assert.AreEqual(5, ca.Children.Length); - Assert.True(Arrays.Equals(new int[] { 4, 3, -1, -1, -1 }, ca.Children)); - Assert.True(Arrays.Equals(new int[] { -1, -1, -1, 2, 1 }, ca.Siblings)); + Assert.IsTrue(Arrays.Equals(new int[] { 4, 3, -1, -1, -1 }, ca.Children)); + Assert.IsTrue(Arrays.Equals(new int[] { -1, -1, -1, 2, 1 }, ca.Siblings)); tw.Dispose(); tr.Dispose(); indexDir.Dispose(); @@ -781,7 +808,7 @@ public virtual void TestTaxonomyReaderRefreshRaces() twBase.Dispose(); var newTaxoReader = TaxonomyReader.OpenIfChanged(trBase); - Assert.NotNull(newTaxoReader); + Assert.IsNotNull(newTaxoReader); trBase.Dispose(); trBase = newTaxoReader; @@ -807,7 +834,6 @@ private void AssertConsistentYoungestChild(FacetLabel abPath, int abOrd, int abY tw.AddCategory(abPath); tw.Commit(); - var tr = new DirectoryTaxonomyReader(indexDir); for (int i = 0; i < numCategories; i++) { @@ -817,7 +843,6 @@ private void AssertConsistentYoungestChild(FacetLabel abPath, int abOrd, int abY } tw.Dispose(); - var stop = new AtomicBoolean(false); Exception[] error = new Exception[] { null }; int[] retrieval = new int[] { 0 }; @@ -825,7 +850,7 @@ private void AssertConsistentYoungestChild(FacetLabel abPath, int abOrd, int abY var thread = new ThreadAnonymousInnerClassHelper(this, abPath, abOrd, abYoungChildBase1, abYoungChildBase2, retry, tr, stop, error, retrieval); thread.Start(); - indexDir.SleepMillis = 1; // some delay for refresh + indexDir.SetSleepMillis(1); // some delay for refresh var newTaxoReader = TaxonomyReader.OpenIfChanged(tr); if (newTaxoReader != null) { @@ -834,7 +859,7 @@ private void AssertConsistentYoungestChild(FacetLabel abPath, int abOrd, int abY stop.Value = true; thread.Join(); - Assert.Null(error[0], "Unexpcted exception at retry " + retry + " retrieval " + retrieval[0] + ": \n" + stackTraceStr(error[0])); + Assert.IsNull(error[0], "Unexpcted exception at retry " + retry + " retrieval " + retrieval[0] + ": \n" + stackTraceStr(error[0])); tr.Dispose(); } @@ -843,17 +868,17 @@ private class ThreadAnonymousInnerClassHelper : ThreadJob { private readonly TestTaxonomyCombined outerInstance; - private Lucene.Net.Facet.Taxonomy.FacetLabel abPath; - private int abOrd; - private int abYoungChildBase1; - private int abYoungChildBase2; - private int retry; - private DirectoryTaxonomyReader tr; - private AtomicBoolean stop; - private Exception[] error; - private int[] retrieval; - - public ThreadAnonymousInnerClassHelper(TestTaxonomyCombined outerInstance, Lucene.Net.Facet.Taxonomy.FacetLabel abPath, int abOrd, int abYoungChildBase1, int abYoungChildBase2, int retry, DirectoryTaxonomyReader tr, AtomicBoolean stop, Exception[] error, int[] retrieval) + private readonly FacetLabel abPath; + private readonly int abOrd; + private readonly int abYoungChildBase1; + private readonly int abYoungChildBase2; + private readonly int retry; + private readonly DirectoryTaxonomyReader tr; + private readonly AtomicBoolean stop; + private readonly Exception[] error; + private readonly int[] retrieval; + + public ThreadAnonymousInnerClassHelper(TestTaxonomyCombined outerInstance, FacetLabel abPath, int abOrd, int abYoungChildBase1, int abYoungChildBase2, int retry, DirectoryTaxonomyReader tr, AtomicBoolean stop, Exception[] error, int[] retrieval) : base("Child Arrays Verifier") { this.outerInstance = outerInstance; @@ -878,7 +903,7 @@ public override void Run() while (!stop) { int lastOrd = tr.ParallelTaxonomyArrays.Parents.Length - 1; - Assert.NotNull(tr.GetPath(lastOrd), "path of last-ord " + lastOrd + " is not found!"); + Assert.IsNotNull(tr.GetPath(lastOrd), "path of last-ord " + lastOrd + " is not found!"); AssertChildrenArrays(tr.ParallelTaxonomyArrays, retry, retrieval[0]++); Thread.Sleep(10);// don't starve refresh()'s CPU, which sleeps every 50 bytes for 1 ms } @@ -893,7 +918,10 @@ public override void Run() private void AssertChildrenArrays(ParallelTaxonomyArrays ca, int retry, int retrieval) { int abYoungChild = ca.Children[abOrd]; - Assert.True(abYoungChildBase1 == abYoungChild || abYoungChildBase2 == ca.Children[abOrd], "Retry " + retry + ": retrieval: " + retrieval + ": wrong youngest child for category " + abPath + " (ord=" + abOrd + ") - must be either " + abYoungChildBase1 + " or " + abYoungChildBase2 + " but was: " + abYoungChild); + Assert.IsTrue(abYoungChildBase1 == abYoungChild || + abYoungChildBase2 == ca.Children[abOrd], + "Retry " + retry + ": retrieval: " + retrieval + ": wrong youngest child for category " + abPath + " (ord=" + abOrd + + ") - must be either " + abYoungChildBase1 + " or " + abYoungChildBase2 + " but was: " + abYoungChild); } } @@ -939,12 +967,12 @@ public virtual void TestSeparateReaderAndWriter() Assert.AreEqual(1, tr.Count); // the empty taxonomy has size 1 (the root) tw.AddCategory(new FacetLabel("Author")); Assert.AreEqual(1, tr.Count); // still root only... - Assert.Null(TaxonomyReader.OpenIfChanged(tr)); // this is not enough, because tw.Commit() hasn't been done yet + Assert.IsNull(TaxonomyReader.OpenIfChanged(tr)); // this is not enough, because tw.Commit() hasn't been done yet Assert.AreEqual(1, tr.Count); // still root only... tw.Commit(); Assert.AreEqual(1, tr.Count); // still root only... var newTaxoReader = TaxonomyReader.OpenIfChanged(tr); - Assert.NotNull(newTaxoReader); + Assert.IsNotNull(newTaxoReader); tr.Dispose(); tr = newTaxoReader; @@ -968,7 +996,7 @@ public virtual void TestSeparateReaderAndWriter() int dawkins = 2; tw.Commit(); newTaxoReader = TaxonomyReader.OpenIfChanged(tr); - Assert.NotNull(newTaxoReader); + Assert.IsNotNull(newTaxoReader); tr.Dispose(); tr = newTaxoReader; int[] parents = tr.ParallelTaxonomyArrays.Parents; @@ -998,7 +1026,7 @@ public virtual void TestSeparateReaderAndWriter2() // before commit and refresh, no change: Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.GetOrdinal(author)); Assert.AreEqual(1, tr.Count); // still root only... - Assert.Null(TaxonomyReader.OpenIfChanged(tr)); // this is not enough, because tw.Commit() hasn't been done yet + Assert.IsNull(TaxonomyReader.OpenIfChanged(tr)); // this is not enough, because tw.Commit() hasn't been done yet Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.GetOrdinal(author)); Assert.AreEqual(1, tr.Count); // still root only... tw.Commit(); @@ -1006,7 +1034,7 @@ public virtual void TestSeparateReaderAndWriter2() Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.GetOrdinal(author)); Assert.AreEqual(1, tr.Count); // still root only... var newTaxoReader = TaxonomyReader.OpenIfChanged(tr); - Assert.NotNull(newTaxoReader); + Assert.IsNotNull(newTaxoReader); tr.Dispose(); tr = newTaxoReader; Assert.AreEqual(1, tr.GetOrdinal(author)); @@ -1037,7 +1065,7 @@ public virtual void TestWriterLock() // We expect to get a LockObtainFailedException. try { - Assert.Null(new DirectoryTaxonomyWriter(indexDir)); + Assert.IsNull(new DirectoryTaxonomyWriter(indexDir)); fail("should have failed to write in locked directory"); } catch (LockObtainFailedException) @@ -1052,7 +1080,7 @@ public virtual void TestWriterLock() tw2.Dispose(); // See that the writer indeed wrote: var newtr = TaxonomyReader.OpenIfChanged(tr); - Assert.NotNull(newtr); + Assert.IsNotNull(newtr); tr.Dispose(); tr = newtr; Assert.AreEqual(3, tr.GetOrdinal(new FacetLabel("hey"))); @@ -1078,7 +1106,8 @@ public static void FillTaxonomyCheckPaths(ITaxonomyWriter tw) int expectedOrdinal = ExpectedPaths[i][ExpectedPaths[i].Length - 1]; if (ordinal != expectedOrdinal) { - fail("For category " + Showcat(categories[i]) + " expected ordinal " + expectedOrdinal + ", but got " + ordinal); + fail("For category " + Showcat(categories[i]) + " expected ordinal " + + expectedOrdinal + ", but got " + ordinal); } for (int j = ExpectedPaths[i].Length - 2; j >= 0; j--) { @@ -1086,7 +1115,9 @@ public static void FillTaxonomyCheckPaths(ITaxonomyWriter tw) expectedOrdinal = ExpectedPaths[i][j]; if (ordinal != expectedOrdinal) { - fail("For category " + Showcat(categories[i]) + " expected ancestor level " + (ExpectedPaths[i].Length - 1 - j) + " was " + expectedOrdinal + ", but got " + ordinal); + fail("For category " + Showcat(categories[i]) + " expected ancestor level " + + (ExpectedPaths[i].Length - 1 - j) + " was " + expectedOrdinal + + ", but got " + ordinal); } } } @@ -1105,7 +1136,9 @@ public static void CheckPaths(ITaxonomyWriter tw) int expectedOrdinal = ExpectedPaths[i][j]; if (ordinal != expectedOrdinal) { - fail("For category " + Showcat(categories[i]) + " expected ancestor level " + (ExpectedPaths[i].Length - 1 - j) + " was " + expectedOrdinal + ", but got " + ordinal); + fail("For category " + Showcat(categories[i]) + " expected ancestor level " + + (ExpectedPaths[i].Length - 1 - j) + " was " + expectedOrdinal + + ", but got " + ordinal); } } Assert.AreEqual(TaxonomyReader.ROOT_ORDINAL, tw.GetParent(ExpectedPaths[i][0])); @@ -1167,9 +1200,9 @@ public virtual void TestNrt() FacetLabel cp = new FacetLabel("a"); writer.AddCategory(cp); var newReader = TaxonomyReader.OpenIfChanged(reader); - Assert.NotNull(newReader, "expected a new instance"); + Assert.IsNotNull(newReader, "expected a new instance"); Assert.AreEqual(2, newReader.Count); - Assert.AreNotSame(TaxonomyReader.INVALID_ORDINAL, newReader.GetOrdinal(cp)); + Assert.AreNotEqual(TaxonomyReader.INVALID_ORDINAL, newReader.GetOrdinal(cp)); // LUCENENET specific: Changed from AreNotSame to AreNotEqual (boxing) reader.Dispose(); reader = newReader; @@ -1183,5 +1216,4 @@ public virtual void TestNrt() // using the same object (simulating threads) or different objects // (simulating processes). } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs index 0b5cab6ae5..424233d8ed 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs @@ -4,7 +4,6 @@ namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -39,7 +38,6 @@ namespace Lucene.Net.Facet.Taxonomy [TestFixture] public class TestTaxonomyFacetAssociations : FacetTestCase { - private static Store.Directory dir; private static IndexReader reader; private static Store.Directory taxoDir; @@ -297,7 +295,5 @@ public virtual void TestIntSumAssociationDrillDown() Assert.AreEqual(100, (int)facets.GetSpecificValue("int", "a"), "Wrong count for category 'a'!"); Assert.AreEqual(150, (int)facets.GetSpecificValue("int", "b"), "Wrong count for category 'b'!"); } - } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs index a5988dd2ae..2af17e1047 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts.cs @@ -12,7 +12,6 @@ namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -131,7 +130,7 @@ public virtual void TestBasic() Assert.AreEqual(1, facets.GetSpecificValue("Author", "Lisa")); - Assert.Null(facets.GetTopChildren(10, "Non exitent dim")); + Assert.IsNull(facets.GetTopChildren(10, "Non exitent dim")); // Smoke test PrintTaxonomyStats: string result; @@ -143,12 +142,12 @@ public virtual void TestBasic() } result = bos.ToString(); } - Assert.True(result.IndexOf("/Author: 4 immediate children; 5 total categories", StringComparison.Ordinal) != -1); - Assert.True(result.IndexOf("/Publish Date: 3 immediate children; 12 total categories", StringComparison.Ordinal) != -1); + Assert.IsTrue(result.IndexOf("/Author: 4 immediate children; 5 total categories", StringComparison.Ordinal) != -1); + Assert.IsTrue(result.IndexOf("/Publish Date: 3 immediate children; 12 total categories", StringComparison.Ordinal) != -1); // Make sure at least a few nodes of the tree came out: - Assert.True(result.IndexOf(" /1999", StringComparison.Ordinal) != -1); - Assert.True(result.IndexOf(" /2012", StringComparison.Ordinal) != -1); - Assert.True(result.IndexOf(" /20", StringComparison.Ordinal) != -1); + Assert.IsTrue(result.IndexOf(" /1999", StringComparison.Ordinal) != -1); + Assert.IsTrue(result.IndexOf(" /2012", StringComparison.Ordinal) != -1); + Assert.IsTrue(result.IndexOf(" /20", StringComparison.Ordinal) != -1); IOUtils.Dispose(writer, taxoWriter, searcher.IndexReader, taxoReader, taxoDir, dir); } @@ -267,7 +266,7 @@ public virtual void TestWrongIndexFieldName() // Ask for top 10 labels for any dims that have counts: IList results = facets.GetAllDims(10); - Assert.True(results.Count == 0); + Assert.IsTrue(results.Count == 0); try { @@ -320,7 +319,7 @@ public PerFieldSimilarityWrapperAnonymousInnerClassHelper(TestTaxonomyFacetCount sim = new DefaultSimilarity(); } - internal readonly Similarity sim; + private readonly Similarity sim; public override Similarity Get(string name) { @@ -890,5 +889,4 @@ public virtual void TestRandom() IOUtils.Dispose(w, tw, searcher.IndexReader, tr, indexDir, taxoDir); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs index 1241ad6019..eaeab0b0f6 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetCounts2.cs @@ -9,7 +9,6 @@ namespace Lucene.Net.Facet.Taxonomy { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -27,7 +26,6 @@ namespace Lucene.Net.Facet.Taxonomy * limitations under the License. */ - using DirectoryReader = Lucene.Net.Index.DirectoryReader; using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader; using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; @@ -148,17 +146,14 @@ private static void AddFacets(Document doc, FacetsConfig config, bool updateTerm } } - private static FacetsConfig Config + private static FacetsConfig GetConfig() { - get - { - FacetsConfig config = new FacetsConfig(); - config.SetMultiValued("A", true); - config.SetMultiValued("B", true); - config.SetRequireDimCount("B", true); - config.SetHierarchical("D", true); - return config; - } + FacetsConfig config = new FacetsConfig(); + config.SetMultiValued("A", true); + config.SetMultiValued("B", true); + config.SetRequireDimCount("B", true); + config.SetHierarchical("D", true); + return config; } private static void IndexDocsNoFacets(IndexWriter indexWriter) @@ -177,7 +172,7 @@ private static void IndexDocsWithFacetsNoTerms(IndexWriter indexWriter, ITaxonom { Random random = Random; int numDocs = AtLeast(random, 2); - FacetsConfig config = Config; + FacetsConfig config = GetConfig(); for (int i = 0; i < numDocs; i++) { Document doc = new Document(); @@ -191,7 +186,7 @@ private static void IndexDocsWithFacetsAndTerms(IndexWriter indexWriter, ITaxono { Random random = Random; int numDocs = AtLeast(random, 2); - FacetsConfig config = Config; + FacetsConfig config = GetConfig(); for (int i = 0; i < numDocs; i++) { Document doc = new Document(); @@ -206,7 +201,7 @@ private static void IndexDocsWithFacetsAndSomeTerms(IndexWriter indexWriter, ITa { Random random = Random; int numDocs = AtLeast(random, 2); - FacetsConfig config = Config; + FacetsConfig config = GetConfig(); for (int i = 0; i < numDocs; i++) { Document doc = new Document(); @@ -296,7 +291,7 @@ public virtual void TestDifferentNumResults() FacetsCollector sfc = new FacetsCollector(); TermQuery q = new TermQuery(A); searcher.Search(q, sfc); - Facets facets = GetTaxonomyFacetCounts(taxoReader, Config, sfc); + Facets facets = GetTaxonomyFacetCounts(taxoReader, GetConfig(), sfc); FacetResult result = facets.GetTopChildren(NUM_CHILDREN_CP_A, CP_A); Assert.AreEqual(-1, (int)result.Value); foreach (LabelAndValue labelValue in result.LabelValues) @@ -323,7 +318,7 @@ public virtual void TestAllCounts() FacetsCollector sfc = new FacetsCollector(); searcher.Search(new MatchAllDocsQuery(), sfc); - Facets facets = GetTaxonomyFacetCounts(taxoReader, Config, sfc); + Facets facets = GetTaxonomyFacetCounts(taxoReader, GetConfig(), sfc); FacetResult result = facets.GetTopChildren(NUM_CHILDREN_CP_A, CP_A); Assert.AreEqual(-1, (int)result.Value); @@ -331,7 +326,7 @@ public virtual void TestAllCounts() foreach (LabelAndValue labelValue in result.LabelValues) { Assert.AreEqual(allExpectedCounts[CP_A + "/" + labelValue.Label].GetValueOrDefault(), labelValue.Value); - Assert.True((int)labelValue.Value <= prevValue, "wrong sort order of sub results: labelValue.value=" + labelValue.Value + " prevValue=" + prevValue); + Assert.IsTrue((int)labelValue.Value <= prevValue, "wrong sort order of sub results: labelValue.value=" + labelValue.Value + " prevValue=" + prevValue); prevValue = (int)labelValue.Value; } @@ -341,7 +336,7 @@ public virtual void TestAllCounts() foreach (LabelAndValue labelValue in result.LabelValues) { Assert.AreEqual(allExpectedCounts[CP_B + "/" + labelValue.Label].GetValueOrDefault(), labelValue.Value); - Assert.True((int)labelValue.Value <= prevValue, "wrong sort order of sub results: labelValue.value=" + labelValue.Value + " prevValue=" + prevValue); + Assert.IsTrue((int)labelValue.Value <= prevValue, "wrong sort order of sub results: labelValue.value=" + labelValue.Value + " prevValue=" + prevValue); prevValue = (int)labelValue.Value; } @@ -358,7 +353,7 @@ public virtual void TestBigNumResults() FacetsCollector sfc = new FacetsCollector(); searcher.Search(new MatchAllDocsQuery(), sfc); - Facets facets = GetTaxonomyFacetCounts(taxoReader, Config, sfc); + Facets facets = GetTaxonomyFacetCounts(taxoReader, GetConfig(), sfc); FacetResult result = facets.GetTopChildren(int.MaxValue, CP_A); Assert.AreEqual(-1, (int)result.Value); @@ -386,7 +381,7 @@ public virtual void TestNoParents() var sfc = new FacetsCollector(); searcher.Search(new MatchAllDocsQuery(), sfc); - Facets facets = GetTaxonomyFacetCounts(taxoReader, Config, sfc); + Facets facets = GetTaxonomyFacetCounts(taxoReader, GetConfig(), sfc); FacetResult result = facets.GetTopChildren(NUM_CHILDREN_CP_C, CP_C); Assert.AreEqual(allExpectedCounts[CP_C].GetValueOrDefault(), result.Value); @@ -404,5 +399,4 @@ public virtual void TestNoParents() IOUtils.Dispose(indexReader, taxoReader); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs index 2f5fba1960..b8dbc71760 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetSumValueSource.cs @@ -68,7 +68,6 @@ public class TestTaxonomyFacetSumValueSource : FacetTestCase [Test] public virtual void TestBasic() { - Store.Directory dir = NewDirectory(); Store.Directory taxoDir = NewDirectory(); @@ -211,7 +210,6 @@ public virtual void TestSparseFacets() [Test] public virtual void TestWrongIndexFieldName() { - Store.Directory dir = NewDirectory(); Store.Directory taxoDir = NewDirectory(); @@ -248,7 +246,7 @@ public virtual void TestWrongIndexFieldName() // Ask for top 10 labels for any dims that have counts: IList results = facets.GetAllDims(10); - Assert.True(results.Count == 0); + Assert.IsTrue(results.Count == 0); try { @@ -394,7 +392,7 @@ private class DoubleDocValuesAnonymousInnerClassHelper : DoubleDocValues { private readonly ValueSourceAnonymousInnerClassHelper outerInstance; - private Scorer scorer; + private readonly Scorer scorer; public DoubleDocValuesAnonymousInnerClassHelper(ValueSourceAnonymousInnerClassHelper outerInstance, Scorer scorer) : base(null) //todo: value source @@ -618,5 +616,4 @@ public virtual void TestRandom() IOUtils.Dispose(w, tw, searcher.IndexReader, tr, indexDir, taxoDir); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs index eaa271a72c..456e189b80 100644 --- a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs +++ b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +using Lucene.Net.Attributes; +using NUnit.Framework; using System; using System.Collections.Generic; using System.IO; @@ -155,6 +156,7 @@ public virtual void TestL2O() /// LUCENENET specific test similar to TestL2O without any randomness, useful for debugging /// [Test] + [LuceneNetSpecific] public virtual void TestL2OBasic() { LabelToOrdinal map = new LabelToOrdinalMap(); diff --git a/src/Lucene.Net.Tests.Facet/TestDrillDownQuery.cs b/src/Lucene.Net.Tests.Facet/TestDrillDownQuery.cs index e2b5be739d..075ead5c35 100644 --- a/src/Lucene.Net.Tests.Facet/TestDrillDownQuery.cs +++ b/src/Lucene.Net.Tests.Facet/TestDrillDownQuery.cs @@ -4,7 +4,6 @@ namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -47,14 +46,12 @@ namespace Lucene.Net.Facet [TestFixture] public class TestDrillDownQuery : FacetTestCase { - private static IndexReader reader; private static DirectoryTaxonomyReader taxo; private static Directory dir; private static Directory taxoDir; private static FacetsConfig config; - [OneTimeTearDown] public override void AfterClass() // LUCENENET specific - renamed from AfterClassDrillDownQueryTest() to ensure calling order { @@ -266,10 +263,10 @@ public virtual void TestClone() var q = new DrillDownQuery(config, new MatchAllDocsQuery()); q.Add("a"); - var clone = q.Clone() as DrillDownQuery; - Assert.NotNull(clone); + var clone = (DrillDownQuery)q.Clone(); + Assert.IsNotNull(clone); clone.Add("b"); - Assert.False(q.ToString().Equals(clone.ToString(), StringComparison.Ordinal), "query wasn't cloned: source=" + q + " clone=" + clone); + Assert.IsFalse(q.ToString().Equals(clone.ToString(), StringComparison.Ordinal), "query wasn't cloned: source=" + q + " clone=" + clone); } [Test] @@ -281,5 +278,4 @@ public virtual void TestNoDrillDown() Assert.AreSame(@base, rewrite); } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs b/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs index 97be3a15ac..b67f645fc9 100644 --- a/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs +++ b/src/Lucene.Net.Tests.Facet/TestDrillSideways.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Assert = Lucene.Net.TestFramework.Assert; using Console = Lucene.Net.Util.SystemConsole; @@ -13,7 +14,6 @@ namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -31,7 +31,6 @@ namespace Lucene.Net.Facet * limitations under the License. */ - using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext; using BytesRef = Lucene.Net.Util.BytesRef; using DefaultSortedSetDocValuesReaderState = Lucene.Net.Facet.SortedSet.DefaultSortedSetDocValuesReaderState; @@ -177,7 +176,7 @@ public virtual void TestBasic() // published once: Assert.AreEqual("dim=Author path=[] value=5 childCount=4\n Lisa (2)\n Bob (1)\n Susan (1)\n Frank (1)\n", r.Facets.GetTopChildren(10, "Author").ToString()); - Assert.True(r.Facets is MultiFacets); + Assert.IsTrue(r.Facets is MultiFacets); IList allResults = r.Facets.GetAllDims(10); Assert.AreEqual(2, allResults.Count); Assert.AreEqual("dim=Author path=[] value=5 childCount=4\n Lisa (2)\n Bob (1)\n Susan (1)\n Frank (1)\n", allResults[0].ToString()); @@ -218,8 +217,8 @@ public virtual void TestBasic() ddq.Add("Foobar", "Baz"); r = ds.Search(null, ddq, 10); Assert.AreEqual(0, r.Hits.TotalHits); - Assert.Null(r.Facets.GetTopChildren(10, "Publish Date")); - Assert.Null(r.Facets.GetTopChildren(10, "Foobar")); + Assert.IsNull(r.Facets.GetTopChildren(10, "Publish Date")); + Assert.IsNull(r.Facets.GetTopChildren(10, "Foobar")); // Test drilling down on valid term or'd with invalid term: ddq = new DrillDownQuery(config); @@ -252,8 +251,8 @@ public virtual void TestBasic() r = ds.Search(null, ddq, 10); Assert.AreEqual(0, r.Hits.TotalHits); - Assert.Null(r.Facets.GetTopChildren(10, "Publish Date")); - Assert.Null(r.Facets.GetTopChildren(10, "Author")); + Assert.IsNull(r.Facets.GetTopChildren(10, "Publish Date")); + Assert.IsNull(r.Facets.GetTopChildren(10, "Author")); IOUtils.Dispose(searcher.IndexReader, taxoReader, writer, taxoWriter, dir, taxoDir); } @@ -369,7 +368,7 @@ public virtual void TestMultipleRequestsPerDim() DrillDownQuery ddq = new DrillDownQuery(config); ddq.Add("dim", "a"); - DrillSidewaysResult r = (new DrillSideways(searcher, config, taxoReader)).Search(null, ddq, 10); + DrillSidewaysResult r = new DrillSideways(searcher, config, taxoReader).Search(null, ddq, 10); Assert.AreEqual(3, r.Hits.TotalHits); Assert.AreEqual("dim=dim path=[] value=6 childCount=4\n a (3)\n b (1)\n c (1)\n d (1)\n", r.Facets.GetTopChildren(10, "dim").ToString()); @@ -442,7 +441,6 @@ private string randomContentToken(bool isQuery) [Test] public virtual void TestRandom() { - bool canUseDV = DefaultCodecSupportsSortedSet; while (aChance == 0.0) @@ -543,7 +541,7 @@ public virtual void TestRandom() Directory td = NewDirectory(); IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)); - iwc.SetInfoStream((InfoStream)InfoStream.NO_OUTPUT); + iwc.SetInfoStream(InfoStream.NO_OUTPUT); var w = new RandomIndexWriter(Random, d, iwc); var tw = new DirectoryTaxonomyWriter(td, OpenMode.CREATE); FacetsConfig config = new FacetsConfig(); @@ -664,7 +662,6 @@ public virtual void TestRandom() for (int iter = 0; iter < numIters; iter++) { - string contentToken = Random.Next(30) == 17 ? null : randomContentToken(true); int numDrillDown = TestUtil.NextInt32(Random, 1, Math.Min(4, numDims)); if (Verbose) @@ -765,7 +762,7 @@ public virtual void TestRandom() // Verify docs are always collected in order. If we // had an AssertingScorer it could catch it when // Weight.scoresDocsOutOfOrder lies!: - (new DrillSideways(s, config, tr)).Search(ddq, new CollectorAnonymousInnerClassHelper(this, s)); + new DrillSideways(s, config, tr).Search(ddq, new CollectorAnonymousInnerClassHelper(this)); // Also separately verify that DS respects the // scoreSubDocsAtOnce method, to ensure that all @@ -777,7 +774,7 @@ public virtual void TestRandom() // easily possible for one of the DD terms to be on // a future docID: new DrillSidewaysAnonymousInnerClassHelper(this, s, config, tr) - .Search(ddq, new AssertingSubDocsAtOnceCollector()); + .Search(ddq, new AssertingSubDocsAtOnceCollector()); } TestFacetResult expected = slowDrillSidewaysSearch(s, docs, contentToken, drillDowns, dimValues, filter); @@ -790,7 +787,7 @@ public virtual void TestRandom() } else { - ds = new DrillSidewaysAnonymousInnerClassHelper2(this, s, config, tr, drillDowns); + ds = new DrillSidewaysAnonymousInnerClassHelper2(this, s, config, tr); } // Retrieve all facets: @@ -850,12 +847,9 @@ private class CollectorAnonymousInnerClassHelper : ICollector { private readonly TestDrillSideways outerInstance; - private IndexSearcher s; - - public CollectorAnonymousInnerClassHelper(TestDrillSideways outerInstance, IndexSearcher s) + public CollectorAnonymousInnerClassHelper(TestDrillSideways outerInstance) { this.outerInstance = outerInstance; - this.s = s; } internal int lastDocID; @@ -882,7 +876,7 @@ private class DrillSidewaysAnonymousInnerClassHelper : DrillSideways { private readonly TestDrillSideways outerInstance; - public DrillSidewaysAnonymousInnerClassHelper(TestDrillSideways outerInstance, IndexSearcher s, Lucene.Net.Facet.FacetsConfig config, TaxonomyReader tr) + public DrillSidewaysAnonymousInnerClassHelper(TestDrillSideways outerInstance, IndexSearcher s, FacetsConfig config, TaxonomyReader tr) : base(s, config, tr) { this.outerInstance = outerInstance; @@ -895,13 +889,10 @@ private class DrillSidewaysAnonymousInnerClassHelper2 : DrillSideways { private readonly TestDrillSideways outerInstance; - private string[][] drillDowns; - - public DrillSidewaysAnonymousInnerClassHelper2(TestDrillSideways outerInstance, IndexSearcher s, Lucene.Net.Facet.FacetsConfig config, TaxonomyReader tr, string[][] drillDowns) + public DrillSidewaysAnonymousInnerClassHelper2(TestDrillSideways outerInstance, IndexSearcher s, FacetsConfig config, TaxonomyReader tr) : base(s, config, tr) { this.outerInstance = outerInstance; - this.drillDowns = drillDowns; } protected override Facets BuildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways, string[] drillSidewaysDims) @@ -924,7 +915,6 @@ protected override Facets BuildFacetsResult(FacetsCollector drillDowns, FacetsCo { return new MultiFacets(drillSidewaysFacets, drillDownFacets); } - } } @@ -1013,9 +1003,9 @@ private class InPlaceMergeSorterAnonymousInnerClassHelper : InPlaceMergeSorter { private readonly TestDrillSideways outerInstance; - private int[] counts; - private string[] values; - private int[] ids; + private readonly int[] counts; + private readonly string[] values; + private readonly int[] ids; public InPlaceMergeSorterAnonymousInnerClassHelper(TestDrillSideways outerInstance, int[] counts, string[] values, int[] ids) { @@ -1049,7 +1039,7 @@ protected override int Compare(int i, int j) else { // ... then by label ascending: - return (new BytesRef(values[ids[i]])).CompareTo(new BytesRef(values[ids[j]])); + return new BytesRef(values[ids[i]]).CompareTo(new BytesRef(values[ids[j]])); } } @@ -1078,7 +1068,7 @@ private TestFacetResult slowDrillSidewaysSearch(IndexSearcher s, IList docs { continue; } - if (onlyEven != null & (Convert.ToInt32(doc.id) & 1) != 0) + if (onlyEven != null & (Convert.ToInt32(doc.id, CultureInfo.InvariantCulture) & 1) != 0) { continue; } @@ -1195,7 +1185,7 @@ internal virtual void VerifyEquals(string[][] dimValues, IndexSearcher s, TestFa } Assert.AreEqual(expected.Hits[i].id, s.Doc(actual.Hits.ScoreDocs[i].Doc).Get("id")); // Score should be IDENTICAL: - Assert.AreEqual(scores[expected.Hits[i].id], actual.Hits.ScoreDocs[i].Score); + Assert.AreEqual(scores[expected.Hits[i].id].GetValueOrDefault(), actual.Hits.ScoreDocs[i].Score, 0.0f); } for (int dim = 0; dim < expected.Counts.Length; dim++) @@ -1289,13 +1279,13 @@ internal virtual void VerifyEquals(string[][] dimValues, IndexSearcher s, TestFa string value = dimValues[dim][i]; if (expected.Counts[dim][i] != 0) { - Assert.True(actualValues.ContainsKey(value)); + Assert.IsTrue(actualValues.ContainsKey(value)); Assert.AreEqual(expected.Counts[dim][i], (int)actualValues[value]); setCount++; } else { - Assert.False(actualValues.ContainsKey(value)); + Assert.IsFalse(actualValues.ContainsKey(value)); } } Assert.AreEqual(setCount, actualValues.Count); diff --git a/src/Lucene.Net.Tests.Facet/TestFacetsConfig.cs b/src/Lucene.Net.Tests.Facet/TestFacetsConfig.cs index 855a09bbbd..195291eb7a 100644 --- a/src/Lucene.Net.Tests.Facet/TestFacetsConfig.cs +++ b/src/Lucene.Net.Tests.Facet/TestFacetsConfig.cs @@ -4,7 +4,6 @@ namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -105,7 +104,7 @@ public virtual void TestCustomDefault() { FacetsConfig config = new FacetsConfigAnonymousInnerClassHelper(this); - Assert.True(config.GetDimConfig("foobar").IsHierarchical); + Assert.IsTrue(config.GetDimConfig("foobar").IsHierarchical); } private class FacetsConfigAnonymousInnerClassHelper : FacetsConfig @@ -128,5 +127,4 @@ protected override DimConfig DefaultDimConfig } } } - } \ No newline at end of file diff --git a/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs b/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs index 352e39b489..74b5f0e5cd 100644 --- a/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs +++ b/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs @@ -4,7 +4,6 @@ namespace Lucene.Net.Facet { - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -45,16 +44,23 @@ namespace Lucene.Net.Facet public class TestMultipleIndexFields : FacetTestCase { - private static readonly FacetField[] CATEGORIES = new FacetField[] { new FacetField("Author", "Mark Twain"), new FacetField("Author", "Stephen King"), new FacetField("Author", "Kurt Vonnegut"), new FacetField("Band", "Rock & Pop", "The Beatles"), new FacetField("Band", "Punk", "The Ramones"), new FacetField("Band", "Rock & Pop", "U2"), new FacetField("Band", "Rock & Pop", "REM"), new FacetField("Band", "Rock & Pop", "Dave Matthews Band"), new FacetField("Composer", "Bach") }; - - private FacetsConfig Config + private static readonly FacetField[] CATEGORIES = new FacetField[] { + new FacetField("Author", "Mark Twain"), + new FacetField("Author", "Stephen King"), + new FacetField("Author", "Kurt Vonnegut"), + new FacetField("Band", "Rock & Pop", "The Beatles"), + new FacetField("Band", "Punk", "The Ramones"), + new FacetField("Band", "Rock & Pop", "U2"), + new FacetField("Band", "Rock & Pop", "REM"), + new FacetField("Band", "Rock & Pop", "Dave Matthews Band"), + new FacetField("Composer", "Bach") + }; + + private FacetsConfig GetConfig() { - get - { - FacetsConfig config = new FacetsConfig(); - config.SetHierarchical("Band", true); - return config; - } + FacetsConfig config = new FacetsConfig(); + config.SetHierarchical("Band", true); + return config; } [Test] @@ -64,10 +70,11 @@ public virtual void TestDefault() Directory taxoDir = NewDirectory(); // create and open an index writer - var iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false))); + var iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer var tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE); - var config = Config; + var config = GetConfig(); seedIndex(tw, iw, config); @@ -97,11 +104,12 @@ public virtual void TestCustom() Directory taxoDir = NewDirectory(); // create and open an index writer - RandomIndexWriter iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false))); + RandomIndexWriter iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer var tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE); - FacetsConfig config = Config; + FacetsConfig config = GetConfig(); config.SetIndexFieldName("Author", "$author"); seedIndex(tw, iw, config); @@ -136,11 +144,12 @@ public virtual void TestTwoCustomsSameField() Directory taxoDir = NewDirectory(); // create and open an index writer - RandomIndexWriter iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false))); + RandomIndexWriter iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer var tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE); - FacetsConfig config = Config; + FacetsConfig config = GetConfig(); config.SetIndexFieldName("Band", "$music"); config.SetIndexFieldName("Composer", "$music"); seedIndex(tw, iw, config); @@ -192,11 +201,12 @@ public virtual void TestDifferentFieldsAndText() Directory taxoDir = NewDirectory(); // create and open an index writer - var iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false))); + var iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer var tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE); - FacetsConfig config = Config; + FacetsConfig config = GetConfig(); config.SetIndexFieldName("Band", "$bands"); config.SetIndexFieldName("Composer", "$composers"); seedIndex(tw, iw, config); @@ -233,11 +243,12 @@ public virtual void TestSomeSameSomeDifferent() Directory taxoDir = NewDirectory(); // create and open an index writer - RandomIndexWriter iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false))); + RandomIndexWriter iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer ITaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE); - FacetsConfig config = Config; + FacetsConfig config = GetConfig(); config.SetIndexFieldName("Band", "$music"); config.SetIndexFieldName("Composer", "$music"); config.SetIndexFieldName("Author", "$literature"); diff --git a/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs b/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs index 5575c312d6..bb7d8feb95 100644 --- a/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs +++ b/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs @@ -5,22 +5,6 @@ namespace Lucene.Net.Facet { - - using Directory = Lucene.Net.Store.Directory; - using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader; - using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; - using Document = Lucene.Net.Documents.Document; - using FastTaxonomyFacetCounts = Lucene.Net.Facet.Taxonomy.FastTaxonomyFacetCounts; - using IndexSearcher = Lucene.Net.Search.IndexSearcher; - using IOUtils = Lucene.Net.Util.IOUtils; - using MatchingDocs = Lucene.Net.Facet.FacetsCollector.MatchingDocs; - using MultiCollector = Lucene.Net.Search.MultiCollector; - using RandomIndexWriter = Lucene.Net.Index.RandomIndexWriter; - using Store = Lucene.Net.Documents.Field.Store; - using StringField = Lucene.Net.Documents.StringField; - using Term = Lucene.Net.Index.Term; - using TermQuery = Lucene.Net.Search.TermQuery; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -38,9 +22,23 @@ namespace Lucene.Net.Facet * limitations under the License. */ + using Directory = Lucene.Net.Store.Directory; + using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader; + using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter; + using Document = Lucene.Net.Documents.Document; + using FastTaxonomyFacetCounts = Lucene.Net.Facet.Taxonomy.FastTaxonomyFacetCounts; + using IndexSearcher = Lucene.Net.Search.IndexSearcher; + using IOUtils = Lucene.Net.Util.IOUtils; + using MatchingDocs = Lucene.Net.Facet.FacetsCollector.MatchingDocs; + using MultiCollector = Lucene.Net.Search.MultiCollector; + using RandomIndexWriter = Lucene.Net.Index.RandomIndexWriter; + using Store = Lucene.Net.Documents.Field.Store; + using StringField = Lucene.Net.Documents.StringField; + using Term = Lucene.Net.Index.Term; + using TermQuery = Lucene.Net.Search.TermQuery; + public class TestRandomSamplingFacetsCollector : FacetTestCase { - [Test] public virtual void TestRandomSampling() { @@ -52,7 +50,7 @@ public virtual void TestRandomSampling() #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif - Util.LuceneTestCase.Random, dir); + Random, dir); FacetsConfig config = new FacetsConfig(); @@ -78,7 +76,7 @@ public virtual void TestRandomSampling() searcher.Search(new TermQuery(new Term("EvenOdd", "NeverMatches")), collectRandomZeroResults); // There should be no divisions by zero and no null result - Assert.NotNull(collectRandomZeroResults.GetMatchingDocs()); + Assert.IsNotNull(collectRandomZeroResults.GetMatchingDocs()); // There should be no results at all foreach (MatchingDocs doc in collectRandomZeroResults.GetMatchingDocs()) @@ -119,9 +117,9 @@ public virtual void TestRandomSampling() // we should have five children, but there is a small chance we have less. // (see above). - Assert.True(random10Result.ChildCount <= maxNumChildren); + Assert.IsTrue(random10Result.ChildCount <= maxNumChildren); // there should be one child at least. - Assert.True(random10Result.ChildCount >= 1); + Assert.IsTrue(random10Result.ChildCount >= 1); // now calculate some statistics to determine if the sampled result is 'ok'. // because random sampling is used, the results will vary each time. @@ -146,12 +144,10 @@ public virtual void TestRandomSampling() // the average should be in the range and the standard deviation should not // be too great - Assert.True(sigma < 200); - Assert.True(targetMu - 3 * sigma < mu && mu < targetMu + 3 * sigma); + Assert.IsTrue(sigma < 200); + Assert.IsTrue(targetMu - 3 * sigma < mu && mu < targetMu + 3 * sigma); IOUtils.Dispose(searcher.IndexReader, taxoReader, dir, taxoDir); } - } - } \ No newline at end of file