Merge pull request #867 from pszklarska/fix_844

Fixing #844 - If a category has exact name entered, show it first
This commit is contained in:
Nicolas Raoul 2017-10-02 16:32:46 +09:00 committed by GitHub
commit 9b8d8e9b7c
4 changed files with 108 additions and 9 deletions

View file

@ -0,0 +1,40 @@
package fr.free.nrw.commons.utils;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
public class StringSortingUtilsTest {
@Test
public void testSortingNumbersBySimilarity() throws Exception {
List<String> actualList = Arrays.asList("1234567", "4567", "12345", "123", "1234");
List<String> expectedList = Arrays.asList("1234", "12345", "123", "1234567", "4567");
Collections.sort(actualList, StringSortingUtils.sortBySimilarity("1234"));
Assert.assertEquals(expectedList, actualList);
}
@Test
public void testSortingTextBySimilarity() throws Exception {
List<String> actualList = Arrays.asList("The quick brown fox",
"quick brown fox",
"The",
"The quick ",
"The fox",
"brown fox",
"fox");
List<String> expectedList = Arrays.asList("The",
"The fox",
"The quick ",
"The quick brown fox",
"quick brown fox",
"brown fox",
"fox");
Collections.sort(actualList, StringSortingUtils.sortBySimilarity("The"));
Assert.assertEquals(expectedList, actualList);
}
}