Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
twitch
live-coding-fr
Commits
26994b78
Commit
26994b78
authored
Nov 09, 2020
by
Colin DAMON
Browse files
String calculator second edition
parent
525eb43f
Changes
7
Show whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
26994b78
...
...
@@ -12,3 +12,4 @@ include:
-
local
:
"
/java-pagination-seven/.gitlab-ci.yml"
-
local
:
"
/a-brief-history-of-date/.gitlab-ci.yml"
-
local
:
"
/mustache-replacer/.gitlab-ci.yml"
-
local
:
"
/string-calculator-2/.gitlab-ci.yml"
README.md
View file @
26994b78
...
...
@@ -30,5 +30,6 @@ Ce dépôt Git a pour but de partager les différents ateliers pouvant être ré
|
[
GreenIT: simple coup de peinture ou réelle démarche écologique ?
](
https://www.youtube.com/watch?v=liTuZZTCpGc
)
| Discussion | |
|
[
Une annonce pour recruter un crafter - Caroline, Chloé, Ianic et Colin
](
https://www.youtube.com/watch?v=E5AX6Ar1Fog
)
| Discussion | |
|
[
PadBowl
](
https://gitlab.com/cdamon/padbowl
)
| Application | Enervé |
|
[
A Brief History of Date
](
/a-brief-history-of-date
)
| Kata | Moyen
|
|
[
A Brief History of Date
](
/a-brief-history-of-date
)
| Kata | Moyen
ne
|
|
[
Mustache Replacer
](
/mustache-replacer
)
| Kata | Facile |
|
[
String calculator 2
](
/string-calculator-2
)
| Kata | Moyenne |
string-calculator-2/.gitlab-ci.yml
0 → 100644
View file @
26994b78
package-string-calculator
:
variables
:
PROJECT_FOLDER
:
"
string-calculator-2"
extends
:
.java
only
:
refs
:
-
master
-
merge_requests
changes
:
-
"
.gitlab-common-ci.yml"
-
"
string-calculator-2/**/*"
string-calculator-2/README.md
0 → 100644
View file @
26994b78
# String calculator
Résolution, en live, de
[
StringCalculator
](
/stringCalculator
)
.
-
**Auteurs**
: Colin DAMON
-
**Date**
: 06/11/2020
-
**Langage**
: Java
-
**Niveau**
: Moyen
-
**Replay**
: TODO
string-calculator-2/pom.xml
0 → 100644
View file @
26994b78
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<version>
1.0.0
</version>
<groupId>
fr.ippon.kata
</groupId>
<artifactId>
java-parent
</artifactId>
<relativePath>
../java-parent
</relativePath>
</parent>
<version>
1.0.0-SNAPSHOT
</version>
<artifactId>
string-calculator-2
</artifactId>
<name>
StringCalculator2
</name>
<developers>
<developer>
<email>
cdamon@ippon.fr
</email>
<name>
Colin DAMON
</name>
</developer>
</developers>
</project>
string-calculator-2/src/main/java/fr/ippon/stringcalculator/StringCalculator.java
0 → 100644
View file @
26994b78
package
fr.ippon.stringcalculator
;
import
java.math.BigDecimal
;
import
java.util.Arrays
;
public
final
class
StringCalculator
{
private
static
final
String
SEPARATOR
=
",|\n"
;
private
StringCalculator
()
{}
public
static
String
sum
(
String
numbers
)
{
if
(
noNumbers
(
numbers
))
{
return
"0"
;
}
return
Arrays
.
stream
(
numbers
.
split
(
SEPARATOR
)).
map
(
BigDecimal:
:
new
).
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
).
toPlainString
();
}
private
static
boolean
noNumbers
(
String
numbers
)
{
return
numbers
==
null
||
numbers
.
isBlank
();
}
}
string-calculator-2/src/test/java/fr/ippon/stringcalculator/StringCalculatorTest.java
0 → 100644
View file @
26994b78
package
fr.ippon.stringcalculator
;
import
static
fr
.
ippon
.
stringcalculator
.
StringCalculator
.*;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.*;
import
org.junit.jupiter.api.Test
;
public
class
StringCalculatorTest
{
@Test
void
shouldSumToZeroFromNullNumbers
()
{
assertThat
(
sum
(
null
)).
isEqualTo
(
"0"
);
}
@Test
void
shouldSumToZeroFromEmptyNumbers
()
{
assertThat
(
sum
(
""
)).
isEqualTo
(
"0"
);
}
@Test
void
shouldSumToFourFromFour
()
{
assertThat
(
sum
(
"4"
)).
isEqualTo
(
"4"
);
}
@Test
void
shouldSumFourAndTwo
()
{
assertThat
(
sum
(
"4,2"
)).
isEqualTo
(
"6"
);
}
@Test
void
shouldSumOneZeroOneAndTwoZeroTwo
()
{
assertThat
(
sum
(
"1.01,2.02"
)).
isEqualTo
(
"3.03"
);
}
@Test
void
shouldUseNewlinesAsSeparator
()
{
assertThat
(
sum
(
"1\n2,3"
)).
isEqualTo
(
"6"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment