Commit 734bd362 authored by Colin DAMON's avatar Colin DAMON
Browse files

Merge branch '51-tcr-roman-numerals' into 'master'

Resolve "TCR Roman Numerals"

Closes #51

See merge request !37
parents 2b87bd84 696b99ed
...@@ -14,3 +14,4 @@ include: ...@@ -14,3 +14,4 @@ include:
- local: "/mustache-replacer/.gitlab-ci.yml" - local: "/mustache-replacer/.gitlab-ci.yml"
- local: "/string-calculator-2/.gitlab-ci.yml" - local: "/string-calculator-2/.gitlab-ci.yml"
- local: "/trip-service-kata/.gitlab-ci.yml" - local: "/trip-service-kata/.gitlab-ci.yml"
- local: "/tcr-roman-numerals/.gitlab-ci.yml"
...@@ -14,7 +14,7 @@ stages: ...@@ -14,7 +14,7 @@ stages:
- cd $PROJECT_FOLDER - cd $PROJECT_FOLDER
script: script:
- mvn $MAVEN_CLI_OPTS clean package - mvn $MAVEN_CLI_OPTS clean package
- awk -F"," '{ branches += $6 + $7; covered += $7 } END { print covered, "/", branches, "branches covered"; print 100*covered/branches, "%covered" }' target/site/jacoco/jacoco.csv - awk -F"," '{ branches += $4 + $5 + $6 + $7; covered += $5 + $7 } END { print covered, "/", branches, "branches covered"; print 100*covered/branches, "%covered" }' target/site/jacoco/jacoco.csv
artifacts: artifacts:
reports: reports:
junit: $PROJECT_FOLDER/target/surefire-reports/TEST-*.xml junit: $PROJECT_FOLDER/target/surefire-reports/TEST-*.xml
...@@ -35,7 +35,7 @@ stages: ...@@ -35,7 +35,7 @@ stages:
- cd $PROJECT_FOLDER - cd $PROJECT_FOLDER
script: script:
- ./mvnw -B -Pprod,swagger verify - ./mvnw -B -Pprod,swagger verify
- awk -F"," '{ branches += $6 + $7; covered += $7 } END { print covered, "/", branches, "branches covered"; print 100*covered/branches, "%covered" }' target/jacoco-aggregate/jacoco.csv - awk -F"," '{ branches += $4 + $5 + $6 + $7; covered += $5 + $7 } END { print covered, "/", branches, "branches covered"; print 100*covered/branches, "%covered" }' target/jacoco-aggregate/jacoco.csv
artifacts: artifacts:
reports: reports:
junit: $PROJECT_FOLDER/target/test-results/**/TEST-*.xml junit: $PROJECT_FOLDER/target/test-results/**/TEST-*.xml
......
...@@ -36,3 +36,4 @@ Ce dépôt Git a pour but de partager les différents ateliers pouvant être ré ...@@ -36,3 +36,4 @@ Ce dépôt Git a pour but de partager les différents ateliers pouvant être ré
| [String calculator 2](/string-calculator-2) | Kata | Moyenne | | [String calculator 2](/string-calculator-2) | Kata | Moyenne |
| [Proxifier son localhost avec un nginx dockerisé avec Edouard CATTEZ](https://www.youtube.com/watch?v=qWMfRb3zK7k) | Talk | Facile | | [Proxifier son localhost avec un nginx dockerisé avec Edouard CATTEZ](https://www.youtube.com/watch?v=qWMfRb3zK7k) | Talk | Facile |
| [Dev pour des data scientists, un sale boulot](https://www.youtube.com/watch?v=QK3OJGAresE) | Discussion | | | [Dev pour des data scientists, un sale boulot](https://www.youtube.com/watch?v=QK3OJGAresE) | Discussion | |
| [TCR - Roman Numerals](/tcr-roman-numerals) | Kata | Moyenne |
package-tcr-roman-numerals:
variables:
PROJECT_FOLDER: "tcr-roman-numerals"
extends: .java
only:
refs:
- master
- merge_requests
changes:
- ".gitlab-common-ci.yml"
- "tcr-roman-numerals/**/*"
# Roman Numerals en TCR
Résolution en TDD et en Java du kata [Roman Numerals](https://codingdojo.org/kata/RomanNumerals/) avec une contrainte de [TCR](https://medium.com/@kentbeck_7670/test-commit-revert-870bbd756864).
- **Auteurs** : Colin DAMON
- **Date** : 24/11/2020
- **Langage** : Java
- **Niveau** : Moyen
- **Replay** : TODO
<?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>tcr-roman-numerals</artifactId>
<name>TCRRomanNumerals</name>
<developers>
<developer>
<email>cdamon@ippon.fr</email>
<name>Colin DAMON</name>
</developer>
</developers>
</project>
package fr.ippon.kata.numeral;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Optional;
import java.util.TreeMap;
import java.util.function.Function;
public class Numerals {
private static final NavigableMap<Integer, String> CONVERSIONS = buildConversions();
private Numerals() {}
public static String toRoman(int arabic) {
return highestKnownConversion(arabic).map(toRomanRepresentation(arabic)).orElse("");
}
private static Optional<Entry<Integer, String>> highestKnownConversion(int arabic) {
return Optional.ofNullable(CONVERSIONS.floorEntry(arabic));
}
private static Function<Entry<Integer, String>, String> toRomanRepresentation(int arabic) {
return conversion -> conversion.getValue() + toRoman(arabic - conversion.getKey());
}
private static NavigableMap<Integer, String> buildConversions() {
NavigableMap<Integer, String> conversions = new TreeMap<>();
conversions.put(1, "I");
conversions.put(4, "IV");
conversions.put(5, "V");
conversions.put(9, "IX");
conversions.put(10, "X");
return conversions;
}
}
package fr.ippon.kata.numeral;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
class NumeralsTest {
@Test
void shouldConvertZeroToEmptyString() {
assertThat(Numerals.toRoman(0)).isEmpty();
}
@Test
void shouldConvertOneToI() {
assertThat(Numerals.toRoman(1)).isEqualTo("I");
}
@Test
void shouldConvertTwoToII() {
assertThat(Numerals.toRoman(2)).isEqualTo("II");
}
@Test
void shouldConvertFourToIV() {
assertThat(Numerals.toRoman(4)).isEqualTo("IV");
}
@Test
void shouldConvertFiveToV() {
assertThat(Numerals.toRoman(5)).isEqualTo("V");
}
@Test
void shouldConvertSixToVI() {
assertThat(Numerals.toRoman(6)).isEqualTo("VI");
}
@Test
void shouldConvertNineToIX() {
assertThat(Numerals.toRoman(9)).isEqualTo("IX");
}
@Test
void shouldConvertTenToX() {
assertThat(Numerals.toRoman(10)).isEqualTo("X");
}
@Test
void shouldConvertElevenToXI() {
assertThat(Numerals.toRoman(11)).isEqualTo("XI");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment