public class FirstClass {
public static byte sum (byte a, byte b) {
byte c = (byte) (a + b);
return c;
}
}
import org.junit.Test; import static org.junit.Assert.assertEquals; public class FirstClassTest { @Test public void testSum() throws Exception { byte a = 1; byte b = 2; assertEquals(3, FirstClass.sum(a, b)); } }
public class AbbreviateTwoWords {
public static String abbrevName(String name) {
String[] names = name.split(" ");
return (names[0].charAt(0) + "." + names[1].charAt(0)).toUpperCase();
}
}
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class SolutionTest { @Test public void testFixed() { assertEquals("S.H", AbbreviateTwoWords.abbrevName("Sam Harris")); assertEquals("P.F", AbbreviateTwoWords.abbrevName("Patrick Feenan")); assertEquals("E.C", AbbreviateTwoWords.abbrevName("Evan Cole")); assertEquals("P.F", AbbreviateTwoWords.abbrevName("P Favuzzi")); assertEquals("D.M", AbbreviateTwoWords.abbrevName("David Mendieta")); } }
import java.util.stream.*; public class Kata { public static int findShort(String s) { return Stream.of(s.split(" ")) .mapToInt(String::length) .min() .getAsInt(); } }
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Created by Javatlacati on 01/03/2017.
*/
public class KataTest {
@Test
public void findShort() throws Exception {
assertEquals(3, Kata.findShort("bitcoin take over the world maybe who knows perhaps"));
assertEquals(3, Kata.findShort("turns out random test cases are easier than writing out basic ones"));
}
}
import java.util.stream.*;
public class Kata {
public static int findShort(String s) {
return Stream.of(s.split(" "))
.mapToInt(String::length)
.min()
.getAsInt();
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Created by Javatlacati on 01/03/2017.
*/
public class KataTest {
@Test
public void findShort() throws Exception {
assertEquals(3, Kata.findShort("bitcoin take over the world maybe who knows perhaps"));
assertEquals(3, Kata.findShort("turns out random test cases are easier than writing out basic ones"));
}
}
public class Kata {
public static String solution(String str) {
// Your code here...
StringBuilder res = new StringBuilder(str.length());
for (int i = (str.length() - 1); i >= 0; i--){
res.append(str.charAt(i));
}
return res.toString();
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
public class SolutionTest {
@Test
public void sampleTests() {
assertEquals("dlrow", Kata.solution("world"));
}
}