/
NikolayIvkin
/
TheAlgorithms
Обзор
Документация
Войти
/
NikolayIvkin
/
TheAlgorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/test/java/com/thealgorithms/strings/LongestCommonPrefixTest.java
73 строки
2 KB
Ramit Gangwar (NoiR)
Add LongestCommonPrefix (#5849)
26 окт 2024, 22:01
Не верифицирован
26 окт 2024, 22:01
3da16a7
Код
Авторство
О чём код?
package com.thealgorithms.strings; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; public class LongestCommonPrefixTest { private final LongestCommonPrefix longestCommonPrefix = new LongestCommonPrefix(); @Test public void testCommonPrefix() { String[] input = {"flower", "flow", "flight"}; String expected = "fl"; assertEquals(expected, longestCommonPrefix.longestCommonPrefix(input)); } @Test public void testNoCommonPrefix() { String[] input = {"dog", "racecar", "car"}; String expected = ""; assertEquals(expected, longestCommonPrefix.longestCommonPrefix(input)); } @Test public void testEmptyArray() { String[] input = {}; String expected = ""; assertEquals(expected, longestCommonPrefix.longestCommonPrefix(input)); } @Test public void testNullArray() { String[] input = null; String expected = ""; assertEquals(expected, longestCommonPrefix.longestCommonPrefix(input)); } @Test public void testSingleString() { String[] input = {"single"}; String expected = "single"; assertEquals(expected, longestCommonPrefix.longestCommonPrefix(input)); } @Test public void testCommonPrefixWithDifferentLengths() { String[] input = {"ab", "a"}; String expected = "a"; assertEquals(expected, longestCommonPrefix.longestCommonPrefix(input)); } @Test public void testAllSameStrings() { String[] input = {"test", "test", "test"}; String expected = "test"; assertEquals(expected, longestCommonPrefix.longestCommonPrefix(input)); } @Test public void testPrefixAtEnd() { String[] input = {"abcde", "abcfgh", "abcmnop"}; String expected = "abc"; assertEquals(expected, longestCommonPrefix.longestCommonPrefix(input)); } @Test public void testMixedCase() { String[] input = {"Flower", "flow", "flight"}; String expected = ""; assertEquals(expected, longestCommonPrefix.longestCommonPrefix(input)); } }