From 95b686b6befbcc90e9c9075b3d3e9046d3c3ad3b Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 1 Apr 2026 07:38:00 +0800 Subject: [PATCH] test: add LeetCode example test cases for leetcode 2828 Add test cases for Check If A String Is An Acronym Of Words using LeetCode examples: - Example 1: Valid acronym formation (["alice","bob","charlie"], s="abc") - Example 2: Length mismatch scenario (["an","apple"], s="a") - Example 3: Longer acronym case (["never","gonna","give","up","on","you"], s="ngguoy") - Update documentation to include test file link --- docs/EASY.md | 2 +- ...ckIfAStringIsAnAcronymOfWords2828Test.java | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/leetcode/easy/CheckIfAStringIsAnAcronymOfWords2828Test.java diff --git a/docs/EASY.md b/docs/EASY.md index 37bda59..f72c5e2 100644 --- a/docs/EASY.md +++ b/docs/EASY.md @@ -40,7 +40,7 @@ Total: 36 problems solved | 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks/) | [CountAsterisks2315.java](../src/main/java/com/leetcode/easy/CountAsterisks2315.java) | [CountAsterisks2315Test.java](../src/test/java/com/leetcode/easy/CountAsterisks2315Test.java) | | 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature/) | [ConvertTheTemperature2469.java](../src/main/java/com/leetcode/easy/ConvertTheTemperature2469.java) | [ConvertTheTemperature2469Test.java](../src/test/java/com/leetcode/easy/ConvertTheTemperature2469Test.java) | | 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target/) | [NumberOfEmployeesWhoMetTheTarget2798.java](../src/main/java/com/leetcode/easy/NumberOfEmployeesWhoMetTheTarget2798.java) | [NumberOfEmployeesWhoMetTheTarget2798Test.java](../src/test/java/com/leetcode/easy/NumberOfEmployeesWhoMetTheTarget2798Test.java) | -| 2828 | [Check If A String Is An Acronym Of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words/) | [CheckIfAStringIsAnAcronymOfWords2828.java](../src/main/java/com/leetcode/easy/CheckIfAStringIsAnAcronymOfWords2828.java) | | +| 2828 | [Check If A String Is An Acronym Of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words/) | [CheckIfAStringIsAnAcronymOfWords2828.java](../src/main/java/com/leetcode/easy/CheckIfAStringIsAnAcronymOfWords2828.java) | [CheckIfAStringIsAnAcronymOfWords2828Test.java](../src/test/java/com/leetcode/easy/CheckIfAStringIsAnAcronymOfWords2828Test.java) | | 3289 | [The Two Sneaky Numbers of Digitville](https://leetcode.com/problems/the-two-sneaky-numbers-of-digitville/) | [TheTwoSneakyNumbersOfDigitville3289.java](../src/main/java/com/leetcode/easy/TheTwoSneakyNumbersOfDigitville3289.java) | [TheTwoSneakyNumbersOfDigitville3289Test.java](../src/test/java/com/leetcode/easy/TheTwoSneakyNumbersOfDigitville3289Test.java) | --- diff --git a/src/test/java/com/leetcode/easy/CheckIfAStringIsAnAcronymOfWords2828Test.java b/src/test/java/com/leetcode/easy/CheckIfAStringIsAnAcronymOfWords2828Test.java new file mode 100644 index 0000000..ac9d44a --- /dev/null +++ b/src/test/java/com/leetcode/easy/CheckIfAStringIsAnAcronymOfWords2828Test.java @@ -0,0 +1,50 @@ +package com.leetcode.easy; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CheckIfAStringIsAnAcronymOfWords2828Test { + private CheckIfAStringIsAnAcronymOfWords2828 solution; + + @BeforeEach + void setUp() { + solution = new CheckIfAStringIsAnAcronymOfWords2828(); + } + + @Test + void testIsAcronym_Example1_ValidAcronym() { + // Input: words = ["alice","bob","charlie"], s = "abc" + // First characters: 'a', 'b', 'c' -> "abc" + List words = Arrays.asList("alice", "bob", "charlie"); + String s = "abc"; + + assertTrue(solution.isAcronym(words, s)); + } + + @Test + void testIsAcronym_Example2_LengthMismatch() { + // Input: words = ["an","apple"], s = "a" + // First characters: 'a', 'a' -> "aa" (length 2) + // s = "a" (length 1), so cannot match + List words = Arrays.asList("an", "apple"); + String s = "a"; + + assertFalse(solution.isAcronym(words, s)); + } + + @Test + void testIsAcronym_Example3_LongAcronym() { + // Input: words = ["never","gonna","give","up","on","you"], s = "ngguoy" + // First characters: 'n', 'g', 'g', 'u', 'o', 'y' -> "ngguoy" + List words = Arrays.asList("never", "gonna", "give", "up", "on", "you"); + String s = "ngguoy"; + + assertTrue(solution.isAcronym(words, s)); + } +}