diff --git a/.gradle/7.1/executionHistory/executionHistory.bin b/.gradle/7.1/executionHistory/executionHistory.bin index 58ac806..3d1e8c6 100644 Binary files a/.gradle/7.1/executionHistory/executionHistory.bin and b/.gradle/7.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.1/executionHistory/executionHistory.lock b/.gradle/7.1/executionHistory/executionHistory.lock index a18228b..e13278c 100644 Binary files a/.gradle/7.1/executionHistory/executionHistory.lock and b/.gradle/7.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.1/fileHashes/fileHashes.bin b/.gradle/7.1/fileHashes/fileHashes.bin index debe535..c7a1c51 100644 Binary files a/.gradle/7.1/fileHashes/fileHashes.bin and b/.gradle/7.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.1/fileHashes/fileHashes.lock b/.gradle/7.1/fileHashes/fileHashes.lock index aab4d00..4ee50ad 100644 Binary files a/.gradle/7.1/fileHashes/fileHashes.lock and b/.gradle/7.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 308155d..552869f 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/main/kotlin/other/PalindromeAdvanced.kt b/src/main/kotlin/other/PalindromeAdvanced.kt new file mode 100644 index 0000000..7a72ee5 --- /dev/null +++ b/src/main/kotlin/other/PalindromeAdvanced.kt @@ -0,0 +1,34 @@ +package other + +/** + * Algorithm for checking a string for a palindrome + * + */ + +class PalindromeAdvanced(private val text: String) { + + /** + * checks a string for a palindrome + * + * @return returns true if the string is a palindrome + */ + fun isYes() : Boolean { + if (text.length <= 1) { + return true + } + for (i in 0 until text.length / 2) { + if (text[i] != text[text.length - 1 - i]) { + return false + } + } + return true + } + + /** + * checks if a string is not a palindrome + * + * @return returns true if the string is not a palindrome + */ + fun isNot() = !isYes() + +} \ No newline at end of file diff --git a/src/test/kotlin/other/PalindromeAdvancedTest.kt b/src/test/kotlin/other/PalindromeAdvancedTest.kt new file mode 100644 index 0000000..5181be1 --- /dev/null +++ b/src/test/kotlin/other/PalindromeAdvancedTest.kt @@ -0,0 +1,40 @@ +package other + +import org.junit.Test +import org.junit.jupiter.api.Assertions.* + +class PalindromeAdvancedTest { + + @Test + fun test_empty_string() { + val text1 = "" + assertEquals(PalindromeAdvanced(text1).isYes(), true) + } + + @Test + fun test_one_length() { + val text1 = "a" + assertEquals(PalindromeAdvanced(text1).isYes(), true) + } + + @Test + fun test_is_palindrome() { + val text1 = "tenet" + assertEquals(PalindromeAdvanced(text1).isYes(), true) + + val text2 = "friend" + assertEquals(PalindromeAdvanced(text2).isYes(), false) + } + + @Test + fun test_is_not_palindrome() { + val text1 = "white" + assertEquals(PalindromeAdvanced(text1).isNot(), true) + + val text2 = "tenet" + assertEquals(PalindromeAdvanced(text2).isNot(), false) + } + +} + + diff --git a/src/test/kotlin/other/PalindromeTest.kt b/src/test/kotlin/other/PalindromeTest.kt index ad692a2..e89c85c 100644 --- a/src/test/kotlin/other/PalindromeTest.kt +++ b/src/test/kotlin/other/PalindromeTest.kt @@ -1,10 +1,23 @@ package other import org.junit.Test +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.* internal class PalindromeTest { + @Test + fun test_empty_string() { + val text1 = "" + assertEquals(Palindrome(text1).isYes(), true) + } + + @Test + fun test_one_length() { + val text1 = "a" + assertEquals(Palindrome(text1).isYes(), true) + } + @Test fun test_is_palindrome() { val text1 = "tenet"