forked from CSC207-2025F-UofT/m5-regex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainTest.java
More file actions
137 lines (110 loc) · 3.65 KB
/
MainTest.java
File metadata and controls
137 lines (110 loc) · 3.65 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package regex;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class MainTest {
// helpers to ensure tests initially fail for the given starter code
void starterTestPasswordValidator() {
assertFalse(Main.checkForPassword("REPLACE WITH CORRECT REGEX", 6));
}
void starterTestExtractEmails() {
assertTrue(Main.extractEmails("REPLACE WITH CORRECT REGEX").isEmpty());
}
void starterTestCheckForDoubles() {
assertFalse(Main.checkForDoubles("replace with correct regex"));
}
// Tests for checkForPassword
@Test
void testPasswordValid() {
assertTrue(Main.checkForPassword("Abc123", 6));
assertTrue(Main.checkForPassword("XyZ9abc", 6));
}
@Test
void testPasswordTooShort() {
starterTestPasswordValidator();
assertFalse(Main.checkForPassword("Ab1", 6));
}
@Test
void testPasswordMissingUppercase() {
starterTestPasswordValidator();
assertFalse(Main.checkForPassword("abc123", 6));
}
@Test
void testPasswordMissingLowercase() {
starterTestPasswordValidator();
assertFalse(Main.checkForPassword("ABC123", 6));
}
@Test
void testPasswordMissingDigit() {
starterTestPasswordValidator();
assertFalse(Main.checkForPassword("Abcdef", 6));
}
@Test
void testPasswordNull() {
assertFalse(Main.checkForPassword(null, 6));
}
@Test
void testPasswordValidWithDifferentMinLength() {
// minLength = 8, password meets requirements and is long enough
assertTrue(Main.checkForPassword("Abcdef12", 8));
// minLength = 8, password meets character requirements but is too short
assertFalse(Main.checkForPassword("Abc123", 8));
}
// Tests for extractEmails
@Test
void testExtractEmailsValid() {
String input = "Contact me at john@mail.utoronto.ca or jane@utoronto.ca.";
List<String> emails = Main.extractEmails(input);
assertEquals(List.of("john@mail.utoronto.ca", "jane@utoronto.ca"), emails);
}
@Test
void testExtractEmailsInvalidDomain() {
starterTestExtractEmails();
String input = "Email: bob@gmail.com";
List<String> emails = Main.extractEmails(input);
assertTrue(emails.isEmpty());
}
@Test
void testExtractEmailsEmptyString() {
starterTestExtractEmails();
assertTrue(Main.extractEmails("").isEmpty());
}
@Test
void testExtractEmailsNull() {
assertTrue(Main.extractEmails(null).isEmpty());
}
@Test
void testExtractEmailsDuplicates() {
String input = "john@mail.utoronto.ca john@mail.utoronto.ca";
List<String> emails = Main.extractEmails(input);
assertEquals(List.of("john@mail.utoronto.ca", "john@mail.utoronto.ca"), emails);
}
// Tests for checkForDoubles
@Test
void testCheckForDoublesTrueOne() {
assertTrue(Main.checkForDoubles("Amazing Apple"));
}
@Test
void testCheckForDoublesTrueTwo() {
assertTrue(Main.checkForDoubles("ABBA"));
}
@Test
void testCheckForDoublesFalseOne() {
starterTestCheckForDoubles();
assertFalse(Main.checkForDoubles("Hello World"));
}
@Test
void testCheckForDoublesFalseTwo() {
starterTestCheckForDoubles();
assertFalse(Main.checkForDoubles("abc def"));
}
@Test
void testCheckForDoublesNull() {
assertFalse(Main.checkForDoubles(null));
}
@Test
void testCheckForDoublesEdgeCaseSingleCapital() {
starterTestCheckForDoubles();
assertFalse(Main.checkForDoubles("A"));
}
}