diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs index 60b625f74a..d338ba1b28 100644 --- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs +++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs @@ -704,7 +704,7 @@ public void TestRandomNRT() Update update = new Update(); update.index = Random.nextInt(inputs.size()); update.weight = weight; - Input input = inputs.ElementAt(update.index); + Input input = inputs[update.index]; pendingUpdates.Add(update); if (VERBOSE) { @@ -735,7 +735,7 @@ public void TestRandomNRT() visibleUpto = inputs.size(); foreach (Update update in pendingUpdates) { - Input oldInput = inputs.ElementAt(update.index); + Input oldInput = inputs[update.index]; Input newInput = new Input(oldInput.term, update.weight, oldInput.payload); inputs[update.index] = newInput; } @@ -760,7 +760,7 @@ public void TestRandomNRT() visibleUpto = inputs.size(); foreach (Update update in pendingUpdates) { - Input oldInput = inputs.ElementAt(update.index); + Input oldInput = inputs[update.index]; Input newInput = new Input(oldInput.term, update.weight, oldInput.payload); inputs[update.index] = newInput; } @@ -789,7 +789,7 @@ public void TestRandomNRT() List expected = new List(); for (int i = 0; i < visibleUpto; i++) { - Input input = inputs.ElementAt(i); + Input input = inputs[i]; string[] inputTerms = Regex.Split(input.term.Utf8ToString(), "\\s", RegexOptions.Compiled).TrimEnd(); bool match = false; for (int j = 0; j < queryTerms.Length; j++) @@ -849,7 +849,7 @@ public void TestRandomNRT() expected.Sort(new TestRandomNRTComparer()); - if (expected.Any()) + if (expected.Count > 0) { int topN = TestUtil.NextInt32(Random, 1, expected.size()); @@ -863,7 +863,7 @@ public void TestRandomNRT() Console.WriteLine(" expected:"); for (int i = 0; i < expectedCount; i++) { - Input x = expected.ElementAt(i); + Input x = expected[i]; Console.WriteLine(" " + x.term.Utf8ToString() + "/" + x.v); } Console.WriteLine(" actual:"); @@ -876,9 +876,9 @@ public void TestRandomNRT() assertEquals(expectedCount, actual.size()); for (int i = 0; i < expectedCount; i++) { - assertEquals(expected.ElementAt(i).term.Utf8ToString(), actual.ElementAt(i).Key.toString()); - assertEquals(expected.ElementAt(i).v, actual.ElementAt(i).Value); - assertEquals(expected.ElementAt(i).payload, actual.ElementAt(i).Payload); + assertEquals(expected[i].term.Utf8ToString(), actual[i].Key.toString()); + assertEquals(expected[i].v, actual[i].Value); + assertEquals(expected[i].payload, actual[i].Payload); } } else @@ -966,9 +966,9 @@ public void TestBasicNRT() IList results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random).ToString(), 10, true, true); assertEquals(1, results.size()); - assertEquals("lend me your ear", results.ElementAt(0).Key); - assertEquals(8, results.ElementAt(0).Value); - assertEquals(new BytesRef("foobar"), results.ElementAt(0).Payload); + assertEquals("lend me your ear", results[0].Key); + assertEquals(8, results[0].Value); + assertEquals(new BytesRef("foobar"), results[0].Payload); // Add a new suggestion: suggester.Add(new BytesRef("a penny saved is a penny earned"), null, 10, new BytesRef("foobaz")); @@ -978,31 +978,31 @@ public void TestBasicNRT() results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random).ToString(), 10, true, true); assertEquals(2, results.size()); - assertEquals("a penny saved is a penny earned", results.ElementAt(0).Key); - assertEquals(10, results.ElementAt(0).Value); - assertEquals(new BytesRef("foobaz"), results.ElementAt(0).Payload); + assertEquals("a penny saved is a penny earned", results[0].Key); + assertEquals(10, results[0].Value); + assertEquals(new BytesRef("foobaz"), results[0].Payload); - assertEquals("lend me your ear", results.ElementAt(1).Key); - assertEquals(8, results.ElementAt(1).Value); - assertEquals(new BytesRef("foobar"), results.ElementAt(1).Payload); + assertEquals("lend me your ear", results[1].Key); + assertEquals(8, results[1].Value); + assertEquals(new BytesRef("foobar"), results[1].Payload); results = suggester.DoLookup(TestUtil.StringToCharSequence("ear ", Random).ToString(), 10, true, true); assertEquals(1, results.size()); - assertEquals("lend me your ear", results.ElementAt(0).Key); - assertEquals(8, results.ElementAt(0).Value); - assertEquals(new BytesRef("foobar"), results.ElementAt(0).Payload); + assertEquals("lend me your ear", results[0].Key); + assertEquals(8, results[0].Value); + assertEquals(new BytesRef("foobar"), results[0].Payload); results = suggester.DoLookup(TestUtil.StringToCharSequence("pen", Random).ToString(), 10, true, true); assertEquals(1, results.size()); - assertEquals("a penny saved is a penny earned", results.ElementAt(0).Key); - assertEquals(10, results.ElementAt(0).Value); - assertEquals(new BytesRef("foobaz"), results.ElementAt(0).Payload); + assertEquals("a penny saved is a penny earned", results[0].Key); + assertEquals(10, results[0].Value); + assertEquals(new BytesRef("foobaz"), results[0].Payload); results = suggester.DoLookup(TestUtil.StringToCharSequence("p", Random).ToString(), 10, true, true); assertEquals(1, results.size()); - assertEquals("a penny saved is a penny earned", results.ElementAt(0).Key); - assertEquals(10, results.ElementAt(0).Value); - assertEquals(new BytesRef("foobaz"), results.ElementAt(0).Payload); + assertEquals("a penny saved is a penny earned", results[0].Key); + assertEquals(10, results[0].Value); + assertEquals(new BytesRef("foobaz"), results[0].Payload); // Change the weight: suggester.Update(new BytesRef("lend me your ear"), null, 12, new BytesRef("foobox")); @@ -1012,12 +1012,12 @@ public void TestBasicNRT() results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random).ToString(), 10, true, true); assertEquals(2, results.size()); - assertEquals("lend me your ear", results.ElementAt(0).Key); - assertEquals(12, results.ElementAt(0).Value); - assertEquals(new BytesRef("foobox"), results.ElementAt(0).Payload); - assertEquals("a penny saved is a penny earned", results.ElementAt(1).Key); - assertEquals(10, results.ElementAt(1).Value); - assertEquals(new BytesRef("foobaz"), results.ElementAt(1).Payload); + assertEquals("lend me your ear", results[0].Key); + assertEquals(12, results[0].Value); + assertEquals(new BytesRef("foobox"), results[0].Payload); + assertEquals("a penny saved is a penny earned", results[1].Key); + assertEquals(10, results[1].Value); + assertEquals(new BytesRef("foobaz"), results[1].Payload); } } @@ -1063,7 +1063,7 @@ public void TestBasicContext() // No context provided, all results returned IList results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random).ToString(), 10, true, true); assertEquals(2, results.size()); - Lookup.LookupResult result = results.ElementAt(0); + Lookup.LookupResult result = results[0]; assertEquals("a penny saved is a penny earned", result.Key); assertEquals(10, result.Value); assertEquals(new BytesRef("foobaz"), result.Payload); @@ -1072,7 +1072,7 @@ public void TestBasicContext() assertTrue(result.Contexts.Contains(new BytesRef("foo"))); assertTrue(result.Contexts.Contains(new BytesRef("baz"))); - result = results.ElementAt(1); + result = results[1]; assertEquals("lend me your ear", result.Key); assertEquals(8, result.Value); assertEquals(new BytesRef("foobar"), result.Payload); @@ -1085,7 +1085,7 @@ public void TestBasicContext() results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random).ToString(), AsSet("foo"), 10, true, true); assertEquals(2, results.size()); - result = results.ElementAt(0); + result = results[0]; assertEquals("a penny saved is a penny earned", result.Key); assertEquals(10, result.Value); assertEquals(new BytesRef("foobaz"), result.Payload); @@ -1094,7 +1094,7 @@ public void TestBasicContext() assertTrue(result.Contexts.Contains(new BytesRef("foo"))); assertTrue(result.Contexts.Contains(new BytesRef("baz"))); - result = results.ElementAt(1); + result = results[1]; assertEquals("lend me your ear", result.Key); assertEquals(8, result.Value); assertEquals(new BytesRef("foobar"), result.Payload); @@ -1107,7 +1107,7 @@ public void TestBasicContext() results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random).ToString(), AsSet("bar"), 10, true, true); assertEquals(1, results.size()); - result = results.ElementAt(0); + result = results[0]; assertEquals("lend me your ear", result.Key); assertEquals(8, result.Value); assertEquals(new BytesRef("foobar"), result.Payload); @@ -1120,7 +1120,7 @@ public void TestBasicContext() results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random).ToString(), AsSet("baz"), 10, true, true); assertEquals(1, results.size()); - result = results.ElementAt(0); + result = results[0]; assertEquals("a penny saved is a penny earned", result.Key); assertEquals(10, result.Value); assertEquals(new BytesRef("foobaz"), result.Payload); @@ -1133,7 +1133,7 @@ public void TestBasicContext() results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random).ToString(), AsSet("foo", "bar"), 10, true, true); assertEquals(2, results.size()); - result = results.ElementAt(0); + result = results[0]; assertEquals("a penny saved is a penny earned", result.Key); assertEquals(10, result.Value); assertEquals(new BytesRef("foobaz"), result.Payload); @@ -1142,7 +1142,7 @@ public void TestBasicContext() assertTrue(result.Contexts.Contains(new BytesRef("foo"))); assertTrue(result.Contexts.Contains(new BytesRef("baz"))); - result = results.ElementAt(1); + result = results[1]; assertEquals("lend me your ear", result.Key); assertEquals(8, result.Value); assertEquals(new BytesRef("foobar"), result.Payload); diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingSuggesterTest.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingSuggesterTest.cs index 83b5324cbb..f38fea18e0 100644 --- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingSuggesterTest.cs +++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingSuggesterTest.cs @@ -56,33 +56,33 @@ public void TestKeyword() // top N of 2, but only foo is available IList results = suggester.DoLookup(TestUtil.StringToCharSequence("f", Random).ToString(), false, 2); assertEquals(1, results.size()); - assertEquals("foo", results.ElementAt(0).Key.toString()); - assertEquals(50, results.ElementAt(0).Value, 0.01F); + assertEquals("foo", results[0].Key.toString()); + assertEquals(50, results[0].Value, 0.01F); // top N of 1 for 'bar': we return this even though // barbar is higher because exactFirst is enabled: results = suggester.DoLookup(TestUtil.StringToCharSequence("bar", Random).ToString(), false, 1); assertEquals(1, results.size()); - assertEquals("bar", results.ElementAt(0).Key.toString()); - assertEquals(10, results.ElementAt(0).Value, 0.01F); + assertEquals("bar", results[0].Key.toString()); + assertEquals(10, results[0].Value, 0.01F); // top N Of 2 for 'b' results = suggester.DoLookup(TestUtil.StringToCharSequence("b", Random).ToString(), false, 2); assertEquals(2, results.size()); - assertEquals("barbar", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); - assertEquals("bar", results.ElementAt(1).Key.toString()); - assertEquals(10, results.ElementAt(1).Value, 0.01F); + assertEquals("barbar", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); + assertEquals("bar", results[1].Key.toString()); + assertEquals(10, results[1].Value, 0.01F); // top N of 3 for 'ba' results = suggester.DoLookup(TestUtil.StringToCharSequence("ba", Random).ToString(), false, 3); assertEquals(3, results.size()); - assertEquals("barbar", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); - assertEquals("bar", results.ElementAt(1).Key.toString()); - assertEquals(10, results.ElementAt(1).Value, 0.01F); - assertEquals("barbara", results.ElementAt(2).Key.toString()); - assertEquals(6, results.ElementAt(2).Value, 0.01F); + assertEquals("barbar", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); + assertEquals("bar", results[1].Key.toString()); + assertEquals(10, results[1].Value, 0.01F); + assertEquals("barbara", results[2].Key.toString()); + assertEquals(6, results[2].Value, 0.01F); } [Test] @@ -103,40 +103,40 @@ public void TestKeywordWithPayloads() // top N of 2, but only foo is available IList results = suggester.DoLookup(TestUtil.StringToCharSequence("f", Random).ToString(), false, 2); assertEquals(1, results.size()); - assertEquals("foo", results.ElementAt(0).Key.toString()); - assertEquals(50, results.ElementAt(0).Value, 0.01F); - assertEquals(new BytesRef("hello"), results.ElementAt(0).Payload); + assertEquals("foo", results[0].Key.toString()); + assertEquals(50, results[0].Value, 0.01F); + assertEquals(new BytesRef("hello"), results[0].Payload); // top N of 1 for 'bar': we return this even though // barbar is higher because exactFirst is enabled: results = suggester.DoLookup(TestUtil.StringToCharSequence("bar", Random).ToString(), false, 1); assertEquals(1, results.size()); - assertEquals("bar", results.ElementAt(0).Key.toString()); - assertEquals(10, results.ElementAt(0).Value, 0.01F); - assertEquals(new BytesRef("goodbye"), results.ElementAt(0).Payload); + assertEquals("bar", results[0].Key.toString()); + assertEquals(10, results[0].Value, 0.01F); + assertEquals(new BytesRef("goodbye"), results[0].Payload); // top N Of 2 for 'b' results = suggester.DoLookup(TestUtil.StringToCharSequence("b", Random).ToString(), false, 2); assertEquals(2, results.size()); - assertEquals("barbar", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); - assertEquals(new BytesRef("thank you"), results.ElementAt(0).Payload); - assertEquals("bar", results.ElementAt(1).Key.toString()); - assertEquals(10, results.ElementAt(1).Value, 0.01F); - assertEquals(new BytesRef("goodbye"), results.ElementAt(1).Payload); + assertEquals("barbar", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); + assertEquals(new BytesRef("thank you"), results[0].Payload); + assertEquals("bar", results[1].Key.toString()); + assertEquals(10, results[1].Value, 0.01F); + assertEquals(new BytesRef("goodbye"), results[1].Payload); // top N of 3 for 'ba' results = suggester.DoLookup(TestUtil.StringToCharSequence("ba", Random).ToString(), false, 3); assertEquals(3, results.size()); - assertEquals("barbar", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); - assertEquals(new BytesRef("thank you"), results.ElementAt(0).Payload); - assertEquals("bar", results.ElementAt(1).Key.toString()); - assertEquals(10, results.ElementAt(1).Value, 0.01F); - assertEquals(new BytesRef("goodbye"), results.ElementAt(1).Payload); - assertEquals("barbara", results.ElementAt(2).Key.toString()); - assertEquals(6, results.ElementAt(2).Value, 0.01F); - assertEquals(new BytesRef("for all the fish"), results.ElementAt(2).Payload); + assertEquals("barbar", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); + assertEquals(new BytesRef("thank you"), results[0].Payload); + assertEquals("bar", results[1].Key.toString()); + assertEquals(10, results[1].Value, 0.01F); + assertEquals(new BytesRef("goodbye"), results[1].Payload); + assertEquals("barbara", results[2].Key.toString()); + assertEquals(6, results[2].Value, 0.01F); + assertEquals(new BytesRef("for all the fish"), results[2].Payload); } } @@ -215,20 +215,20 @@ public void TestStandard() IList results = suggester.DoLookup(TestUtil.StringToCharSequence("the ghost of chris", Random).ToString(), false, 1); assertEquals(1, results.size()); - assertEquals("the ghost of christmas past", results.ElementAt(0).Key.toString()); - assertEquals(50, results.ElementAt(0).Value, 0.01F); + assertEquals("the ghost of christmas past", results[0].Key.toString()); + assertEquals(50, results[0].Value, 0.01F); // omit the 'the' since its a stopword, its suggested anyway results = suggester.DoLookup(TestUtil.StringToCharSequence("ghost of chris", Random).ToString(), false, 1); assertEquals(1, results.size()); - assertEquals("the ghost of christmas past", results.ElementAt(0).Key.toString()); - assertEquals(50, results.ElementAt(0).Value, 0.01F); + assertEquals("the ghost of christmas past", results[0].Key.toString()); + assertEquals(50, results[0].Value, 0.01F); // omit the 'the' and 'of' since they are stopwords, its suggested anyway results = suggester.DoLookup(TestUtil.StringToCharSequence("ghost chris", Random).ToString(), false, 1); assertEquals(1, results.size()); - assertEquals("the ghost of christmas past", results.ElementAt(0).Key.toString()); - assertEquals(50, results.ElementAt(0).Value, 0.01F); + assertEquals("the ghost of christmas past", results[0].Key.toString()); + assertEquals(50, results[0].Value, 0.01F); } [Test] @@ -266,7 +266,7 @@ public void TestNoSeps() // With no PRESERVE_SEPS specified, "ab c" should also // complete to "abcd", which has higher weight so should // appear first: - assertEquals("abcd", r.ElementAt(0).Key.toString()); + assertEquals("abcd", r[0].Key.toString()); } internal class TestGraphDupsTokenStreamComponents : TokenStreamComponents @@ -353,10 +353,10 @@ public void TestGraphDups() Console.WriteLine("Results: " + results); } assertEquals(2, results.size()); - assertEquals("wifi network is slow", results.ElementAt(0).Key); - assertEquals(50, results.ElementAt(0).Value); - assertEquals("wi fi network is fast", results.ElementAt(1).Key); - assertEquals(10, results.ElementAt(1).Value); + assertEquals("wifi network is slow", results[0].Key); + assertEquals(50, results[0].Value); + assertEquals("wi fi network is fast", results[1].Key); + assertEquals(10, results[1].Value); } internal class TestInputPathRequiredTokenStreamComponents : TokenStreamComponents @@ -553,23 +553,23 @@ public void TestExactFirst() assertEquals(Math.Min(topN, 4), results.size()); - assertEquals("x y", results.ElementAt(0).Key); - assertEquals(1, results.ElementAt(0).Value); + assertEquals("x y", results[0].Key); + assertEquals(1, results[0].Value); if (topN > 1) { - assertEquals("z z z", results.ElementAt(1).Key); - assertEquals(20, results.ElementAt(1).Value); + assertEquals("z z z", results[1].Key); + assertEquals(20, results[1].Value); if (topN > 2) { - assertEquals("x y z", results.ElementAt(2).Key); - assertEquals(3, results.ElementAt(2).Value); + assertEquals("x y z", results[2].Key); + assertEquals(3, results[2].Value); if (topN > 3) { - assertEquals("x", results.ElementAt(3).Key); - assertEquals(2, results.ElementAt(3).Value); + assertEquals("x", results[3].Key); + assertEquals(2, results[3].Value); } } } @@ -596,23 +596,23 @@ public void TestNonExactFirst() assertEquals(Math.Min(topN, 4), results.size()); - assertEquals("z z z", results.ElementAt(0).Key); - assertEquals(20, results.ElementAt(0).Value); + assertEquals("z z z", results[0].Key); + assertEquals(20, results[0].Value); if (topN > 1) { - assertEquals("x y z", results.ElementAt(1).Key); - assertEquals(3, results.ElementAt(1).Value); + assertEquals("x y z", results[1].Key); + assertEquals(3, results[1].Value); if (topN > 2) { - assertEquals("x", results.ElementAt(2).Key); - assertEquals(2, results.ElementAt(2).Value); + assertEquals("x", results[2].Key); + assertEquals(2, results[2].Value); if (topN > 3) { - assertEquals("x y", results.ElementAt(3).Key); - assertEquals(1, results.ElementAt(3).Value); + assertEquals("x y", results[3].Key); + assertEquals(1, results[3].Value); } } } @@ -1030,11 +1030,11 @@ public void TestRandom() for (int hit = 0; hit < r.size(); hit++) { //System.out.println(" check hit " + hit); - assertEquals(matches.ElementAt(hit).surfaceForm, r.ElementAt(hit).Key); - assertEquals(matches.ElementAt(hit).weight, r.ElementAt(hit).Value, 0f); + assertEquals(matches[hit].surfaceForm, r[hit].Key); + assertEquals(matches[hit].weight, r[hit].Value, 0f); if (doPayloads) { - assertEquals(matches.ElementAt(hit).payload, r.ElementAt(hit).Payload); + assertEquals(matches[hit].payload, r[hit].Payload); } } } @@ -1073,8 +1073,8 @@ public void TestFixed() assertEquals(1, r1.size()); - assertEquals("bar foo orange cat", r1.ElementAt(0).Key); - assertEquals(654321, r1.ElementAt(0).Value, 0f); + assertEquals("bar foo orange cat", r1[0].Key); + assertEquals(654321, r1[0].Value, 0f); // Query 2 Analyzer a2 = new MockTokenEatingAnalyzer(numStopChars, preserveHoles); @@ -1088,8 +1088,8 @@ public void TestFixed() assertEquals(1, r2.size()); - assertEquals("peter piper picked a pack of pickled peppers", r2.ElementAt(0).Key); - assertEquals(7654321, r2.ElementAt(0).Value, 0f); + assertEquals("peter piper picked a pack of pickled peppers", r2[0].Key); + assertEquals(7654321, r2[0].Value, 0f); } @@ -1103,10 +1103,10 @@ public void TestMaxSurfaceFormsPerAnalyzedForm() IList results = suggester.DoLookup("a", false, 5); assertEquals(2, results.size()); - assertEquals(" a", results.ElementAt(0).Key); - assertEquals(60, results.ElementAt(0).Value); - assertEquals("a ", results.ElementAt(1).Key); - assertEquals(50, results.ElementAt(1).Value); + assertEquals(" a", results[0].Key); + assertEquals(60, results[0].Value); + assertEquals("a ", results[1].Key); + assertEquals(50, results[1].Value); } [Test] @@ -1142,12 +1142,12 @@ public void TestExactFirstMissingResult() assertEquals(3, suggester.Count); IList results = suggester.DoLookup("a", false, 3); assertEquals(3, results.size()); - assertEquals("a", results.ElementAt(0).Key); - assertEquals(5, results.ElementAt(0).Value); - assertEquals("a c", results.ElementAt(1).Key); - assertEquals(4, results.ElementAt(1).Value); - assertEquals("a b", results.ElementAt(2).Key); - assertEquals(3, results.ElementAt(2).Value); + assertEquals("a", results[0].Key); + assertEquals(5, results[0].Value); + assertEquals("a c", results[1].Key); + assertEquals(4, results[1].Value); + assertEquals("a b", results[2].Key); + assertEquals(3, results[2].Value); // Try again after save/load: DirectoryInfo tmpDir = CreateTempDir("AnalyzingSuggesterTest"); @@ -1166,12 +1166,12 @@ public void TestExactFirstMissingResult() assertEquals(3, suggester.Count); results = suggester.DoLookup("a", false, 3); assertEquals(3, results.size()); - assertEquals("a", results.ElementAt(0).Key); - assertEquals(5, results.ElementAt(0).Value); - assertEquals("a c", results.ElementAt(1).Key); - assertEquals(4, results.ElementAt(1).Value); - assertEquals("a b", results.ElementAt(2).Key); - assertEquals(3, results.ElementAt(2).Value); + assertEquals("a", results[0].Key); + assertEquals(5, results[0].Value); + assertEquals("a c", results[1].Key); + assertEquals(4, results[1].Value); + assertEquals("a b", results[2].Key); + assertEquals(3, results[2].Value); } internal class TestDupSurfaceFormsMissingResultsTokenStreamComponents : TokenStreamComponents @@ -1227,10 +1227,10 @@ public void TestDupSurfaceFormsMissingResults() IList results = suggester.DoLookup("nellie", false, 2); assertEquals(2, results.size()); - assertEquals("hambone", results.ElementAt(0).Key); - assertEquals(6, results.ElementAt(0).Value); - assertEquals("nellie", results.ElementAt(1).Key); - assertEquals(5, results.ElementAt(1).Value); + assertEquals("hambone", results[0].Key); + assertEquals(6, results[0].Value); + assertEquals("nellie", results[1].Key); + assertEquals(5, results[1].Value); // Try again after save/load: DirectoryInfo tmpDir = CreateTempDir("AnalyzingSuggesterTest"); @@ -1248,10 +1248,10 @@ public void TestDupSurfaceFormsMissingResults() results = suggester.DoLookup("nellie", false, 2); assertEquals(2, results.size()); - assertEquals("hambone", results.ElementAt(0).Key); - assertEquals(6, results.ElementAt(0).Value); - assertEquals("nellie", results.ElementAt(1).Key); - assertEquals(5, results.ElementAt(1).Value); + assertEquals("hambone", results[0].Key); + assertEquals(6, results[0].Value); + assertEquals("nellie", results[1].Key); + assertEquals(5, results[1].Value); } internal class TestDupSurfaceFormsMissingResults2TokenStreamComponents : TokenStreamComponents { @@ -1311,10 +1311,10 @@ public void TestDupSurfaceFormsMissingResults2() IList results = suggester.DoLookup("a", false, 2); assertEquals(2, results.size()); - assertEquals("a", results.ElementAt(0).Key); - assertEquals(6, results.ElementAt(0).Value); - assertEquals("b", results.ElementAt(1).Key); - assertEquals(5, results.ElementAt(1).Value); + assertEquals("a", results[0].Key); + assertEquals(6, results[0].Value); + assertEquals("b", results[1].Key); + assertEquals(5, results[1].Value); // Try again after save/load: DirectoryInfo tmpDir = CreateTempDir("AnalyzingSuggesterTest"); @@ -1332,10 +1332,10 @@ public void TestDupSurfaceFormsMissingResults2() results = suggester.DoLookup("a", false, 2); assertEquals(2, results.size()); - assertEquals("a", results.ElementAt(0).Key); - assertEquals(6, results.ElementAt(0).Value); - assertEquals("b", results.ElementAt(1).Key); - assertEquals(5, results.ElementAt(1).Value); + assertEquals("a", results[0].Key); + assertEquals(6, results[0].Value); + assertEquals("b", results[1].Key); + assertEquals(5, results[1].Value); } internal class Test0ByteKeysTokenStreamComponents : TokenStreamComponents diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/FuzzySuggesterTest.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/FuzzySuggesterTest.cs index 06a972d668..8893e6ae87 100644 --- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/FuzzySuggesterTest.cs +++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/FuzzySuggesterTest.cs @@ -59,8 +59,8 @@ public void TestRandomEdits() string addRandomEdit = AddRandomEdit("foo bar boo", FuzzySuggester.DEFAULT_NON_FUZZY_PREFIX); IList results = suggester.DoLookup(TestUtil.StringToCharSequence(addRandomEdit, Random).ToString(), false, 2); assertEquals(addRandomEdit, 1, results.size()); - assertEquals("foo bar boo far", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); + assertEquals("foo bar boo far", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); } } @@ -84,8 +84,8 @@ public void TestNonLatinRandomEdits() string addRandomEdit = AddRandomEdit("фуу бар буу", 0); IList results = suggester.DoLookup(TestUtil.StringToCharSequence(addRandomEdit, Random).ToString(), false, 2); assertEquals(addRandomEdit, 1, results.size()); - assertEquals("фуу бар буу фар", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); + assertEquals("фуу бар буу фар", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); } } @@ -105,63 +105,63 @@ public void TestKeyword() IList results = suggester.DoLookup(TestUtil.StringToCharSequence("bariar", Random).ToString(), false, 2); assertEquals(2, results.size()); - assertEquals("barbar", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); + assertEquals("barbar", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); results = suggester.DoLookup(TestUtil.StringToCharSequence("barbr", Random).ToString(), false, 2); assertEquals(2, results.size()); - assertEquals("barbar", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); + assertEquals("barbar", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); results = suggester.DoLookup(TestUtil.StringToCharSequence("barbara", Random).ToString(), false, 2); assertEquals(2, results.size()); - assertEquals("barbara", results.ElementAt(0).Key.toString()); - assertEquals(6, results.ElementAt(0).Value, 0.01F); + assertEquals("barbara", results[0].Key.toString()); + assertEquals(6, results[0].Value, 0.01F); results = suggester.DoLookup(TestUtil.StringToCharSequence("barbar", Random).ToString(), false, 2); assertEquals(2, results.size()); - assertEquals("barbar", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); - assertEquals("barbara", results.ElementAt(1).Key.toString()); - assertEquals(6, results.ElementAt(1).Value, 0.01F); + assertEquals("barbar", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); + assertEquals("barbara", results[1].Key.toString()); + assertEquals(6, results[1].Value, 0.01F); results = suggester.DoLookup(TestUtil.StringToCharSequence("barbaa", Random).ToString(), false, 2); assertEquals(2, results.size()); - assertEquals("barbar", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); - assertEquals("barbara", results.ElementAt(1).Key.toString()); - assertEquals(6, results.ElementAt(1).Value, 0.01F); + assertEquals("barbar", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); + assertEquals("barbara", results[1].Key.toString()); + assertEquals(6, results[1].Value, 0.01F); // top N of 2, but only foo is available results = suggester.DoLookup(TestUtil.StringToCharSequence("f", Random).ToString(), false, 2); assertEquals(1, results.size()); - assertEquals("foo", results.ElementAt(0).Key.toString()); - assertEquals(50, results.ElementAt(0).Value, 0.01F); + assertEquals("foo", results[0].Key.toString()); + assertEquals(50, results[0].Value, 0.01F); // top N of 1 for 'bar': we return this even though // barbar is higher because exactFirst is enabled: results = suggester.DoLookup(TestUtil.StringToCharSequence("bar", Random).ToString(), false, 1); assertEquals(1, results.size()); - assertEquals("bar", results.ElementAt(0).Key.toString()); - assertEquals(10, results.ElementAt(0).Value, 0.01F); + assertEquals("bar", results[0].Key.toString()); + assertEquals(10, results[0].Value, 0.01F); // top N Of 2 for 'b' results = suggester.DoLookup(TestUtil.StringToCharSequence("b", Random).ToString(), false, 2); assertEquals(2, results.size()); - assertEquals("barbar", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); - assertEquals("bar", results.ElementAt(1).Key.toString()); - assertEquals(10, results.ElementAt(1).Value, 0.01F); + assertEquals("barbar", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); + assertEquals("bar", results[1].Key.toString()); + assertEquals(10, results[1].Value, 0.01F); // top N of 3 for 'ba' results = suggester.DoLookup(TestUtil.StringToCharSequence("ba", Random).ToString(), false, 3); assertEquals(3, results.size()); - assertEquals("barbar", results.ElementAt(0).Key.toString()); - assertEquals(12, results.ElementAt(0).Value, 0.01F); - assertEquals("bar", results.ElementAt(1).Key.toString()); - assertEquals(10, results.ElementAt(1).Value, 0.01F); - assertEquals("barbara", results.ElementAt(2).Key.toString()); - assertEquals(6, results.ElementAt(2).Value, 0.01F); + assertEquals("barbar", results[0].Key.toString()); + assertEquals(12, results[0].Value, 0.01F); + assertEquals("bar", results[1].Key.toString()); + assertEquals(10, results[1].Value, 0.01F); + assertEquals("barbara", results[2].Key.toString()); + assertEquals(6, results[2].Value, 0.01F); } /** @@ -181,20 +181,20 @@ public void TestStandard() IList results = suggester.DoLookup(TestUtil.StringToCharSequence("the ghost of chris", Random).ToString(), false, 1); assertEquals(1, results.size()); - assertEquals("the ghost of christmas past", results.ElementAt(0).Key.toString()); - assertEquals(50, results.ElementAt(0).Value, 0.01F); + assertEquals("the ghost of christmas past", results[0].Key.toString()); + assertEquals(50, results[0].Value, 0.01F); // omit the 'the' since its a stopword, its suggested anyway results = suggester.DoLookup(TestUtil.StringToCharSequence("ghost of chris", Random).ToString(), false, 1); assertEquals(1, results.size()); - assertEquals("the ghost of christmas past", results.ElementAt(0).Key.toString()); - assertEquals(50, results.ElementAt(0).Value, 0.01F); + assertEquals("the ghost of christmas past", results[0].Key.toString()); + assertEquals(50, results[0].Value, 0.01F); // omit the 'the' and 'of' since they are stopwords, its suggested anyway results = suggester.DoLookup(TestUtil.StringToCharSequence("ghost chris", Random).ToString(), false, 1); assertEquals(1, results.size()); - assertEquals("the ghost of christmas past", results.ElementAt(0).Key.toString()); - assertEquals(50, results.ElementAt(0).Value, 0.01F); + assertEquals("the ghost of christmas past", results[0].Key.toString()); + assertEquals(50, results[0].Value, 0.01F); } [Test] @@ -220,7 +220,7 @@ public void TestNoSeps() // With no PRESERVE_SEPS specified, "ab c" should also // complete to "abcd", which has higher weight so should // appear first: - assertEquals("abcd", r.ElementAt(0).Key.toString()); + assertEquals("abcd", r[0].Key.toString()); } internal class TestGraphDupsTokenStreamComponents : TokenStreamComponents { @@ -304,10 +304,10 @@ public void TestGraphDups() Console.WriteLine("Results: " + results); } assertEquals(2, results.size()); - assertEquals("wifi network is slow", results.ElementAt(0).Key); - assertEquals(50, results.ElementAt(0).Value); - assertEquals("wi fi network is fast", results.ElementAt(1).Key); - assertEquals(10, results.ElementAt(1).Value); + assertEquals("wifi network is slow", results[0].Key); + assertEquals(50, results[0].Value); + assertEquals("wi fi network is fast", results[1].Key); + assertEquals(10, results[1].Value); } [Test] @@ -508,23 +508,23 @@ public void TestExactFirst() assertEquals(Math.Min(topN, 4), results.size()); - assertEquals("x y", results.ElementAt(0).Key); - assertEquals(1, results.ElementAt(0).Value); + assertEquals("x y", results[0].Key); + assertEquals(1, results[0].Value); if (topN > 1) { - assertEquals("z z z", results.ElementAt(1).Key); - assertEquals(20, results.ElementAt(1).Value); + assertEquals("z z z", results[1].Key); + assertEquals(20, results[1].Value); if (topN > 2) { - assertEquals("x y z", results.ElementAt(2).Key); - assertEquals(3, results.ElementAt(2).Value); + assertEquals("x y z", results[2].Key); + assertEquals(3, results[2].Value); if (topN > 3) { - assertEquals("x", results.ElementAt(3).Key); - assertEquals(2, results.ElementAt(3).Value); + assertEquals("x", results[3].Key); + assertEquals(2, results[3].Value); } } } @@ -551,23 +551,23 @@ public void TestNonExactFirst() assertEquals(Math.Min(topN, 4), results.size()); - assertEquals("z z z", results.ElementAt(0).Key); - assertEquals(20, results.ElementAt(0).Value); + assertEquals("z z z", results[0].Key); + assertEquals(20, results[0].Value); if (topN > 1) { - assertEquals("x y z", results.ElementAt(1).Key); - assertEquals(3, results.ElementAt(1).Value); + assertEquals("x y z", results[1].Key); + assertEquals(3, results[1].Value); if (topN > 2) { - assertEquals("x", results.ElementAt(2).Key); - assertEquals(2, results.ElementAt(2).Value); + assertEquals("x", results[2].Key); + assertEquals(2, results[2].Value); if (topN > 3) { - assertEquals("x y", results.ElementAt(3).Key); - assertEquals(1, results.ElementAt(3).Value); + assertEquals("x y", results[3].Key); + assertEquals(1, results[3].Value); } } } @@ -977,8 +977,8 @@ public void TestRandom() for (int hit = 0; hit < r.size(); hit++) { //Console.WriteLine(" check hit " + hit); - assertEquals(prefix + " " + topN, matches.ElementAt(hit).Key.toString(), r.ElementAt(hit).Key.toString()); - assertEquals(matches.ElementAt(hit).Value, r.ElementAt(hit).Value, 0f); + assertEquals(prefix + " " + topN, matches[hit].Key.toString(), r[hit].Key.toString()); + assertEquals(matches[hit].Value, r[hit].Value, 0f); } } } @@ -1189,8 +1189,8 @@ public void TestRandom2() int limit = Math.Min(expected.size(), actual.size()); for (int ans = 0; ans < limit; ans++) { - Lookup.LookupResult c0 = expected.ElementAt(ans); - Lookup.LookupResult c1 = actual.ElementAt(ans); + Lookup.LookupResult c0 = expected[ans]; + Lookup.LookupResult c1 = actual[ans]; assertEquals("expected " + c0.Key + " but got " + c1.Key, 0,