diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9aab457 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/demo/target diff --git a/demo/.editorconfig b/demo/.editorconfig new file mode 100644 index 0000000..1f494b0 --- /dev/null +++ b/demo/.editorconfig @@ -0,0 +1,17 @@ +# Editor configuration, see http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true +max_line_length = 80 + +[*.sh] +end_of_line = lf + +[*.java] +indent_size = 4 +max_line_length = 120 diff --git a/demo/pom.xml b/demo/pom.xml new file mode 100644 index 0000000..10c88ce --- /dev/null +++ b/demo/pom.xml @@ -0,0 +1,173 @@ + + 4.0.0 + com.challenges + demo + 1.0-SNAPSHOT + + 1.8 + 1.8 + UTF-8 + 5.6.0 + 3.0.0-M3 + 3.1.2 + 8.45.1 + 3.0.0-M5 + 0.8.4 + 3.0.0 + + 0% + 0% + 20 + 5 + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${maven-enforcer-plugin.version} + + + + enforce + + + + + 3.6.3 + + + true + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + com.puppycrawl.tools + checkstyle + ${checkstyle.version} + + + com.github.ngeor + checkstyle-rules + 4.9.3 + + + + com/github/ngeor/checkstyle.xml + true + ${skipTests} + + + + checkstyle + validate + + check + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + org.jacoco + jacoco-maven-plugin + ${jacoco-maven-plugin.version} + + + pre-unit-test + + prepare-agent + + + + post-unit-test + test + + report + + + + check-unit-test + test + + check + + + ${project.build.directory}/jacoco.exec + + + BUNDLE + + + INSTRUCTION + COVEREDRATIO + ${jacoco.unit-tests.limit.instruction-ratio} + + + BRANCH + COVEREDRATIO + ${jacoco.unit-tests.limit.branch-ratio} + + + + + CLASS + + + COMPLEXITY + TOTALCOUNT + ${jacoco.unit-tests.limit.class-complexity} + + + + + METHOD + + + COMPLEXITY + TOTALCOUNT + ${jacoco.unit-tests.limit.method-complexity} + + + + + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + + diff --git a/demo/src/main/java/com/challenges/App.java b/demo/src/main/java/com/challenges/App.java new file mode 100644 index 0000000..b01379b --- /dev/null +++ b/demo/src/main/java/com/challenges/App.java @@ -0,0 +1,61 @@ +package com.challenges; + +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Hello world! + */ +public final class App { + public static int highestDigit(String s) { + Pattern p = Pattern.compile("\\d+"); + Matcher m = p.matcher(s); + if (!m.matches()) + return -1; + + int largest = -1, current = -1; + for (int j = 0; j < s.length(); j++) { + if ((current = Integer.parseInt(s.charAt(j) + "")) > largest) + largest = current; + } + return largest; + } + + public static boolean match(String s, String c) { + if (s.length() != c.length()) + return false; + return s.toLowerCase().equals(c.toLowerCase()); + } + + /** + * Says hello to the world. + * + * @param args The arguments of the program. + */ + public static void main(String[] args) { + try (Scanner sc = new Scanner(System.in)) { + for (int i = 0; i < 7; i++) { + String s = sc.next(); + String c = sc.next(); + if ((match(s, c))) + System.out.println("True"); + else + System.out.println("False"); + } + + for (int i = 0; i < 7; i++) { + String s = sc.next(); + int digit; + if ((digit = highestDigit(s)) > -1) + System.out.println("largest: " + digit); + else + System.out.println("please input digits only"); + } + + System.out.println("thats it, 7 times each only.."); + } catch (Exception e) { + // TODO: handle exception + } + } +} diff --git a/demo/src/test/java/com/challenges/AppTest.java b/demo/src/test/java/com/challenges/AppTest.java new file mode 100644 index 0000000..84511bf --- /dev/null +++ b/demo/src/test/java/com/challenges/AppTest.java @@ -0,0 +1,29 @@ +package com.challenges; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Unit test for simple App. + */ +class AppTest { + /** + * Rigorous Test. + */ + @Test + void testDigits() { + assertEquals(App.highestDigit(12899 + ""), 9); + assertEquals(App.highestDigit(8123 + ""), 8); + assertEquals(App.highestDigit(193 + ""), 9); + assertEquals(App.highestDigit(1 + ""), 1); + } + + @Test + void testCaseInsensitiveComparisonChallenge() { + assertEquals(App.match("Jose", "JoSe"), true); + assertEquals(App.match("water", "wait"), false); + assertEquals(App.match("JOHN", "JOHn"), true); + assertEquals(App.match("ElEmEnTs", "eLeMeNtS"), true); + } +}