forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCountCharTest.java
More file actions
24 lines (19 loc) · 927 Bytes
/
CountCharTest.java
File metadata and controls
24 lines (19 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.thealgorithms.strings;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
class CountCharTest {
@ParameterizedTest(name = "\"{0}\" should have {1} non-whitespace characters")
@CsvSource({"'', 0", "' ', 0", "'a', 1", "'abc', 3", "'a b c', 3", "' a b c ', 3", "'\tabc\n', 3", "' a b\tc ', 3", "' 12345 ', 5", "'Hello, World!', 12"})
@DisplayName("Test countCharacters with various inputs")
void testCountCharacters(String input, int expected) {
assertEquals(expected, CountChar.countCharacters(input));
}
@Test
@DisplayName("Test countCharacters with null input")
void testCountCharactersNullInput() {
assertEquals(0, CountChar.countCharacters(null));
}
}