forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsogramTest.java
More file actions
93 lines (74 loc) · 4.77 KB
/
IsogramTest.java
File metadata and controls
93 lines (74 loc) · 4.77 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.thealgorithms.strings;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class IsogramTest {
record IsogramTestCase(String input, boolean expected) {
}
private static Stream<IsogramTestCase> isogramArrayTestData() {
return Stream.of(
// Valid isograms (only checks letters)
new IsogramTestCase("uncopyrightable", true), new IsogramTestCase("dermatoglyphics", true), new IsogramTestCase("background", true), new IsogramTestCase("python", true), new IsogramTestCase("keyboard", true), new IsogramTestCase("clipboard", true), new IsogramTestCase("flowchart", true),
new IsogramTestCase("bankruptcy", true), new IsogramTestCase("computer", true), new IsogramTestCase("algorithms", true),
// Not isograms - letters repeat
new IsogramTestCase("hello", false), new IsogramTestCase("programming", false), new IsogramTestCase("java", false), new IsogramTestCase("coffee", false), new IsogramTestCase("book", false), new IsogramTestCase("letter", false), new IsogramTestCase("mississippi", false),
new IsogramTestCase("google", false),
// Edge cases
new IsogramTestCase("", true), new IsogramTestCase("a", true), new IsogramTestCase("ab", true), new IsogramTestCase("abc", true), new IsogramTestCase("aa", false), new IsogramTestCase("abcdefghijklmnopqrstuvwxyz", true),
// Case insensitive
new IsogramTestCase("Python", true), new IsogramTestCase("BACKGROUND", true), new IsogramTestCase("Hello", false), new IsogramTestCase("PROGRAMMING", false));
}
private static Stream<IsogramTestCase> isogramLengthTestData() {
return Stream.of(
// Valid isograms (checks all characters)
new IsogramTestCase("uncopyrightable", true), new IsogramTestCase("dermatoglyphics", true), new IsogramTestCase("background", true), new IsogramTestCase("python", true), new IsogramTestCase("keyboard", true), new IsogramTestCase("clipboard", true), new IsogramTestCase("flowchart", true),
new IsogramTestCase("bankruptcy", true), new IsogramTestCase("computer", true), new IsogramTestCase("algorithms", true),
// Not isograms - characters repeat
new IsogramTestCase("hello", false), new IsogramTestCase("programming", false), new IsogramTestCase("java", false), new IsogramTestCase("coffee", false), new IsogramTestCase("book", false), new IsogramTestCase("letter", false), new IsogramTestCase("mississippi", false),
new IsogramTestCase("google", false),
// Edge cases
new IsogramTestCase("", true), new IsogramTestCase("a", true), new IsogramTestCase("ab", true), new IsogramTestCase("abc", true), new IsogramTestCase("aa", false), new IsogramTestCase("abcdefghijklmnopqrstuvwxyz", true),
// Case insensitive
new IsogramTestCase("Python", true), new IsogramTestCase("BACKGROUND", true), new IsogramTestCase("Hello", false), new IsogramTestCase("PROGRAMMING", false),
// Strings with symbols and numbers
new IsogramTestCase("abc@def", true), // all characters unique
new IsogramTestCase("test-case", false), // 't', 's', 'e' repeat
new IsogramTestCase("python123", true), // all characters unique
new IsogramTestCase("hello@123", false), // 'l' repeats
new IsogramTestCase("abc123!@#", true), // all characters unique
new IsogramTestCase("test123test", false), // 't', 'e', 's' repeat
new IsogramTestCase("1234567890", true), // all digits unique
new IsogramTestCase("12321", false), // '1' and '2' repeat
new IsogramTestCase("!@#$%^&*()", true) // all special characters unique
);
}
@ParameterizedTest
@MethodSource("isogramArrayTestData")
void testIsogramByArray(IsogramTestCase testCase) {
assertEquals(testCase.expected(), Isogram.isIsogramByArray(testCase.input()));
}
@ParameterizedTest
@MethodSource("isogramLengthTestData")
void testIsogramByLength(IsogramTestCase testCase) {
assertEquals(testCase.expected(), Isogram.isIsogramByLength(testCase.input()));
}
@Test
void testNullInputByArray() {
assertTrue(Isogram.isIsogramByArray(null));
}
@Test
void testNullInputByLength() {
assertTrue(Isogram.isIsogramByLength(null));
}
@Test
void testEmptyStringByArray() {
assertTrue(Isogram.isIsogramByArray(""));
}
@Test
void testEmptyStringByLength() {
assertTrue(Isogram.isIsogramByLength(""));
}
}