mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Add more tests to StringSortingUtils (#2622)
* Add more tests to StringSortingUtils * Add test with empty strings to improve coverage
This commit is contained in:
parent
deb0a9874c
commit
561f9ea23c
1 changed files with 90 additions and 4 deletions
|
|
@ -19,23 +19,109 @@ class StringSortingUtilsTest {
|
|||
|
||||
@Test
|
||||
fun testSortingTextBySimilarity() {
|
||||
val actualList = listOf("The quick brown fox",
|
||||
val actualList = listOf(
|
||||
"The quick brown fox",
|
||||
"quick brown fox",
|
||||
"The",
|
||||
"The quick ",
|
||||
"The fox",
|
||||
"brown fox",
|
||||
"fox")
|
||||
val expectedList = listOf("The",
|
||||
"fox"
|
||||
)
|
||||
val expectedList = listOf(
|
||||
"The",
|
||||
"The fox",
|
||||
"The quick ",
|
||||
"The quick brown fox",
|
||||
"quick brown fox",
|
||||
"brown fox",
|
||||
"fox")
|
||||
"fox"
|
||||
)
|
||||
|
||||
sort(actualList, sortBySimilarity("The"))
|
||||
|
||||
assertEquals(expectedList, actualList)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSortingSymbolsBySimilarity() {
|
||||
val actualList = listOf(
|
||||
"$$$$$",
|
||||
"****",
|
||||
"**$*",
|
||||
"*$*$",
|
||||
".*$"
|
||||
)
|
||||
val expectedList = listOf(
|
||||
"**$*",
|
||||
"*$*$",
|
||||
".*$",
|
||||
"****",
|
||||
"$$$$$"
|
||||
)
|
||||
|
||||
sort(actualList, sortBySimilarity("**$"))
|
||||
|
||||
assertEquals(expectedList, actualList)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSortingMixedStringsBySimilarity() {
|
||||
// Sample from Category:2018 Android phones
|
||||
val actualList = listOf(
|
||||
"ASUS ZenFone 5 (2018)",
|
||||
"Google Pixel 3",
|
||||
"HTC U12",
|
||||
"Huawei P20",
|
||||
"LG G7 ThinQ",
|
||||
"Samsung Galaxy A8 (2018)",
|
||||
"Samsung Galaxy S9",
|
||||
// One with more complicated symbols
|
||||
"MadeUpPhone 2018.$£#你好"
|
||||
)
|
||||
val expectedList = listOf(
|
||||
"Samsung Galaxy S9",
|
||||
"ASUS ZenFone 5 (2018)",
|
||||
"Samsung Galaxy A8 (2018)",
|
||||
"Google Pixel 3",
|
||||
"HTC U12",
|
||||
"Huawei P20",
|
||||
"LG G7 ThinQ",
|
||||
"MadeUpPhone 2018.$£#你好"
|
||||
)
|
||||
|
||||
sort(actualList, sortBySimilarity("S9"))
|
||||
|
||||
assertEquals(expectedList, actualList)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSortingWithEmptyStrings() {
|
||||
val actualList = listOf(
|
||||
"brown fox",
|
||||
"",
|
||||
"quick brown fox",
|
||||
"the",
|
||||
"",
|
||||
"the fox",
|
||||
"fox",
|
||||
"",
|
||||
""
|
||||
)
|
||||
val expectedList = listOf(
|
||||
"the fox",
|
||||
"brown fox",
|
||||
"the",
|
||||
"fox",
|
||||
"quick brown fox",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
""
|
||||
)
|
||||
|
||||
sort(actualList, sortBySimilarity("the fox"))
|
||||
|
||||
assertEquals(expectedList, actualList)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue