Skip to content

Commit

Permalink
Add new Wordle Kata and unfinished solutions module.
Browse files Browse the repository at this point in the history
Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
  • Loading branch information
donraab committed Aug 13, 2023
1 parent 85c57c8 commit 2689630
Show file tree
Hide file tree
Showing 12 changed files with 483 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pom-jdk17.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<module>record-kata-solutions</module>
<module>haiku-kata</module>
<module>haiku-kata-solutions</module>
<module>wordle-kata</module>
<module>wordle-kata-solutions</module>
<module>pom.xml</module>
</modules>

Expand Down
48 changes: 48 additions & 0 deletions wordle-kata-solutions/pom.xml
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>
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;
}
}
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;
}
}
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"));
}
}
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"));
}
}
27 changes: 27 additions & 0 deletions wordle-kata/README.md
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)
48 changes: 48 additions & 0 deletions wordle-kata/pom.xml
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>
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;
}
}
Loading

0 comments on commit 2689630

Please sign in to comment.