Skip to content

Commit 7068e54

Browse files
committed
Add JUnit tests for LengthOfLastWord algorithm
1 parent d85c129 commit 7068e54

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
package com.thealgorithms.strings;
22

3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
37
public class LengthOfLastWordTest {
8+
@Test
9+
public void testLengthOfLastWord() {
10+
assertEquals(5, new LengthOfLastWord().lengthOfLastWord("Hello World"));
11+
assertEquals(4, new LengthOfLastWord().lengthOfLastWord(" fly me to the moon "));
12+
assertEquals(6, new LengthOfLastWord().lengthOfLastWord("luffy is still joyboy"));
13+
assertEquals(5, new LengthOfLastWord().lengthOfLastWord("Hello"));
14+
assertEquals(0, new LengthOfLastWord().lengthOfLastWord(" "));
15+
assertEquals(0, new LengthOfLastWord().lengthOfLastWord(""));
16+
assertEquals(3, new LengthOfLastWord().lengthOfLastWord("JUST LIE "));
17+
}
418
}

0 commit comments

Comments
 (0)