Skip to content

Commit 779e141

Browse files
committed
2020-10-29 Update: Added "Parse nice int from char problem" and "Is valid identifier?"
1 parent d7d6664 commit 779e141

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.smlnskgmail.jaman.codewarsjava.kyu7;
2+
3+
// https://www.codewars.com/kata/563a8656d52a79f06c00001f
4+
public class IsValidIdentifier {
5+
6+
private final String input;
7+
8+
public IsValidIdentifier(String input) {
9+
this.input = input;
10+
}
11+
12+
public boolean solution() {
13+
return input.length() > 1
14+
&& input.substring(0, 1).matches("^[a-zA-Z_$]*$")
15+
&& input.substring(1).matches("^[a-zA-Z0-9_$]*$");
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.smlnskgmail.jaman.codewarsjava.kyu8;
2+
3+
// https://www.codewars.com/kata/557cd6882bfa3c8a9f0000c1
4+
public class ParseNiceIntFromCharProblem {
5+
6+
private final String input;
7+
8+
public ParseNiceIntFromCharProblem(String input) {
9+
this.input = input;
10+
}
11+
12+
public int solution() {
13+
return Character.getNumericValue(input.charAt(0));
14+
}
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.smlnskgmail.jaman.codewarsjava.kyu7;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertFalse;
6+
import static org.junit.Assert.assertTrue;
7+
8+
public class IsValidIdentifierTest {
9+
10+
@Test
11+
public void testValid() {
12+
assertTrue(new IsValidIdentifier("i1").solution());
13+
}
14+
15+
@Test
16+
public void testInvalid() {
17+
assertFalse(new IsValidIdentifier("1i").solution());
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.smlnskgmail.jaman.codewarsjava.kyu8;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class ParseNiceIntFromCharProblemTest {
8+
9+
@Test
10+
public void test1() {
11+
assertEquals(
12+
5,
13+
new ParseNiceIntFromCharProblem("5 years old").solution()
14+
);
15+
}
16+
17+
@Test
18+
public void test2() {
19+
assertEquals(
20+
9,
21+
new ParseNiceIntFromCharProblem("9 years old").solution()
22+
);
23+
}
24+
25+
@Test
26+
public void test3() {
27+
assertEquals(
28+
1,
29+
new ParseNiceIntFromCharProblem("1 year old").solution()
30+
);
31+
}
32+
33+
}

0 commit comments

Comments
 (0)