Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java tdd #9

Open
wants to merge 3 commits into
base: java-tdd
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ The implementation part should be done in this order:
1. Implement `StringUtils.isPalindrome(final String str)`
2. Implement the tests for `Calculator.sumAll(final Integer... valuesPram)`
3. Implement both the tests and the functionality for `StringUtils.isBlank(final String str)`
hej
9 changes: 7 additions & 2 deletions src/main/java/se/cygni/palmithor/tdd/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ public class StringUtils {


public boolean isPalindrome(final String str) {
throw new RuntimeException("Not yet implemented");
if (str == null) {
return false;
}
StringBuilder sb = new StringBuilder(str).reverse();
var sbStr = sb.toString();
return sbStr.equals(str);
}


Expand All @@ -15,6 +20,6 @@ public boolean isPalindrome(final String str) {
* @return true if str is null, empty or whitespace only, otherwise false
*/
public boolean isBlank(final String str) {
throw new RuntimeException("Not yet implemented");
return str == null || str.equals("") || str.replace(" ", "").isEmpty();
}
}
10 changes: 8 additions & 2 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,14 @@ 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); // TODO failing on purpose please fix
assertThat(calculator.sumAll(1)).isEqualTo(Optional.of(1));
assertThat(calculator.sumAll(0, 0)).isEqualTo(Optional.of(0));
assertThat(calculator.sumAll(1, 1)).isEqualTo(Optional.of(2));
assertThat(calculator.sumAll(-1, 1)).isEqualTo(Optional.of(0));
assertThat(calculator.sumAll(-1, -1)).isEqualTo(Optional.of(-2));
assertThat(calculator.sumAll(null)).isEqualTo(Optional.empty());
}


}
}
6 changes: 5 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,10 @@ public void isPalindrome() {
*/
@Test
public void isBlank() {
// stringUtils.isBlank()
assertThat(stringUtils.isBlank("")).isTrue();
assertThat(stringUtils.isBlank("asd")).isFalse();
assertThat(stringUtils.isBlank(null)).isTrue();
assertThat(stringUtils.isBlank(" ")).isTrue();

}
}