Commit f4b5fc0b authored by Colin DAMON's avatar Colin DAMON

Resolve "Small TDD kata"

parent 5fd8da9e
......@@ -25,3 +25,6 @@ include:
- local: "/java-streams/.gitlab-ci.yml"
- local: "/game-of-life/.gitlab-ci.yml"
- local: "/movie-rental/.gitlab-ci.yml"
- local: "/fizz-buzz/.gitlab-ci.yml"
- local: "/leap-years/.gitlab-ci.yml"
- local: "/employee-report/.gitlab-ci.yml"
......@@ -50,3 +50,6 @@ Ce dépôt Git a pour but de partager les différents ateliers pouvant être ré
| [CodingGame Mars Landing Party](https://www.youtube.com/watch?v=FeJa3UnmeHw) | CodingGame | Moyenne |
| [Game of life](/game-of-life) | Kata | Enervé |
| [Movie rental](/movie-rental) | Kata | Moyenne |
| [Fizz Buzz](/fizz-buzz) | Kata | Facile |
| [Leap years](/leap-years) | Kata | Facile |
| [Employee report](/employee-report) | Kata | Facile |
package-employee-report:
variables:
PROJECT_FOLDER: "employee-report"
extends: .java
only:
refs:
- master
- merge_requests
changes:
- ".gitlab-common-ci.yml"
- "employee-report/**/*"
<?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>employee-report</artifactId>
<name>EmployeeReport</name>
<developers>
<developer>
<email>lcoston@ippon.fr</email>
<name>Léa COSTON</name>
</developer>
<developer>
<email>cdamon@ippon.fr</email>
<name>Colin DAMON</name>
</developer>
</developers>
</project>
# Leap Year
Résolution en TDD et en Java du kata [EmmployeeReport](https://codingdojo.org/kata/Employee-Report/).
- **Auteurs** : Léa COSTON et Colin DAMON
- **Date** : 19/02/2021
- **Langage** : Java
- **Niveau** : Facile
- **Replay** : TODO
package fr.ippon.employee;
public class Employee {
private final String name;
private final int age;
public Employee(String name, int age) {
this.name = name;
this.age = age;
}
boolean isAdult() {
return age >= 18;
}
public String getName() {
return name.toUpperCase();
}
}
package fr.ippon.employee;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class EmployeeReport {
private final List<Employee> employees;
public EmployeeReport(Employee... employees) {
this.employees = Arrays.asList(employees);
}
public Collection<String> getAdults() {
return employees
.stream()
.filter(Employee::isAdult)
.map(Employee::getName)
.sorted(Comparator.reverseOrder())
.collect(Collectors.toUnmodifiableList());
}
}
package fr.ippon.employee;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class EmployeeReportTest {
private static final EmployeeReport employees = buildEmployees();
private static EmployeeReport buildEmployees() {
return new EmployeeReport(new Employee("Max", 17), new Employee("Sepp", 18), new Employee("Nina", 15), new Employee("mike", 51));
}
@Test
void shouldGetAdultEmployees() {
assertThat(employees.getAdults()).containsExactly("SEPP", "MIKE");
}
}
package-fizz-buzz:
variables:
PROJECT_FOLDER: "fizz-buzz"
extends: .java
only:
refs:
- master
- merge_requests
changes:
- ".gitlab-common-ci.yml"
- "fizz-buzz/**/*"
<?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>fizz-buzz</artifactId>
<name>FizzBuzz</name>
<developers>
<developer>
<email>lcoston@ippon.fr</email>
<name>Léa COSTON</name>
</developer>
<developer>
<email>cdamon@ippon.fr</email>
<name>Colin DAMON</name>
</developer>
</developers>
</project>
# Fizz Buzz
Résolution en TDD et en Java du kata [FizzBuzz](https://codingdojo.org/kata/FizzBuzz/).
- **Auteurs** : Léa COSTON et Colin DAMON
- **Date** : 19/02/2021
- **Langage** : Java
- **Niveau** : Facile
- **Replay** : TODO
package fr.ippon.fizzbuzz;
public class FizzBuzz {
private static final int BUZZ_VALUE = 5;
private static final int FIZZ_VALUE = 3;
private static final String BUZZ = "Buzz";
private static final String FIZZ = "Fizz";
private static final String FIZZ_BUZZ = FIZZ + BUZZ;
public static String of(int value) {
if (isFizzBuzz(value)) {
return FIZZ_BUZZ;
}
if (isBuzz(value)) {
return BUZZ;
}
if (isFizz(value)) {
return FIZZ;
}
return String.valueOf(value);
}
private static boolean isFizzBuzz(int value) {
return isFizz(value) && isBuzz(value);
}
private static boolean isBuzz(int value) {
return value % BUZZ_VALUE == 0;
}
private static boolean isFizz(int value) {
return value % FIZZ_VALUE == 0;
}
}
package fr.ippon.fizzbuzz;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
class FizzBuzzTest {
@Test
void shouldGetOneForOne() {
assertThat(FizzBuzz.of(1)).isEqualTo("1");
}
@Test
void shouldGetTwoForTwo() {
assertThat(FizzBuzz.of(2)).isEqualTo("2");
}
@Test
void shouldGetFizzForThree() {
assertThat(FizzBuzz.of(3)).isEqualTo("Fizz");
}
@Test
void shouldGetFizzForSix() {
assertThat(FizzBuzz.of(6)).isEqualTo("Fizz");
}
@Test
void shouldGetBuzzForFive() {
assertThat(FizzBuzz.of(5)).isEqualTo("Buzz");
}
@Test
void shouldGetFizzBuzzForFifteen() {
assertThat(FizzBuzz.of(15)).isEqualTo("FizzBuzz");
}
}
package-leap-years:
variables:
PROJECT_FOLDER: "leap-years"
extends: .java
only:
refs:
- master
- merge_requests
changes:
- ".gitlab-common-ci.yml"
- "leap-years/**/*"
<?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>leap-years</artifactId>
<name>LeapYears</name>
<developers>
<developer>
<email>lcoston@ippon.fr</email>
<name>Léa COSTON</name>
</developer>
<developer>
<email>cdamon@ippon.fr</email>
<name>Colin DAMON</name>
</developer>
</developers>
</project>
# Leap Year
Résolution en TDD et en Java du kata [LeapYears](https://codingdojo.org/kata/LeapYears/).
- **Auteurs** : Léa COSTON et Colin DAMON
- **Date** : 19/02/2021
- **Langage** : Java
- **Niveau** : Facile
- **Replay** : TODO
package fr.ippon.leapyears;
public class Years {
public static boolean isLeap(int year) {
return new Year(year).isLeap();
}
private static class Year {
private final int year;
public Year(int year) {
this.year = year;
}
private boolean isLeap() {
if (year % 400 == 0) {
return true;
}
if (year % 100 == 0) {
return false;
}
if (year % 4 == 0) {
return true;
}
return false;
}
}
}
package fr.ippon.leapyears;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
class LeapYearsTest {
@Test
void shouldNotBeLeapYearsFor2021() {
assertThat(Years.isLeap(2021)).isFalse();
}
@Test
void shouldBeLeapYearsFor2020() {
assertThat(Years.isLeap(2020)).isTrue();
}
@Test
void shouldNotBeLeapYearsFor1900() {
assertThat(Years.isLeap(1900)).isFalse();
}
@Test
void shouldBeLeapYearsFor2000() {
assertThat(Years.isLeap(2000)).isTrue();
}
}
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