Update ui tests & search fixing #8647

This commit is contained in:
Victor Shcherb 2020-05-24 15:55:14 +02:00
parent f54e7c8cb1
commit 5d344acf17
4 changed files with 66 additions and 57 deletions

View file

@ -851,8 +851,8 @@ public class SearchUICore {
private enum ResultCompareStep { private enum ResultCompareStep {
TOP_VISIBLE, TOP_VISIBLE,
UNKNOWN_PHRASE_MATCH_WEIGHT,
FOUND_WORD_COUNT, FOUND_WORD_COUNT,
UNKNOWN_PHRASE_MATCH_WEIGHT,
SEARCH_DISTANCE_IF_NOT_BY_NAME, SEARCH_DISTANCE_IF_NOT_BY_NAME,
COMPARE_FIRST_NUMBER_IN_NAME, COMPARE_FIRST_NUMBER_IN_NAME,
COMPARE_DISTANCE_TO_PARENT_SEARCH_RESULT, // makes sense only for inner subqueries COMPARE_DISTANCE_TO_PARENT_SEARCH_RESULT, // makes sense only for inner subqueries

View file

@ -1,10 +1,7 @@
package net.osmand.search; package net.osmand.search;
import java.io.File; import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -22,9 +19,6 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.osmand.OsmAndCollator; import net.osmand.OsmAndCollator;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
@ -35,8 +29,6 @@ import net.osmand.data.MapObject;
import net.osmand.data.Street; import net.osmand.data.Street;
import net.osmand.osm.AbstractPoiType; import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapPoiTypes;
import net.osmand.router.RouteTestingTest;
import net.osmand.router.TestEntry;
import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.SearchUICore.SearchResultCollection;
import net.osmand.search.SearchUICore.SearchResultMatcher; import net.osmand.search.SearchUICore.SearchResultMatcher;
import net.osmand.search.core.SearchPhrase; import net.osmand.search.core.SearchPhrase;
@ -48,6 +40,7 @@ import net.osmand.util.Algorithms;
public class SearchUICoreTest { public class SearchUICoreTest {
private static final String SEARCH_RESOURCES_PATH = "src/test/resources/search/"; private static final String SEARCH_RESOURCES_PATH = "src/test/resources/search/";
private static boolean TEST_EXTRA_RESULTS = true;
private File testFile; private File testFile;
@ -98,7 +91,7 @@ public class SearchUICoreTest {
} }
@Test @Test
public void testSearchImpl() throws IOException, JSONException { public void testSearch() throws IOException, JSONException {
File jsonFile = testFile; File jsonFile = testFile;
String sourceJsonText = Algorithms.getFileAsString(jsonFile); String sourceJsonText = Algorithms.getFileAsString(jsonFile);
Assert.assertNotNull(sourceJsonText); Assert.assertNotNull(sourceJsonText);
@ -149,6 +142,12 @@ public class SearchUICoreTest {
results.add(resultsArr.getString(i)); results.add(resultsArr.getString(i));
} }
} }
if (TEST_EXTRA_RESULTS && sourceJson.has("extra-results")) {
JSONArray resultsArr = sourceJson.getJSONArray("extra-results");
for (int i = 0; i < resultsArr.length(); i++) {
results.add(resultsArr.getString(i));
}
}
SearchSettings s = SearchSettings.parseJSON(settingsJson); SearchSettings s = SearchSettings.parseJSON(settingsJson);
s.setOfflineIndexes(Collections.singletonList(reader)); s.setOfflineIndexes(Collections.singletonList(reader));
@ -181,6 +180,12 @@ public class SearchUICoreTest {
String expected = results.get(i++); String expected = results.get(i++);
String present = result.toString(); String present = result.toString();
//System.out.println(present); //System.out.println(present);
if(!Algorithms.stringsEqual(expected, present)) {
System.out.println(String.format("Mismatch for '%s' != '%s'. Result: ", expected, present));
for (SearchResult r : searchResults) {
System.out.println("\t\""+r.toString()+"\",");
}
}
Assert.assertEquals(expected, present); Assert.assertEquals(expected, present);
if (i >= results.size()) { if (i >= results.size()) {
break; break;

View file

@ -12,17 +12,20 @@
"phrase": "48 Free Street Portland", "phrase": "48 Free Street Portland",
"results": [ "results": [
"48.0, <input> ", "48.0, <input> ",
"48, Free Street (Downtown), Portland", "48, Free Street (Downtown), Portland"],
"48, Portland Street, North Berwick", "extra-results": [
"48, Portland Avenue, Old Orchard Beach", "48, Portland Street, North Berwick",
"Portland Street (Downtown), Portland", "Free Street (Downtown), Portland",
"Portland Street Pier, South Portland", "Free Street (Ferry Village), South Portland",
"Portland Street, Yarmouth", "Portland Street",
"Portland Street, North Berwick", "48, Portland Avenue, Old Orchard Beach",
"Portland Street, Berwick", "Portland Street (Downtown), Portland",
"Portland Street, South Berwick", "Portland Street Pier, South Portland",
"Portland Street, Fryeburg", "Portland Street, Yarmouth",
"Portland Square, Portland" "Portland Street, North Berwick",
"Portland Street, Berwick",
"Portland Street, South Berwick",
"Portland Street, Fryeburg"
], ],
"amenities": [ "amenities": [
{ {

View file

@ -10,43 +10,44 @@
"sortByName": false "sortByName": false
}, },
"phrase": "Calle de las eras 5, Navacerrada", "phrase": "Calle de las eras 5, Navacerrada",
"results": [ "results": [
"5, Calle de las Eras (Uranización Los Corales), Navacerrada", "5, Calle de las Eras (Uranización Los Corales), Navacerrada"
"5, Calle Navacerrada (Urb. Las Suertes), Las Suertes", ],
"50, Calle de Francisco Navacerrada, Salamanca", "extra-results": [
"52, Calle de Francisco Navacerrada, Salamanca", "Calle de las Eras (Uranización Los Corales), Pasaje de las Eras (Uranización Los Corales), Navacerrada",
"53, Calle de Francisco Navacerrada, Salamanca", "Calle del Sotillo (Uranización Los Corales), Pasaje de las Eras (Uranización Los Corales), Navacerrada",
"54, Calle de Francisco Navacerrada, Salamanca", "5, Calle Navacerrada (Urb. Las Suertes), Las Suertes",
"55, Calle de Francisco Navacerrada, Salamanca", "50, Calle de Francisco Navacerrada, Salamanca",
"56, Calle de Francisco Navacerrada, Salamanca", "52, Calle de Francisco Navacerrada, Salamanca",
"57, Calle de Francisco Navacerrada, Salamanca", "53, Calle de Francisco Navacerrada, Salamanca",
"58, Calle de Francisco Navacerrada, Salamanca", "54, Calle de Francisco Navacerrada, Salamanca",
"59, Calle de Francisco Navacerrada, Salamanca", "55, Calle de Francisco Navacerrada, Salamanca",
"Calle del Puerto de Navacerrada, Las Nieves", "56, Calle de Francisco Navacerrada, Salamanca",
"Calle Puerto de Navacerrada, La Poveda", "57, Calle de Francisco Navacerrada, Salamanca",
"Calle del Embalse de Navacerrada, Villa de Vallecas", "58, Calle de Francisco Navacerrada, Salamanca",
"Calle del Puerto de Navacerrada, Puente de Vallecas", "59, Calle de Francisco Navacerrada, Salamanca",
"Calle de Francisco Navacerrada, Salamanca", "Calle del Puerto de Navacerrada, Las Nieves",
"Calle de Navacerrada, Moraleja de Enmedio", "Pasaje de las Eras (Uranización Los Corales), Navacerrada",
"Calle Navacerrada (Urb. Las Suertes), Las Suertes", "Calle Barrio de las Peñas, Navacerrada",
"Calle Puerto de Navacerrada, Roman Candelas", "Calle de las Cruces (Residencial Sanabria), Navacerrada",
"Calle Navacerrada, Becerril de la Sierra", "Calle de las Escuelas, Navacerrada",
"Carretera de Collado Villalba a Navacerrada, El Baillo y las Hojarascas", "Calle de las Huertas (Residencial Sanabria), Navacerrada",
"Calle Navacerrada (Cerceda), El Boalo", "Calle de la Virgen de las Nieves, Puerto de Navacerrada",
"Calle Navacerrada (El Pedregal), Bustarviejo", "Calle Puerto de Navacerrada, La Poveda",
"Calle Navacerrada, Buitrago del Lozoya", "Calle del Embalse de Navacerrada, Villa de Vallecas",
"Carretera de Colmenar Viejo a Navacerrada, Becerril de la Sierra", "Calle del Puerto de Navacerrada, Puente de Vallecas",
"Carretera de Colmenar Viejo a Navacerrada, Manzanares el Real", "Calle de Francisco Navacerrada, Salamanca",
"Carretera de Collado Villalba a Navacerrada, Dehesa Boyal", "Calle de Navacerrada, Moraleja de Enmedio",
"Carretera de Collado Villalba a Navacerrada, Polideportivo Dehesa Boyal", "Calle Navacerrada (Urb. Las Suertes), Las Suertes",
"Carretera de Navacerrada, Jazmines", "Calle Puerto de Navacerrada, Roman Candelas",
"Carretera de Colmenar Viejo a Navacerrada (Cerceda), El Boalo", "Calle Navacerrada, Becerril de la Sierra",
"Carretera de Collado Villalba a Navacerrada, Cerca de Cascarrilla", "Carretera de Collado Villalba a Navacerrada, El Baillo y las Hojarascas",
"Carretera de Navacerrada, El Boalo", "Calle de Ángel Rojas, Navacerrada",
"Carretera de Collado Villalba a Navacerrada, Collado Mediano", "Calle de los Robles (Uranización Los Corales), Navacerrada",
"Camino de Navacerrada (Serranía de la Paloma), Collado Mediano", "Calle de los Enebros (Uranización Los Corales), Navacerrada",
"Camino de Los Molinos a Navacerrada, Collado Mediano", "Calle de la Bola del Mundo (Residencial Sanabria), Navacerrada",
"Carretera de Collado Villalba a Navacerrada, Navacerrada" "Calle de la Maliciosa (Residencial Sanabria), Navacerrada",
], ],
"amenities": [ "amenities": [
{ {