From 90df818a38ffc057f59815550f52df6007fe1af1 Mon Sep 17 00:00:00 2001 From: somename Date: Fri, 16 Sep 2016 16:02:29 +0300 Subject: [PATCH 1/2] besouro automatic message --- .besouro/20160916160212601/actions.txt | 3 + .../20160916160212601/besouroEpisodes.txt | 1 + .besouro/20160916160212601/disagreements.txt | 0 .../randomHeuristicEpisodes.txt | 1 + .besouro/20160916160212601/userComments.txt | 0 .besouro/20160916160212601/zorroEpisodes.txt | 1 + bin/.gitignore | 3 + bin/StringCalculator.class | Bin 405 -> 2453 bytes bin/StringCalculatorTest.class | Bin 505 -> 2843 bytes src/StringCalculator.java | 109 +++++++++++++++++- tests/StringCalculatorTest.java | 109 ++++++++++++++++-- 11 files changed, 211 insertions(+), 16 deletions(-) create mode 100644 .besouro/20160916160212601/actions.txt create mode 100644 .besouro/20160916160212601/besouroEpisodes.txt create mode 100644 .besouro/20160916160212601/disagreements.txt create mode 100644 .besouro/20160916160212601/randomHeuristicEpisodes.txt create mode 100644 .besouro/20160916160212601/userComments.txt create mode 100644 .besouro/20160916160212601/zorroEpisodes.txt create mode 100644 bin/.gitignore diff --git a/.besouro/20160916160212601/actions.txt b/.besouro/20160916160212601/actions.txt new file mode 100644 index 0000000..1644b5b --- /dev/null +++ b/.besouro/20160916160212601/actions.txt @@ -0,0 +1,3 @@ +FileOpenedAction 1474030932817 StringCalculator.java 2409 4 20 0 +UnitTestCaseAction 1474030944931 StringCalculatorTest.java OK +UnitTestSessionAction 1474030944933 StringCalculatorTest.java OK diff --git a/.besouro/20160916160212601/besouroEpisodes.txt b/.besouro/20160916160212601/besouroEpisodes.txt new file mode 100644 index 0000000..8f1db8a --- /dev/null +++ b/.besouro/20160916160212601/besouroEpisodes.txt @@ -0,0 +1 @@ +1474030944933 regression 1 12 true diff --git a/.besouro/20160916160212601/disagreements.txt b/.besouro/20160916160212601/disagreements.txt new file mode 100644 index 0000000..e69de29 diff --git a/.besouro/20160916160212601/randomHeuristicEpisodes.txt b/.besouro/20160916160212601/randomHeuristicEpisodes.txt new file mode 100644 index 0000000..8f1db8a --- /dev/null +++ b/.besouro/20160916160212601/randomHeuristicEpisodes.txt @@ -0,0 +1 @@ +1474030944933 regression 1 12 true diff --git a/.besouro/20160916160212601/userComments.txt b/.besouro/20160916160212601/userComments.txt new file mode 100644 index 0000000..e69de29 diff --git a/.besouro/20160916160212601/zorroEpisodes.txt b/.besouro/20160916160212601/zorroEpisodes.txt new file mode 100644 index 0000000..393e16e --- /dev/null +++ b/.besouro/20160916160212601/zorroEpisodes.txt @@ -0,0 +1 @@ +1474030944933 regression 1 12 false diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..249513b --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,3 @@ +/StringCalculator.class +/StringCalculatorException.class +/StringCalculatorTest.class diff --git a/bin/StringCalculator.class b/bin/StringCalculator.class index a937b0c43633d36f133837cd90ddd10fb14ac782..69bee41f10727f4a4aa08384895cc29b1559a429 100644 GIT binary patch literal 2453 zcmb7FOK%fb6#lL~<8d5A9%KNg;gOV(I1f_N#8AhffC*p-P9YGQq!cF3BpEPvWREFG zT_SbgT@eZ(wPM4j8z4nWyQ*+qW=!u{^d_(2GZ%Chh4+;h(No$p-#@#d!u z03%q@;1g(`whLBnIca1wrL1A+3mO#e-ZbtQLs=uYJT$d%)6CccfrOQ_>|+A{-sp^g zlFTofA^6b{hKhhd)1;L%)1})BX5q52kTnHbC-WI2J7W|qx%M^{d&Mfsv(0hG=-F6Y z6wrGoYtdb+v1m#lG;ud$uG&^USJcod5ZUaZdLBfZ074Mh8OAQ`76@8JH#LD>Tewdq zqjMp&pdpA41jIlHd$3Q#-nWQw!-cUQodRlcHEWTTo-MpZ=idbo!iVVAa6q7?1}>Ge z&1JI?#z8bO$5o?HG`UBpIfut0LrSV@H#|B>Rk3uNnUWUGvlZB}MO@mD?QPSxk-2rj zSaph^VL%{EuCL^>)@{o+NqUo97Ab_Z`Bj#M)bKGKI)O{Jl^r@!C>Zx9t)d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d_yTSJIMiO!m{e1fMCvQ0t=L^Dw?vf)OQHV`FbN zLAV&nVl;(^_y?jarr2*?Za>`MhzB2^L4K$CW;3E^?k%+6Rl6X>r<&%E=;t%s9EWj(UjhT1 z?Lvg(Zhj3S%27W@L%d@p47<87D5Q9izYyPji_v^SoMLS0j4 zku(b3!iQ8H;C-930lufML*HrA2R(Z9jvqcsNQ|xwx8Vmpyw=1=+VCI$PyAg!{21}$ z#7|rsf6oW6ay7(wsdN^YvjE?tEytrXG0Y{RN#cL|1F4JgpQHs-7{MLaf_P)E7l6TL z00jT@cIN!u+=nrIl8AnK33r;@d*ses!CiQ7?qUqfiRkB-aFgWDlbgDN`-Km;qsD!z zY}GH#SweG6^Mh-rd5!ph+gR5L^7<*B_$7Cd+$B1@e1)@Ly%#NiicLS-I%$tddvXQs zn`_dxVkjh{JD1S%q&*{T^9tHaU)ol)P2ygg?Di$1-(AAmB5RvxM4^op_nKtDYmy&) jS)DEUV+=nfqI;LnUXr#;&tA3BMm^eDOP1N@0m%OV%-HyF delta 190 zcmbO&_LG_G)W2Q(7#J8#7^Ek1&17XMNi8m!_(tD>gF%RqLD(<9M4>XZL?JV`ASX39 zHLoN!g^NLiL5!V2l#xLozbIWlt28gOMBlNvIJKyRhe4b{f{}qGEip4^az3LtW7uQ~ zRue|1$-b;EflLhiKx^0-fck(mJJ?D_AP*=eB)Ee?cq5R-#J~k4xqvhS11AG3ki`vT U@jz4oX 3) { + throw new StringCalculatorException(); + } + + for(String s : numbers) { + sum += Integer.parseInt(s); + } + + return sum; + + } + + // add unlimited amount with comma + public int addUnlimited(String numbersStr) { + int sum = 0; + + if(numbersStr == null || numbersStr == "" || !isNumber(numbersStr, '\n', ',')) { + return 0; + } + + // create an array of our string, splitting it with character ','. + String[] numbers = numbersStr.split(","); + + for(String s : numbers) { + sum += Integer.parseInt(s); + } + + return sum; + } + + // add unlimited + cut with newline and comma. + public int addUsingNewline(String numbersStr) { + + int sum = 0; + + if(numbersStr == null || numbersStr == "" || !isNumber(numbersStr, '\n', ',')) { + return 0; + } + + // From this point forwards our string contains only numbers, newlines and commas. + + // create a new list, which contains our integers as characters. + List numbers = new ArrayList(); + + // helper boolean + boolean cutOnce = false; + + // cut our string using newline or comma. + for(char c : numbersStr.toCharArray()) { + if(c == '\n' || c == ',') { + + // if we have cut once already. + // -> return zero, because it's not allowed to have two + // cuts in a row. + if(cutOnce) { + return 0; + } + + cutOnce = true; + continue; + } + + cutOnce = false; + numbers.add(c); + } + + for(Character c : numbers) { + sum += Integer.parseInt(c.toString()); + } + + return sum; + } + + private boolean isNumber(String s, char cut1, char cut2) { + + for(char c : s.toCharArray()) { + + // change this to allow different char to split? + if(c == cut1 || c == cut2) { + continue; + } + + if(!Character.isDigit(c)) { + return false; + } + } + + return true; } + } diff --git a/tests/StringCalculatorTest.java b/tests/StringCalculatorTest.java index 4ec9afe..2df694c 100644 --- a/tests/StringCalculatorTest.java +++ b/tests/StringCalculatorTest.java @@ -1,12 +1,97 @@ -import static org.junit.Assert.*; - -import org.junit.Test; - -public class StringCalculatorTest { - - @Test - public void test() { - fail("Not yet implemented"); - } - -} +import static org.junit.Assert.*; + +import org.junit.Test; + +public class StringCalculatorTest { + + // TEST ADD BEGIN + + @Test (expected = StringCalculatorException.class) + public void test_return_zero_null_string() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + //assertEquals("zero", 0, strcalc.add(null)); + int a = strcalc.add(null); + } + + @Test (expected = StringCalculatorException.class) + public void test_return_zero_empty_string() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + //assertEquals("zero", 0, strcalc.add("")); + int a = strcalc.add(""); + } + + @Test (expected = StringCalculatorException.class) + public void test_return_zero_invalid_string() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + //assertEquals("zero", 0, strcalc.add("as2")); + int a = strcalc.add("as2"); + } + + @Test + public void test_return_two_string_1_1() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return two.", 2, strcalc.add("1,1")); + } + + @Test + public void test_return_five_string_2_3() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return five.", 5, strcalc.add("2,3")); + } + + @Test + public void test_return_three_string_3() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return three.", 3, strcalc.add("3")); + } + + @Test(expected = StringCalculatorException.class) + public void test_return_exception_string_negative() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + int a = strcalc.add("-3"); + } + + // TEST ADD END. + + // TEST ADDUNLIMITED BEGIN + + @Test + public void test_unlimited_return_5_string_1_1_1_1_1() { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return five.", 5, strcalc.addUnlimited("1,1,1,1,1")); + } + + // TEST ADDUNLIMITED END. + + // TEST ADDNEWCHAR BEGIN + + @Test + public void test_newline_return_5_string_1_1_1_1_1() { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return five.", 5, strcalc.addUsingNewline("1\n1\n1\n1\n1")); + } + + @Test + public void test_newline_return_6_string_1_newline_2_3() { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return six.", 6, strcalc.addUsingNewline("1\n2,3")); + } + + @Test + public void test_newline_return_0_string_1_newline_comma_3() { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return zero.", 0, strcalc.addUsingNewline("1\n,")); + } + + @Test + public void test_newline_return_10_string_1_newline_2_newline_3_comma_3_comma_1() { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return ten.", 10, strcalc.addUsingNewline("1\n2\n3,3,1")); + } + + // TEST ADDNEWCHAR END. + + + + +} From 31506078731737bc5b3e4700ca399bd4f2836923 Mon Sep 17 00:00:00 2001 From: heiheisk Date: Fri, 16 Sep 2016 16:23:50 +0300 Subject: [PATCH 2/2] task finished --- tests/StringCalculatorTest.java | 194 ++++++++++++++++---------------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/tests/StringCalculatorTest.java b/tests/StringCalculatorTest.java index 2df694c..e40c53d 100644 --- a/tests/StringCalculatorTest.java +++ b/tests/StringCalculatorTest.java @@ -1,97 +1,97 @@ -import static org.junit.Assert.*; - -import org.junit.Test; - -public class StringCalculatorTest { - - // TEST ADD BEGIN - - @Test (expected = StringCalculatorException.class) - public void test_return_zero_null_string() throws StringCalculatorException { - StringCalculator strcalc = new StringCalculator(); - //assertEquals("zero", 0, strcalc.add(null)); - int a = strcalc.add(null); - } - - @Test (expected = StringCalculatorException.class) - public void test_return_zero_empty_string() throws StringCalculatorException { - StringCalculator strcalc = new StringCalculator(); - //assertEquals("zero", 0, strcalc.add("")); - int a = strcalc.add(""); - } - - @Test (expected = StringCalculatorException.class) - public void test_return_zero_invalid_string() throws StringCalculatorException { - StringCalculator strcalc = new StringCalculator(); - //assertEquals("zero", 0, strcalc.add("as2")); - int a = strcalc.add("as2"); - } - - @Test - public void test_return_two_string_1_1() throws StringCalculatorException { - StringCalculator strcalc = new StringCalculator(); - assertEquals("Should return two.", 2, strcalc.add("1,1")); - } - - @Test - public void test_return_five_string_2_3() throws StringCalculatorException { - StringCalculator strcalc = new StringCalculator(); - assertEquals("Should return five.", 5, strcalc.add("2,3")); - } - - @Test - public void test_return_three_string_3() throws StringCalculatorException { - StringCalculator strcalc = new StringCalculator(); - assertEquals("Should return three.", 3, strcalc.add("3")); - } - - @Test(expected = StringCalculatorException.class) - public void test_return_exception_string_negative() throws StringCalculatorException { - StringCalculator strcalc = new StringCalculator(); - int a = strcalc.add("-3"); - } - - // TEST ADD END. - - // TEST ADDUNLIMITED BEGIN - - @Test - public void test_unlimited_return_5_string_1_1_1_1_1() { - StringCalculator strcalc = new StringCalculator(); - assertEquals("Should return five.", 5, strcalc.addUnlimited("1,1,1,1,1")); - } - - // TEST ADDUNLIMITED END. - - // TEST ADDNEWCHAR BEGIN - - @Test - public void test_newline_return_5_string_1_1_1_1_1() { - StringCalculator strcalc = new StringCalculator(); - assertEquals("Should return five.", 5, strcalc.addUsingNewline("1\n1\n1\n1\n1")); - } - - @Test - public void test_newline_return_6_string_1_newline_2_3() { - StringCalculator strcalc = new StringCalculator(); - assertEquals("Should return six.", 6, strcalc.addUsingNewline("1\n2,3")); - } - - @Test - public void test_newline_return_0_string_1_newline_comma_3() { - StringCalculator strcalc = new StringCalculator(); - assertEquals("Should return zero.", 0, strcalc.addUsingNewline("1\n,")); - } - - @Test - public void test_newline_return_10_string_1_newline_2_newline_3_comma_3_comma_1() { - StringCalculator strcalc = new StringCalculator(); - assertEquals("Should return ten.", 10, strcalc.addUsingNewline("1\n2\n3,3,1")); - } - - // TEST ADDNEWCHAR END. - - - - -} +import static org.junit.Assert.*; + +import org.junit.Test; + +public class StringCalculatorTest { + + // TEST ADD BEGIN + + @Test (expected = StringCalculatorException.class) + public void test_return_zero_null_string() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + //assertEquals("zero", 0, strcalc.add(null)); + int a = strcalc.add(null); + } + + @Test (expected = StringCalculatorException.class) + public void test_return_zero_empty_string() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + //assertEquals("zero", 0, strcalc.add("")); + int a = strcalc.add(""); + } + + @Test (expected = StringCalculatorException.class) + public void test_return_zero_invalid_string() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + //assertEquals("zero", 0, strcalc.add("as2")); + int a = strcalc.add("as2"); + } + + @Test + public void test_return_two_string_1_1() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return two.", 2, strcalc.add("1,1")); + } + + @Test + public void test_return_five_string_2_3() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return five.", 5, strcalc.add("2,3")); + } + + @Test + public void test_return_three_string_3() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return three.", 3, strcalc.add("3")); + } + + @Test(expected = StringCalculatorException.class) + public void test_return_exception_string_negative() throws StringCalculatorException { + StringCalculator strcalc = new StringCalculator(); + int a = strcalc.add("-3"); + } + + // TEST ADD END. + + // TEST ADDUNLIMITED BEGIN + + @Test + public void test_unlimited_return_5_string_1_1_1_1_1() { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return five.", 5, strcalc.addUnlimited("1,1,1,1,1")); + } + + // TEST ADDUNLIMITED END. + + // TEST ADDNEWCHAR BEGIN + + @Test + public void test_newline_return_5_string_1_1_1_1_1() { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return five.", 5, strcalc.addUsingNewline("1\n1\n1\n1\n1")); + } + + @Test + public void test_newline_return_6_string_1_newline_2_3() { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return six.", 6, strcalc.addUsingNewline("1\n2,3")); + } + + @Test + public void test_newline_return_0_string_1_newline_comma_3() { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return zero.", 0, strcalc.addUsingNewline("1\n,")); + } + + @Test + public void test_newline_return_10_string_1_newline_2_newline_3_comma_3_comma_1() { + StringCalculator strcalc = new StringCalculator(); + assertEquals("Should return ten.", 10, strcalc.addUsingNewline("1\n2\n3,3,1")); + } + + // TEST ADDNEWCHAR END. + + + + +}