From 30a5cddce068ec790c81e886524e14c14df21117 Mon Sep 17 00:00:00 2001 From: Graham Cox Date: Thu, 21 Mar 2024 05:34:48 +0000 Subject: [PATCH] Updates for BAEL-7496 (#16150) * Moved vigenere cipher code to a new module * New test case for encoding and decoding together --- .../algorithms-miscellaneous-8/pom.xml | 16 ++++++++++++ .../algorithms/vigenere/VigenereCipher.java | 0 .../vigenere/VigenereCipherUnitTest.java | 25 ++++++++++++++----- algorithms-modules/pom.xml | 3 ++- 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 algorithms-modules/algorithms-miscellaneous-8/pom.xml rename algorithms-modules/{algorithms-miscellaneous-7 => algorithms-miscellaneous-8}/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipher.java (100%) rename algorithms-modules/{algorithms-miscellaneous-7 => algorithms-miscellaneous-8}/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipherUnitTest.java (68%) diff --git a/algorithms-modules/algorithms-miscellaneous-8/pom.xml b/algorithms-modules/algorithms-miscellaneous-8/pom.xml new file mode 100644 index 0000000000..29163c5de7 --- /dev/null +++ b/algorithms-modules/algorithms-miscellaneous-8/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + algorithms-miscellaneous-8 + 0.0.1-SNAPSHOT + algorithms-miscellaneous-8 + + + com.baeldung + algorithms-modules + 1.0.0-SNAPSHOT + + + diff --git a/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipher.java b/algorithms-modules/algorithms-miscellaneous-8/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipher.java similarity index 100% rename from algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipher.java rename to algorithms-modules/algorithms-miscellaneous-8/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipher.java diff --git a/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipherUnitTest.java b/algorithms-modules/algorithms-miscellaneous-8/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipherUnitTest.java similarity index 68% rename from algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipherUnitTest.java rename to algorithms-modules/algorithms-miscellaneous-8/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipherUnitTest.java index 0e61e9c42e..ea463caa08 100644 --- a/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipherUnitTest.java +++ b/algorithms-modules/algorithms-miscellaneous-8/src/test/java/com/baeldung/algorithms/vigenere/VigenereCipherUnitTest.java @@ -24,17 +24,17 @@ public class VigenereCipherUnitTest { @Test void encodeArticleTitle() { VigenereCipher cipher = new VigenereCipher(); - String output = cipher.encode("VEGENERE CIPHER IN JAVA", "BAELDUNG"); + String output = cipher.encode("VIGENERE CIPHER IN JAVA", "BAELDUNG"); - Assertions.assertEquals("XFLQRZFL EJUTIM WU LBAM", output); + Assertions.assertEquals("XJLQRZFL EJUTIM WU LBAM", output); } @Test void encodeArticleTitleMoreCharacters() { VigenereCipher cipher = new VigenereCipher("ABCDEFGHIJKLMNOPQRSTUVWXYZ "); - String output = cipher.encode("VEGENERE CIPHER IN JAVA", "BAELDUNG"); + String output = cipher.encode("VIGENERE CIPHER IN JAVA", "BAELDUNG"); - Assertions.assertEquals("XFLQRZELBDNALZEGKOEVEPO", output); + Assertions.assertEquals("XJLQRZELBDNALZEGKOEVEPO", output); } @Test @@ -56,8 +56,21 @@ public class VigenereCipherUnitTest { @Test void decodeArticleTitleMoreCharacters() { VigenereCipher cipher = new VigenereCipher("ABCDEFGHIJKLMNOPQRSTUVWXYZ "); - String output = cipher.decode("XFLQRZELBDNALZEGKOEVEPO", "BAELDUNG"); + String output = cipher.decode("XJLQRZELBDNALZEGKOEVEPO", "BAELDUNG"); - Assertions.assertEquals("VEGENERE CIPHER IN JAVA", output); + Assertions.assertEquals("VIGENERE CIPHER IN JAVA", output); + } + + @Test + void encodeDecodeBaeldung() { + VigenereCipher cipher = new VigenereCipher(); + + String input = "BAELDUNG"; + String key = "HELLO"; + + String encoded = cipher.encode(input, key); + String decoded = cipher.decode(encoded, key); + + Assertions.assertEquals(input, decoded); } } diff --git a/algorithms-modules/pom.xml b/algorithms-modules/pom.xml index fda8eea0e7..d3f27f4fa8 100644 --- a/algorithms-modules/pom.xml +++ b/algorithms-modules/pom.xml @@ -22,6 +22,7 @@ algorithms-miscellaneous-5 algorithms-miscellaneous-6 algorithms-miscellaneous-7 + algorithms-miscellaneous-8 algorithms-searching algorithms-sorting algorithms-sorting-2 @@ -34,4 +35,4 @@ 1.0.1 - \ No newline at end of file +