Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathAlphabeticalTest.java
More file actions
Latest commit
45 lines (37 loc) · 2.35 KB
/
Copy pathAlphabeticalTest.java
File metadata and controls
45 lines (37 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
packagecom.thealgorithms.strings;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.params.provider.Arguments.arguments;
importjava.util.stream.Stream;
importorg.junit.jupiter.api.DisplayName;
importorg.junit.jupiter.api.Test;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
@DisplayName("Alphabetical.isAlphabetical()")
classAlphabeticalTest {
staticStream<Arguments> testCases() {
// Workaround for SpotBugs false positive (NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION)
// due to JUnit Arguments.of(Object...) auto-boxing
returnStream.of(arguments("", Boolean.FALSE, "Should return false for empty string"), arguments(" ", Boolean.FALSE, "Should return false for blank string"), arguments("a1b2", Boolean.FALSE, "Should return false when string contains numbers"),
arguments("abc!DEF", Boolean.FALSE, "Should return false when string contains symbols"), arguments("#abc", Boolean.FALSE, "Should return false when first character is not a letter"), arguments("abc", Boolean.TRUE, "Should return true for non-decreasing order"),
arguments("aBcD", Boolean.TRUE, "Should return true for mixed case increasing sequence"), arguments("a", Boolean.TRUE, "Should return true for single letter"), arguments("'", Boolean.FALSE, "Should return false for single symbol"),
arguments("aabbcc", Boolean.TRUE, "Should return true for repeated letters"), arguments("cba", Boolean.FALSE, "Should return false when order decreases"), arguments("abzba", Boolean.FALSE, "Should return false when middle breaks order"));
}
privatevoidassertAlphabetical(Stringinput, booleanexpected, Stringmessage) {
// Arrange & Act
booleanresult = Alphabetical.isAlphabetical(input);
// Assert
assertEquals(expected, result, message);
}
@Test
@DisplayName("Should return false for null input")
voidnullInputTest() {
assertAlphabetical(null, false, "Should return false for null input");
}
@ParameterizedTest(name = "{2}")
@MethodSource("testCases")
@DisplayName("Alphabetical cases")
voidisAlphabeticalTest(Stringinput, booleanexpected, Stringmessage) {
assertAlphabetical(input, expected, message);
}
}