forked from eclipse/eclipse-collections-kata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Wordle Kata and unfinished solutions module.
Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
- Loading branch information
Showing
12 changed files
with
483 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,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2023 The Bank of New York Mellon. | ||
~ All rights reserved. This program and the accompanying materials | ||
~ are made available under the terms of the Eclipse Public License v1.0 | ||
~ and Eclipse Distribution License v. 1.0 which accompany this distribution. | ||
~ The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
~ and the Eclipse Distribution License is available at | ||
~ http://www.eclipse.org/org/documents/edl-v10.php. | ||
--> | ||
|
||
<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"> | ||
<parent> | ||
<artifactId>eclipse-collections-kata-parent-17</artifactId> | ||
<groupId>org.eclipse.collections.kata</groupId> | ||
<version>7.1.0-SNAPSHOT</version> | ||
<relativePath>../pom-jdk17.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>wordle-kata-solutions</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections-testutils</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
48 changes: 48 additions & 0 deletions
48
wordle-kata-solutions/src/main/java/org/eclipse/collections/wordlekata/WordleEC.java
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,48 @@ | ||
/* | ||
* Copyright (c) 2023 The Bank of New York Mellon. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v. 1.0 which accompany this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*/ | ||
|
||
package org.eclipse.collections.wordlekata; | ||
|
||
import org.eclipse.collections.api.bag.primitive.MutableCharBag; | ||
import org.eclipse.collections.impl.factory.Strings; | ||
import org.eclipse.collections.impl.factory.primitive.CharBags; | ||
import org.eclipse.collections.impl.string.immutable.CharAdapter; | ||
|
||
public record WordleEC(String string) | ||
{ | ||
public WordleEC(String string) | ||
{ | ||
this.string = string.toLowerCase(); | ||
} | ||
|
||
/** | ||
* TODO - Implement the guess method using Eclipse Collections so tests in WordleECTest pass. | ||
* <p/> | ||
* Hint: Look at Strings.asChars(), CharAdapter, CharBags, MutableCharBag | ||
* <p/> | ||
* Rules: | ||
* <p/> | ||
* <p><ul> | ||
* <li>If a letter in the guess String doesn’t match a letter in the hidden word, | ||
* then replace the character in the output with “.” | ||
* <li>If a letter in the guess String matches a letter in the hidden word and the letter is in the same position, | ||
* then replace the character with an uppercase letter. | ||
* <li>If a letter in the guess String matches a letter in the hidden word but the letter is in a different position, | ||
* then replace the character with a lowercase letter. | ||
* <li>If a letter matches, but appears more times in the guess String than in the hidden word, | ||
* then replace the additional characters in the output with a “.”. | ||
* </ul></p> | ||
*/ | ||
public String guess(String guess) | ||
{ | ||
// TODO - Replace null with the code needed to satisfy the rules above. | ||
return null; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
wordle-kata-solutions/src/main/java/org/eclipse/collections/wordlekata/WordleJDK.java
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,43 @@ | ||
/* | ||
* Copyright (c) 2023 The Bank of New York Mellon. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v. 1.0 which accompany this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*/ | ||
|
||
package org.eclipse.collections.wordlekata; | ||
|
||
public record WordleJDK(String string) | ||
{ | ||
public WordleJDK(String string) | ||
{ | ||
this.string = string.toLowerCase(); | ||
} | ||
|
||
/** | ||
* TODO - Implement the guess method using Java Streams so tests in WordleJDKTest pass. | ||
* <p/> | ||
* Hint: Look at String.chars() and methods on IntStream. | ||
* <p/> | ||
* Rules: | ||
* <p/> | ||
* <p><ul> | ||
* <li>If a letter in the guess String doesn’t match a letter in the hidden word, | ||
* then replace the character in the output with “.” | ||
* <li>If a letter in the guess String matches a letter in the hidden word and the letter is in the same position, | ||
* then replace the character with an uppercase letter. | ||
* <li>If a letter in the guess String matches a letter in the hidden word but the letter is in a different position, | ||
* then replace the character with a lowercase letter. | ||
* <li>If a letter matches, but appears more times in the guess String than in the hidden word, | ||
* then replace the additional characters in the output with a “.”. | ||
* </ul></p> | ||
*/ | ||
public String guess(String guess) | ||
{ | ||
// TODO - Replace null with the code needed to satisfy the rules above. | ||
return null; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
wordle-kata-solutions/src/test/java/org/eclipse/collections/wordlekata/WordleECTest.java
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,44 @@ | ||
/* | ||
* Copyright (c) 2023 The Bank of New York Mellon. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v. 1.0 which accompany this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*/ | ||
|
||
package org.eclipse.collections.wordlekata; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class WordleECTest | ||
{ | ||
// @Test // Uncomment once guess is implemented for WordleEC | ||
public void matchWordWithGuess() | ||
{ | ||
Assertions.assertEquals(".....", new WordleEC("aaaaa").guess("bbbbb")); | ||
Assertions.assertEquals("A....", new WordleEC("aaaaa").guess("abbbb")); | ||
Assertions.assertEquals(".A...", new WordleEC("aaaaa").guess("babbb")); | ||
Assertions.assertEquals("..A..", new WordleEC("aaaaa").guess("bbabb")); | ||
Assertions.assertEquals("...A.", new WordleEC("aaaaa").guess("bbbab")); | ||
Assertions.assertEquals("....A", new WordleEC("aaaaa").guess("bbbba")); | ||
|
||
Assertions.assertEquals(".a...", new WordleEC("abbbb").guess("caccc")); | ||
Assertions.assertEquals("..a..", new WordleEC("abbbb").guess("ccacc")); | ||
Assertions.assertEquals("...a.", new WordleEC("abbbb").guess("cccac")); | ||
Assertions.assertEquals("....a", new WordleEC("abbbb").guess("cccca")); | ||
|
||
Assertions.assertEquals("A....", new WordleEC("abbbb").guess("accca")); | ||
Assertions.assertEquals("A....", new WordleEC("abbbb").guess("accaa")); | ||
Assertions.assertEquals("A..a.", new WordleEC("aabbb").guess("accaa")); | ||
Assertions.assertEquals("AA...", new WordleEC("aabbb").guess("aacaa")); | ||
Assertions.assertEquals("...aa", new WordleEC("aabbb").guess("cccaa")); | ||
|
||
Assertions.assertEquals("..A..", new WordleEC("bbabb").guess("aaaaa")); | ||
|
||
Assertions.assertEquals("AAAAA", new WordleEC("aaaaa").guess("aaaaa")); | ||
Assertions.assertEquals("BRAVO", new WordleEC("bravo").guess("bravo")); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
wordle-kata-solutions/src/test/java/org/eclipse/collections/wordlekata/WordleJDKTest.java
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,44 @@ | ||
/* | ||
* Copyright (c) 2023 The Bank of New York Mellon. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v. 1.0 which accompany this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*/ | ||
|
||
package org.eclipse.collections.wordlekata; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class WordleJDKTest | ||
{ | ||
// @Test // Uncomment once guess is implemented for WordleJDK | ||
public void matchWordWithGuess() | ||
{ | ||
Assertions.assertEquals(".....", new WordleJDK("aaaaa").guess("bbbbb")); | ||
Assertions.assertEquals("A....", new WordleJDK("aaaaa").guess("abbbb")); | ||
Assertions.assertEquals(".A...", new WordleJDK("aaaaa").guess("babbb")); | ||
Assertions.assertEquals("..A..", new WordleJDK("aaaaa").guess("bbabb")); | ||
Assertions.assertEquals("...A.", new WordleJDK("aaaaa").guess("bbbab")); | ||
Assertions.assertEquals("....A", new WordleJDK("aaaaa").guess("bbbba")); | ||
|
||
Assertions.assertEquals(".a...", new WordleJDK("abbbb").guess("caccc")); | ||
Assertions.assertEquals("..a..", new WordleJDK("abbbb").guess("ccacc")); | ||
Assertions.assertEquals("...a.", new WordleJDK("abbbb").guess("cccac")); | ||
Assertions.assertEquals("....a", new WordleJDK("abbbb").guess("cccca")); | ||
|
||
Assertions.assertEquals("A....", new WordleJDK("abbbb").guess("accca")); | ||
Assertions.assertEquals("A....", new WordleJDK("abbbb").guess("accaa")); | ||
Assertions.assertEquals("A..a.", new WordleJDK("aabbb").guess("accaa")); | ||
Assertions.assertEquals("AA...", new WordleJDK("aabbb").guess("aacaa")); | ||
Assertions.assertEquals("...aa", new WordleJDK("aabbb").guess("cccaa")); | ||
|
||
Assertions.assertEquals("..A..", new WordleJDK("bbabb").guess("aaaaa")); | ||
|
||
Assertions.assertEquals("AAAAA", new WordleJDK("aaaaa").guess("aaaaa")); | ||
Assertions.assertEquals("BRAVO", new WordleJDK("bravo").guess("bravo")); | ||
} | ||
} |
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,27 @@ | ||
<!-- | ||
~ Copyright (c) 2023 The Bank of New York Mellon. | ||
~ All rights reserved. This program and the accompanying materials | ||
~ are made available under the terms of the Eclipse Public License v1.0 | ||
~ and Eclipse Distribution License v. 1.0 which accompany this distribution. | ||
~ The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
~ and the Eclipse Distribution License is available at | ||
~ http://www.eclipse.org/org/documents/edl-v10.php. | ||
--> | ||
# **What is the Wordle Kata?** | ||
The Wordle Kata is an advanced Code Kata with a set exercises that a developer can complete to familiarize themselves with the String APIs available in [Eclipse Collections](https://github.com/eclipse/eclipse-collections), as well as the chars() method available on the String class for the JDK section of the kata. | ||
|
||
The domain of the Wordle Kata includes the `WordleEC` and `WordleJDK` classes. The kata uses advanced features like Java Records which are available in JDK 17. | ||
|
||
This kata is based on the following blog by Donald Raab: [A Wordle JLDD Kata Challenge](https://medium.com/oracledevs/a-wordle-jldd-kata-challenge-b6fb1c89d8eb?source=friends_link&sk=0a8b6f949515cdc36fe7a7fff24097c6). | ||
The blog was also covered in JEP Café Episode #10 on YouTube by José Paumard: [Leverage Java 17 New Features to Create Your Wordle Checker](https://www.youtube.com/watch?v=5--tDQIMqhY). | ||
|
||
# Getting Started | ||
|
||
Run the tests for specific frameworks in the tests folder. | ||
|
||
* [Eclipse Collections Tests](./src/test/java/org/eclipse/collections/wordlekata/WordleECTest.java) | ||
* [Java Streams Tests](./src/test/java/org/eclipse/collections/wordlekata/WordleJDKTest.java) | ||
|
||
You will need to change code in the domain classes to get the tests to pass. | ||
|
||
* [Domain Folder](./src/main/java/org/eclipse/collections/wordlekata) |
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,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2023 The Bank of New York Mellon. | ||
~ All rights reserved. This program and the accompanying materials | ||
~ are made available under the terms of the Eclipse Public License v1.0 | ||
~ and Eclipse Distribution License v. 1.0 which accompany this distribution. | ||
~ The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
~ and the Eclipse Distribution License is available at | ||
~ http://www.eclipse.org/org/documents/edl-v10.php. | ||
--> | ||
|
||
<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"> | ||
<parent> | ||
<artifactId>eclipse-collections-kata-parent-17</artifactId> | ||
<groupId>org.eclipse.collections.kata</groupId> | ||
<version>7.1.0-SNAPSHOT</version> | ||
<relativePath>../pom-jdk17.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>wordle-kata</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections-testutils</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
48 changes: 48 additions & 0 deletions
48
wordle-kata/src/main/java/org/eclipse/collections/wordlekata/WordleEC.java
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,48 @@ | ||
/* | ||
* Copyright (c) 2023 The Bank of New York Mellon. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v. 1.0 which accompany this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*/ | ||
|
||
package org.eclipse.collections.wordlekata; | ||
|
||
import org.eclipse.collections.api.bag.primitive.MutableCharBag; | ||
import org.eclipse.collections.impl.factory.Strings; | ||
import org.eclipse.collections.impl.factory.primitive.CharBags; | ||
import org.eclipse.collections.impl.string.immutable.CharAdapter; | ||
|
||
public record WordleEC(String string) | ||
{ | ||
public WordleEC(String string) | ||
{ | ||
this.string = string.toLowerCase(); | ||
} | ||
|
||
/** | ||
* TODO - Implement the guess method using Eclipse Collections so tests in WordleECTest pass. | ||
* <p/> | ||
* Hint: Look at Strings.asChars(), CharAdapter, CharBags, MutableCharBag | ||
* <p/> | ||
* Rules: | ||
* <p/> | ||
* <p><ul> | ||
* <li>If a letter in the guess String doesn’t match a letter in the hidden word, | ||
* then replace the character in the output with “.” | ||
* <li>If a letter in the guess String matches a letter in the hidden word and the letter is in the same position, | ||
* then replace the character with an uppercase letter. | ||
* <li>If a letter in the guess String matches a letter in the hidden word but the letter is in a different position, | ||
* then replace the character with a lowercase letter. | ||
* <li>If a letter matches, but appears more times in the guess String than in the hidden word, | ||
* then replace the additional characters in the output with a “.”. | ||
* </ul></p> | ||
*/ | ||
public String guess(String guess) | ||
{ | ||
// TODO - Replace null with the code needed to satisfy the rules above. | ||
return null; | ||
} | ||
} |
Oops, something went wrong.