mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
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:
commit
9b8d8e9b7c
4 changed files with 108 additions and 9 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue