From 561f9ea23c025086959e82d1682e6edd7a0ee384 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Sat, 16 Mar 2019 17:51:23 +0000 Subject: [PATCH] Add more tests to StringSortingUtils (#2622) * Add more tests to StringSortingUtils * Add test with empty strings to improve coverage --- .../commons/utils/StringSortingUtilsTest.kt | 94 ++++++++++++++++++- 1 file changed, 90 insertions(+), 4 deletions(-) diff --git a/app/src/test/kotlin/fr/free/nrw/commons/utils/StringSortingUtilsTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/utils/StringSortingUtilsTest.kt index 83e2f7169..a26c0e325 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/utils/StringSortingUtilsTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/utils/StringSortingUtilsTest.kt @@ -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) + } } \ No newline at end of file