File tree Expand file tree Collapse file tree 4 files changed +38
-0
lines changed
basic-math-add-or-subtract Expand file tree Collapse file tree 4 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ # [ Basic Math (Add or Subtract)] ( https://www.codewars.com/kata/basic-math-add-or-subtract " https://www.codewars.com/kata/5809b62808ad92e31b000031 ")
2+
3+ In this kata, you will do addition and subtraction on a given string. The return value must be also a string.
4+
5+ ** Note:** the input will not be empty.
6+
7+ ## Examples
8+
9+ ```
10+ "1plus2plus3plus4" --> "10"
11+ "1plus2plus3minus4" --> "2"
12+ ```
Original file line number Diff line number Diff line change 1+ import static java .util .stream .Stream .of ;
2+
3+ interface Kata {
4+ static String calculate (String str ) {
5+ return of (str .replace ("minus" , "plus-" ).split ("plus" )).mapToInt (Integer ::parseInt ).sum () + "" ;
6+ }
7+ }
Original file line number Diff line number Diff line change 1+ import static org .junit .jupiter .api .Assertions .assertEquals ;
2+
3+ import org .junit .jupiter .params .ParameterizedTest ;
4+ import org .junit .jupiter .params .provider .CsvSource ;
5+
6+ class CalculateExampleTest {
7+ @ ParameterizedTest
8+ @ CsvSource (textBlock = """
9+ 1plus2plus3plus4, 10
10+ 1minus2minus3minus4, -8
11+ 1plus2plus3minus4, 2
12+ 1minus2plus3minus4, -2
13+ 1plus2minus3plus4minus5, -1
14+ """ )
15+ void sample (String equation , String result ) {
16+ assertEquals (result , Kata .calculate (equation ));
17+ }
18+ }
Original file line number Diff line number Diff line change 4444- [ Averages of numbers] ( averages-of-numbers " 57d2807295497e652b000139 ")
4545- [ Balanced Number (Special Numbers Series #1 ) ] ( balanced-number-special-numbers-series-number-1 " 5a4e3782880385ba68000018 ")
4646- [ Basic Calculator] ( basic-calculator " 5296455e4fe0cdf2e000059f ")
47+ - [ Basic Math (Add or Subtract)] ( basic-math-add-or-subtract " 5809b62808ad92e31b000031 ")
4748- [ Basic Sequence Practice] ( basic-sequence-practice " 5436f26c4e3d6c40e5000282 ")
4849- [ Basics - Generators #1 ] ( basics-generators-number-1 " 5636840bd87777688b00006c ")
4950- [ Batman Quotes] ( batman-quotes " 551614eb77dd9ee37100003e ")
You can’t perform that action at this time.
0 commit comments