From d15bce42e3b012d6d6e95502bb9257db430c7645 Mon Sep 17 00:00:00 2001 From: Sameer Varanasi Date: Fri, 4 Sep 2026 18:16:18 +0530 Subject: [PATCH] Improve Aho-Corasick multiple occurrence test --- .../strings/AhoCorasickTest.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/thealgorithms/strings/AhoCorasickTest.java b/src/test/java/com/thealgorithms/strings/AhoCorasickTest.java index 43137b358cf9..0bc52cd82e85 100644 --- a/src/test/java/com/thealgorithms/strings/AhoCorasickTest.java +++ b/src/test/java/com/thealgorithms/strings/AhoCorasickTest.java @@ -95,16 +95,21 @@ void testPatternAtEnd() { } /** - * Test searching for patterns with multiple occurrences in the input text. - * The expected sizes are 1 and 1, and the expected positions are 2 and 3 - * for the patterns "AT" and "T" respectively. - */ + * Test searching for patterns with multiple occurrences in the input text. + * The expected positions are 2 and 4 for "AT", and 3 and 5 for "T". + */ @Test void testMultipleOccurrencesOfPattern() { - // Define patterns with multiple occurrences in the text + final var searchText = "GCATATCG"; final var searchPatterns = new String[] {"AT", "T"}; - final var expected = Map.of("AT", new ArrayList<>(List.of(2)), "T", new ArrayList<>(List.of(3))); - assertEquals(expected, AhoCorasick.search(text, searchPatterns)); + + final var expected = + Map.of( + "AT", new ArrayList<>(List.of(2, 4)), + "T", new ArrayList<>(List.of(3, 5)) + ); + + assertEquals(expected, AhoCorasick.search(searchText, searchPatterns)); } /**