Skip to content
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
25 changes: 23 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,28 @@ public class StringUtils {


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

String strCopy = new StringBuilder(str).reverse().toString();

if(strCopy.equalsIgnoreCase(str))
return true;
return false;
/*


boolean result = false;

if (str == null) {
result = false;
}

if (str.equals("")) result = false;

return result;*/
}


Expand All @@ -15,6 +36,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.isEmpty() || str.equals("") || str.trim().isEmpty();
}
}
53 changes: 51 additions & 2 deletions src/test/java/se/cygni/palmithor/tdd/CalculatorTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package se.cygni.palmithor.tdd;


import org.junit.Ignore;
import org.junit.Test;

import java.util.Optional;
Expand All @@ -12,9 +13,57 @@ public class CalculatorTest {
private Calculator calculator = new Calculator();

@Test
public void test() {
assertThat(calculator.sumAll().get()).isEqualTo(1); // TODO failing on purpose please fix
public void testEmptyParamList() {

assertThat(calculator.sumAll().get()).isEqualTo(0); // TODO failing on purpose please fix

}

@Test
public void testNullParamList() {

assertThat(calculator.sumAll(null)).isEqualTo(Optional.empty()); // TODO failing on purpose please fix

}

@Test
public void testParamListWithOneParam() {

assertThat(calculator.sumAll(5).get()).isEqualTo(5); // TODO failing on purpose please fix

}

@Test
public void testParamListWithThreeParams() {

assertThat(calculator.sumAll(5, 1, 2).get()).isEqualTo(8); // TODO failing on purpose please fix

}

@Test
public void testParamListWithNegativeParam() {

assertThat(calculator.sumAll(-5, -1, 3).get()).isEqualTo(-3); // TODO failing on purpose please fix

}

@Test
public void testParamListWithIntegerParam() {

assertThat(calculator.sumAll(Integer.parseInt("5")).get()).isEqualTo(5); // TODO failing on purpose please fix

}
@Test
public void testParamListWithMaxIntParam() {

assertThat(calculator.sumAll(Integer.MAX_VALUE).get()).isEqualTo(Integer.MAX_VALUE); // TODO failing on purpose please fix
}

@Test
@Ignore
public void testParamListWithParam() {

assertThat(calculator.sumAll(Integer.MAX_VALUE, Integer.MAX_VALUE).get()).isEqualTo(Integer.MAX_VALUE); // TODO failing on purpose please fix

}
}
15 changes: 12 additions & 3 deletions src/test/java/se/cygni/palmithor/tdd/StringUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class StringUtilsTest {

@Test
public void isPalindrome() {
assertThat(stringUtils.isPalindrome("aabb")).isFalse();
assertThat(stringUtils.isPalindrome(null)).isFalse();
assertThat(stringUtils.isPalindrome("NotEvenClose")).isFalse();
assertThat(stringUtils.isPalindrome("")).isTrue();
assertThat(stringUtils.isPalindrome("aabb")).isFalse();
assertThat(stringUtils.isPalindrome("NotEvenClose")).isFalse();
assertThat(stringUtils.isPalindrome("abba")).isTrue();
assertThat(stringUtils.isPalindrome("tattarrattat")).isTrue();
}
Expand All @@ -24,6 +24,15 @@ public void isPalindrome() {
*/
@Test
public void isBlank() {
// stringUtils.isBlank()
assertThat(stringUtils.isBlank(" ")).isTrue();
assertThat(stringUtils.isBlank("")).isTrue();
assertThat(stringUtils.isBlank(null)).isTrue();
assertThat(stringUtils.isBlank("mjjjouu")).isFalse();
assertThat(stringUtils.isBlank(" hej")).isFalse();
assertThat(stringUtils.isBlank(" \n")).isTrue();
assertThat(stringUtils.isBlank(" \t")).isTrue();



}
}