mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +01:00
Implementing String similarity algorithm for searching category functionality
This commit is contained in:
parent
d4a89afafd
commit
5094cbc58a
4 changed files with 85 additions and 0 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("tes"));
|
||||
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