From ec0d2184c8c1afdf30f441e7b7f13a4fa4c73db5 Mon Sep 17 00:00:00 2001
From: Colin DAMON <cdamon@ippon.fr>
Date: Wed, 22 Jul 2020 17:46:11 +0200
Subject: [PATCH 1/2] Init string calculator

---
 .gitlab-ci.yml                  |  1 +
 stringCalculator/.gitlab-ci.yml | 24 ++++++++
 stringCalculator/README.md      |  7 +++
 stringCalculator/pom.xml        | 98 +++++++++++++++++++++++++++++++++
 4 files changed, 130 insertions(+)
 create mode 100644 stringCalculator/.gitlab-ci.yml
 create mode 100644 stringCalculator/README.md
 create mode 100644 stringCalculator/pom.xml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7c0aa195..5b00776b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,3 +5,4 @@ include:
   - local: "/.gitlab-common-ci.yml"
   - local: "/wordWrap/.gitlab-ci.yml"
   - local: "/romanNumerals/.gitlab-ci.yml"
+  - local: "/stringCalculator/.gitlab-ci.yml"
diff --git a/stringCalculator/.gitlab-ci.yml b/stringCalculator/.gitlab-ci.yml
new file mode 100644
index 00000000..a83cd56f
--- /dev/null
+++ b/stringCalculator/.gitlab-ci.yml
@@ -0,0 +1,24 @@
+stages:
+  - build
+  
+package-string-calculator:
+  extends: .java
+  stage: build
+  tags:
+    - docker
+  script:
+    - cd stringCalculator
+    - mvn $MAVEN_CLI_OPTS clean package
+    - cat target/site/jacoco/index.html
+  artifacts:
+    reports:
+      junit: stringCalculator/target/surefire-reports/TEST-*.xml
+    expire_in: 1 day
+  only:
+    refs:
+      - master
+      - merge_requests
+    changes:
+      - ".gitlab-ci.yml"
+      - ".gitlab-common-ci.yml"
+      - "stringCalculator/**/*"
diff --git a/stringCalculator/README.md b/stringCalculator/README.md
new file mode 100644
index 00000000..df98c36e
--- /dev/null
+++ b/stringCalculator/README.md
@@ -0,0 +1,7 @@
+<p align="center">
+  <a href="https://fr.ippon.tech/" target="_blank">
+    <img alt="Ippon Technologies Logo" width="100" src="https://fr.ippon.tech/assets/images/common/Logo.svg">
+  </a>
+</p>
+
+# Ippon Kata : String Calculator
diff --git a/stringCalculator/pom.xml b/stringCalculator/pom.xml
new file mode 100644
index 00000000..4c1471bf
--- /dev/null
+++ b/stringCalculator/pom.xml
@@ -0,0 +1,98 @@
+<?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>
+
+  <version>1.0.0-SNAPSHOT</version>
+  <groupId>fr.ippon.kata</groupId>
+  <artifactId>string-calculator</artifactId>
+
+  <name>StringCalculator</name>
+
+  <properties>
+    <java.version>14</java.version>
+
+    <junit.version>5.7.0-M1</junit.version>
+    <assertj.version>3.16.1</assertj.version>
+    <mockito.version>3.1.0</mockito.version>
+
+    <surefire-plugin.version>3.0.0-M4</surefire-plugin.version>
+    <compiler-plugin.version>3.8.1</compiler-plugin.version>
+    <jacoco.version>0.8.5</jacoco.version>
+  </properties>
+
+  <developers>
+    <developer>
+      <email>cdamon@ippon.fr</email>
+      <name>Colin DAMON</name>
+    </developer>
+    <developer>
+      <email>mfillatre@ippon.fr</email>
+      <name>Marina FILLATRE</name>
+    </developer>
+  </developers>
+
+
+  <dependencies>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-engine</artifactId>
+      <version>${junit.version}</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <version>${assertj.version}</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-junit-jupiter</artifactId>
+      <version>${mockito.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>${surefire-plugin.version}</version>
+      </plugin>
+
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>${compiler-plugin.version}</version>
+        <configuration>
+          <source>${java.version}</source>
+          <target>${java.version}</target>
+        </configuration>
+      </plugin>
+
+      <plugin>
+        <groupId>org.jacoco</groupId>
+        <artifactId>jacoco-maven-plugin</artifactId>
+        <version>${jacoco.version}</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>prepare-agent</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>report</id>
+            <phase>test</phase>
+            <goals>
+              <goal>report</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
-- 
GitLab


From 95bad8548d1cdaf3092bf625c4795b903703ce86 Mon Sep 17 00:00:00 2001
From: Colin DAMON <cdamon@ippon.fr>
Date: Thu, 23 Jul 2020 14:02:30 +0200
Subject: [PATCH 2/2] Live implementation

---
 README.md                                     |  4 +
 .../fr/ippon/stringcalculator/Calculator.java | 41 +++++++++
 .../stringcalculator/CalculatorTest.java      | 89 +++++++++++++++++++
 3 files changed, 134 insertions(+)
 create mode 100644 stringCalculator/src/main/java/fr/ippon/stringcalculator/Calculator.java
 create mode 100644 stringCalculator/src/test/java/fr/ippon/stringcalculator/CalculatorTest.java

diff --git a/README.md b/README.md
index c8bbb25a..2fa755e8 100644
--- a/README.md
+++ b/README.md
@@ -23,3 +23,7 @@ Ce dépôt Git a pour but de partager les différents ateliers pouvant être ré
     * Niveau: Débutant
     * Lien: [Roman Numerals avec Julie et Colin](https://www.youtube.com/watch?v=CWJqq_k7hDY)
     * Go To: [RomanNumerals](/romanNumerals)
+* **[Presque String Calculator](https://codingdojo.org/kata/StringCalculator/)**: Par Marina FILLATRE et Colin DAMON le 23/07/2020
+    * Niveau: Moyen
+    * Lien: [Agility && TDD, Marina et Colin](https://www.twitch.tv/videos/688222419)
+    * Go To: [stringCalculator](/stringCalculator)
diff --git a/stringCalculator/src/main/java/fr/ippon/stringcalculator/Calculator.java b/stringCalculator/src/main/java/fr/ippon/stringcalculator/Calculator.java
new file mode 100644
index 00000000..792c5707
--- /dev/null
+++ b/stringCalculator/src/main/java/fr/ippon/stringcalculator/Calculator.java
@@ -0,0 +1,41 @@
+package fr.ippon.stringcalculator;
+
+import java.math.BigDecimal;
+import java.util.function.BinaryOperator;
+
+public class Calculator {
+
+  public static String sum(String first, String second) {
+    return operate(first, second, BigDecimal::add);
+  }
+
+  public static String substract(String first,
+      String second) {
+    return operate(first, second, BigDecimal::subtract);
+  }
+
+  private static String operate(String first,
+      String second, BinaryOperator<BigDecimal> operation) {
+    notNull(first);
+    notNull(second);
+
+    return operation
+        .apply(toBigDecimal(first), toBigDecimal(second))
+        .toPlainString();
+  }
+
+  private static BigDecimal toBigDecimal(String value) {
+    if (value.isBlank()) {
+      return BigDecimal.ZERO;
+    }
+
+    return new BigDecimal(value.replace(",", "."));
+  }
+
+  private static void notNull(String first) {
+    if (first == null) {
+      throw new IllegalArgumentException();
+    }
+  }
+
+}
diff --git a/stringCalculator/src/test/java/fr/ippon/stringcalculator/CalculatorTest.java b/stringCalculator/src/test/java/fr/ippon/stringcalculator/CalculatorTest.java
new file mode 100644
index 00000000..1b4d1668
--- /dev/null
+++ b/stringCalculator/src/test/java/fr/ippon/stringcalculator/CalculatorTest.java
@@ -0,0 +1,89 @@
+package fr.ippon.stringcalculator;
+
+import static org.assertj.core.api.Assertions.*;
+
+import org.junit.jupiter.api.Test;
+
+public class CalculatorTest {
+
+  @Test
+  void shouldNotSumWithNullFirstInput() {
+    assertThatThrownBy(() -> Calculator.sum(null, "3"))
+        .isExactlyInstanceOf(
+            IllegalArgumentException.class);
+  }
+
+  @Test
+  void shouldNotSumWithNullSecondInput() {
+    assertThatThrownBy(() -> Calculator.sum("3", null))
+        .isExactlyInstanceOf(
+            IllegalArgumentException.class);
+  }
+
+  @Test
+  void shouldSumEmptyInputs() {
+    assertThat(Calculator.sum("", "")).isEqualTo("0");
+  }
+
+  @Test
+  void shouldSumIntegerWithEmptyFirstInput() {
+    assertThat(Calculator.sum("", "4")).isEqualTo("4");
+  }
+
+  @Test
+  void shouldSumIntegerWithEmptySecondInput() {
+    assertThat(Calculator.sum("4", "")).isEqualTo("4");
+  }
+
+  @Test
+  void shouldSumIntegers() {
+    assertThat(Calculator.sum("1", "2")).isEqualTo("3");
+  }
+
+  @Test
+  void shouldSumFloats() {
+    assertThat(Calculator.sum("1.01", "2.02"))
+        .isEqualTo("3.03");
+  }
+
+  @Test
+  void shouldSumCommaSeparatedFloats() {
+    assertThat(Calculator.sum("1,01", "2,02"))
+        .isEqualTo("3.03");
+  }
+
+  @Test
+  void shouldSumNegativeCommaSeparatedFloats() {
+    assertThat(Calculator.sum("-1,01", "-2,02"))
+        .isEqualTo("-3.03");
+  }
+
+  @Test
+  void shouldNotSubstractNullInputs() {
+    assertThatThrownBy(
+        () -> Calculator.substract(null, "3"))
+            .isExactlyInstanceOf(
+                IllegalArgumentException.class);
+  }
+
+  @Test
+  void shouldNotSubstractWithNullSecondInputs() {
+    assertThatThrownBy(
+        () -> Calculator.substract("3", null))
+            .isExactlyInstanceOf(
+                IllegalArgumentException.class);
+  }
+
+  @Test
+  void shouldSubstractCommaSeparatedFloats() {
+    assertThat(Calculator.substract("1,01", "2,02"))
+        .isEqualTo("-1.01");
+  }
+
+  @Test
+  void shouldSumTooBigIntegers() {
+    assertThat(Calculator
+        .sum(String.valueOf(Integer.MAX_VALUE), "2,02"))
+            .isEqualTo("2147483649.02");
+  }
+}
-- 
GitLab