class Kata{ public static Boolean verifySum(String nameOne, String nameTwo) { int sumOfNames = 0; if (nameOne == null || nameTwo == null) { return null; } for (char ch : nameOne.toCharArray()){ sumOfNames += ch; } for (char ch : nameTwo.toCharArray()){ sumOfNames -= ch; } return sumOfNames == 0; } }
- class Kata{
public static String verifySum(String nameOne, String nameTwo) {int[] sumOfNames = new int[]{0, 0};- public static Boolean verifySum(String nameOne, String nameTwo) {
- int sumOfNames = 0;
- if (nameOne == null || nameTwo == null) {
return "NULL";- return null;
- }
for (int i = 0; i < nameOne.length(); i++){sumOfNames[0] += nameOne.charAt(i);- for (char ch : nameOne.toCharArray()){
- sumOfNames += ch;
- }
for (int i = 0; i < nameTwo.length(); i++){sumOfNames[1] += nameTwo.charAt(i);- for (char ch : nameTwo.toCharArray()){
- sumOfNames -= ch;
- }
return sumOfNames[0] == sumOfNames[1] ? "TRUE" : "FALSE";- return sumOfNames == 0;
- }
- }
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class SolutionTest { @Test public void testName() { assertEquals(false, Kata.verifySum("Sebastian", "Patricia")); assertEquals(true, Kata.verifySum("Anna", "Nana")); assertEquals(null, Kata.verifySum("John", null)); } }
- import org.junit.Test;
- import static org.junit.Assert.assertEquals;
- import org.junit.runners.JUnit4;
- public class SolutionTest {
- @Test
- public void testName() {
assertEquals("FALSE", Kata.verifySum("Sebastian", "Patricia"));assertEquals("TRUE", Kata.verifySum("Anna", "Nana"));assertEquals("NULL", Kata.verifySum("John", null));- assertEquals(false, Kata.verifySum("Sebastian", "Patricia"));
- assertEquals(true, Kata.verifySum("Anna", "Nana"));
- assertEquals(null, Kata.verifySum("John", null));
- }
- }