Skip to content
Open

100% #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/main/java/se/cygni/palmithor/tdd/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@ public class StringUtils {


public boolean isPalindrome(final String str) {
throw new RuntimeException("Not yet implemented");
if (str == null) return false;

var maxIndex = str.length();
for (int i = 0; i < str.length(); i++) {
maxIndex--;
if (str.charAt(i) != str.charAt(maxIndex))
return false;
}
return true;

// (throw new RuntimeException("Not yet implemented");
}


/**
* Checks if a String is empty (""), null or whitespace only.
* @param str the string to check
*
* @param str the string to check
* @return true if str is null, empty or whitespace only, otherwise false
*/
public boolean isBlank(final String str) {
throw new RuntimeException("Not yet implemented");
if (str == null)
return true;
String s = str.strip();
if (s.isEmpty())
return true;
return false;
}
}
6 changes: 3 additions & 3 deletions src/test/java/se/cygni/palmithor/tdd/CalculatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class CalculatorTest {

@Test
public void test() {
assertThat(calculator.sumAll().get()).isEqualTo(1); // TODO failing on purpose please fix
assertThat(calculator.sumAll().get()).isEqualTo(0);
assertThat(calculator.sumAll(null)).isEqualTo(Optional.empty());
assertThat(calculator.sumAll(1, 2)).isEqualTo(Optional.of(3));
}


}
11 changes: 10 additions & 1 deletion src/test/java/se/cygni/palmithor/tdd/StringUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public void isPalindrome() {
*/
@Test
public void isBlank() {
// stringUtils.isBlank()
assertThat(stringUtils.isBlank(" ")).isTrue();
assertThat(stringUtils.isBlank(" ")).isTrue();
assertThat(stringUtils.isBlank(" ")).isTrue();
assertThat(stringUtils.isBlank("\r")).isTrue();
assertThat(stringUtils.isBlank("\n")).isTrue();
assertThat(stringUtils.isBlank("\t")).isTrue();
assertThat(stringUtils.isBlank("a ö")).isFalse();
assertThat(stringUtils.isBlank("g")).isFalse();
assertThat(stringUtils.isBlank(null)).isTrue();
assertThat(stringUtils.isBlank("")).isTrue();
}
}