mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
Implement LengthOfLastWord algorithm and add JUnit tests (#7057)
* Implement LengthOfLastWord algorithm in strings package * Add JUnit tests for LengthOfLastWord algorithm * style: fix import order and spacing for clang-format
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class LengthOfLastWordTest {
|
||||
@Test
|
||||
public void testLengthOfLastWord() {
|
||||
assertEquals(5, new LengthOfLastWord().lengthOfLastWord("Hello World"));
|
||||
assertEquals(4, new LengthOfLastWord().lengthOfLastWord(" fly me to the moon "));
|
||||
assertEquals(6, new LengthOfLastWord().lengthOfLastWord("luffy is still joyboy"));
|
||||
assertEquals(5, new LengthOfLastWord().lengthOfLastWord("Hello"));
|
||||
assertEquals(0, new LengthOfLastWord().lengthOfLastWord(" "));
|
||||
assertEquals(0, new LengthOfLastWord().lengthOfLastWord(""));
|
||||
assertEquals(3, new LengthOfLastWord().lengthOfLastWord("JUST LIE "));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user