-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b87e70f
commit 70ed7c1
Showing
7 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## Day 17: One and thousand tests. | ||
|
||
Today, you are recovering at the nearby harbor to | ||
replenish your ship before the last week on the journey. | ||
|
||
Challenges are not going to lack and in order to face | ||
them, new skills are required. | ||
|
||
Today's exercise is about transforming your test in | ||
a way you've not done before. | ||
|
||
However, nothing is simple. You've got to think | ||
of your tests and your code differently. | ||
|
||
_What characteristic does my code have?_ | ||
|
||
> **Day 17: Design one test that has the impact of thousands.** | ||
May your crafting journey bring you to new heights! | ||
|
||
- <u>💡HINT:</u> What PBT stands for. | ||
|
||
![snippet of the day](snippet.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
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> | ||
<groupId>com.advent-of-craft</groupId> | ||
<artifactId>advent-of-craft2023</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>fizzbuzz-part5</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<vavr.version>0.10.4</vavr.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.vavr</groupId> | ||
<artifactId>vavr</artifactId> | ||
<version>${vavr.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.vavr</groupId> | ||
<artifactId>vavr-test</artifactId> | ||
<version>${vavr.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package games; | ||
|
||
import io.vavr.collection.LinkedHashMap; | ||
import io.vavr.collection.Map; | ||
import io.vavr.control.Option; | ||
|
||
import static io.vavr.control.Option.none; | ||
import static io.vavr.control.Option.some; | ||
|
||
public class FizzBuzz { | ||
public static final int MIN = 1; | ||
public static final int MAX = 100; | ||
private static final Map<Integer, String> mapping = LinkedHashMap.of( | ||
15, "FizzBuzz", | ||
3, "Fizz", | ||
5, "Buzz" | ||
); | ||
|
||
public static Option<String> convert(int input) { | ||
return isOutOfRange(input) | ||
? none() | ||
: some(convertSafely(input)); | ||
} | ||
|
||
private static String convertSafely(Integer input) { | ||
return mapping | ||
.find(p -> is(p._1, input)) | ||
.map(p -> p._2) | ||
.getOrElse(input.toString()); | ||
} | ||
|
||
private static boolean is(Integer divisor, Integer input) { | ||
return input % divisor == 0; | ||
} | ||
|
||
private static boolean isOutOfRange(Integer input) { | ||
return input < MIN || input > MAX; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package games; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static io.vavr.API.Some; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class FizzBuzzTests { | ||
private static Stream<Arguments> validInputs() { | ||
return Stream.of( | ||
Arguments.of(1, "1"), | ||
Arguments.of(67, "67"), | ||
Arguments.of(82, "82"), | ||
Arguments.of(3, "Fizz"), | ||
Arguments.of(66, "Fizz"), | ||
Arguments.of(99, "Fizz"), | ||
Arguments.of(5, "Buzz"), | ||
Arguments.of(50, "Buzz"), | ||
Arguments.of(85, "Buzz"), | ||
Arguments.of(15, "FizzBuzz"), | ||
Arguments.of(30, "FizzBuzz"), | ||
Arguments.of(45, "FizzBuzz") | ||
); | ||
} | ||
|
||
private static Stream<Arguments> invalidInputs() { | ||
return Stream.of( | ||
Arguments.of(0), | ||
Arguments.of(-1), | ||
Arguments.of(101) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("validInputs") | ||
void parse_successfully_numbers_between_1_and_100(int input, String expectedResult) { | ||
assertThat(FizzBuzz.convert(input)) | ||
.isEqualTo(Some(expectedResult)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("invalidInputs") | ||
void parse_fail_for_numbers_out_of_range(int input) { | ||
assertThat(FizzBuzz.convert(input).isEmpty()) | ||
.isTrue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters