Beschreibe hier die neue Seite. |
Der im RefactoringBeispiel verwendete Algorithmus bedarf einiger UnitTests, um ihn zu refaktorisieren. Dieser Algorithmus ist zwar relativ klein, jedoch: sicher ist sicher. Folgender Codeabschnitt zeigt 4 Tests, anhand derer ein unbeschwerteres Refactoring möglich sein sollte: [[Code] public void testEmptyString() { assertEqualsLongestRepeatingSubstring("", ""); assertEqualsLongestRepeatingSubstring("", " "); assertEqualsLongestRepeatingSubstring(" ", " "); assertEqualsLongestRepeatingSubstring(" ", " "); } public void testOneRepetition() { assertEqualsLongestRepeatingSubstring("", "a"); assertEqualsLongestRepeatingSubstring("a", "aa"); assertEqualsLongestRepeatingSubstring("a", "aba"); assertEqualsLongestRepeatingSubstring("a", "abba"); assertEqualsLongestRepeatingSubstring("a", "aab"); assertEqualsLongestRepeatingSubstring("a", "baa"); assertEqualsLongestRepeatingSubstring("a", "baab"); } public void testNumerouslyRepetition(){ assertEqualsLongestRepeatingSubstring("aa", "aaa"); assertEqualsLongestRepeatingSubstring("ab", "abab"); assertEqualsLongestRepeatingSubstring("abab", "ababab"); assertEqualsLongestRepeatingSubstring("aa", "aaabbb"); assertEqualsLongestRepeatingSubstring("aa", "bbbaaa"); } public void testConcretExample() { assertEqualsLongestRepeatingSubstring("issi", "Mississippi"); } private void assertEqualsLongestRepeatingSubstring(String expected, String actual){ assertEquals(expected, RefactoringBeispiel2?.longestRepeatingSubstring(actual)); } ] -- BerndSchiffer |
|