Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review of Lucene.Net.Tests.Facet (See #259) #411

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}
}
}

}