Skip to content

Commit

Permalink
Lucene.Net.Tests.Facet: Fixed formatting, member ordering, assert met…
Browse files Browse the repository at this point in the history
…hod calls, marked fields readonly on anonymous classes (#259)
  • Loading branch information
NightOwl888 committed Feb 4, 2021
1 parent 26f0127 commit 9c58a07
Show file tree
Hide file tree
Showing 24 changed files with 476 additions and 436 deletions.
9 changes: 3 additions & 6 deletions src/Lucene.Net.Tests.Facet/AssertingSubDocsAtOnceCollector.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

/// <summary>
/// Verifies in collect() that all child subScorers are on
/// the collected doc.
/// </summary>
internal class AssertingSubDocsAtOnceCollector : ICollector
{

// TODO: allow wrapping another Collector

internal IList<Scorer> allScorers;
Expand Down Expand Up @@ -70,5 +68,4 @@ public virtual void SetNextReader(AtomicReaderContext context)

public virtual bool AcceptsDocsOutOfOrder => false;
}

}
21 changes: 10 additions & 11 deletions src/Lucene.Net.Tests.Facet/FacetTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -153,9 +153,9 @@ protected internal virtual void SortTies(LabelAndValue[] labelValues)
{
if (numInRow > 1)
{
Array.Sort(labelValues, i - numInRow, i - (i - numInRow), Comparer<LabelAndValue>.Create((a,b)=> {
Array.Sort(labelValues, i - numInRow, i - (i - numInRow), Comparer<LabelAndValue>.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;
Expand All @@ -170,7 +170,7 @@ protected internal virtual void SortTies(LabelAndValue[] labelValues)

protected internal virtual void SortLabelValues(List<LabelAndValue> labelValues)
{
labelValues.Sort(Comparer<LabelAndValue>.Create((a,b)=> {
labelValues.Sort(Comparer<LabelAndValue>.Create((a,b) => {
if ((double)a.Value > (double)b.Value)
{
return -1;
Expand All @@ -181,7 +181,7 @@ protected internal virtual void SortLabelValues(List<LabelAndValue> labelValues)
}
else
{
return (new BytesRef(a.Label)).CompareTo(new BytesRef(b.Label));
return new BytesRef(a.Label).CompareTo(new BytesRef(b.Label));
}
}));
}
Expand All @@ -206,14 +206,14 @@ protected internal virtual void SortFacetResults(List<FacetResult> results)
}));
}

protected internal virtual void AssertFloatValuesEquals(IList<FacetResult> a, IList<FacetResult> b)
protected virtual void AssertFloatValuesEquals(IList<FacetResult> a, IList<FacetResult> b)
{
Assert.AreEqual(a.Count, b.Count);
float lastValue = float.PositiveInfinity;
IDictionary<string, FacetResult> aByDim = new Dictionary<string, FacetResult>();
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];
}
Expand All @@ -222,7 +222,7 @@ protected internal virtual void AssertFloatValuesEquals(IList<FacetResult> 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)
Expand All @@ -231,10 +231,10 @@ protected internal virtual void AssertFloatValuesEquals(IList<FacetResult> 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);
Expand All @@ -245,5 +245,4 @@ protected internal virtual void AssertFloatValuesEquals(FacetResult a, FacetResu
}
}
}

}
Loading

0 comments on commit 9c58a07

Please sign in to comment.