feat: add tests for bonus exercises
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class TestDates {
|
||||
static BonusExercises ex;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
ex = new BonusExercises();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDates0() {
|
||||
String input = "Today is 12/09/2023.";
|
||||
String expected = "12/09/2023";
|
||||
assertEquals(expected, ex.findDate(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDates1() {
|
||||
String input = "Meeting: 2024-07-15 at noon.";
|
||||
String expected = "2024-07-15";
|
||||
assertEquals(expected, ex.findDate(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDates2() {
|
||||
String input = "No date here.";
|
||||
assertNull(ex.findDate(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDates3() {
|
||||
String input = "Release date will be 2025/01/01 (hopefully) at midnight";
|
||||
String expected = "2025/01/01";
|
||||
assertEquals(expected, ex.findDate(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDates4() {
|
||||
String input = "Meet me at 45/12/2023.";
|
||||
assertNull(ex.findDate(input));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestEmail {
|
||||
static BonusExercises ex;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
ex = new BonusExercises();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmail0() {
|
||||
assertTrue(ex.validateEmail("john.doe@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmail1() {
|
||||
assertFalse(ex.validateEmail("hello world@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmail2() {
|
||||
assertTrue(ex.validateEmail("alice_bob123@research-lab.co.uk"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmail3() {
|
||||
assertFalse(ex.validateEmail("user@ex_ample.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmail4() {
|
||||
assertFalse(ex.validateEmail("user.@-example.com"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestPalindromes {
|
||||
static BonusExercises ex;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
ex = new BonusExercises();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPalindrome0() {
|
||||
String input = "madam racecar level";
|
||||
|
||||
// palindrome words
|
||||
List<String> expected = new ArrayList<>();
|
||||
expected.add("madam");
|
||||
expected.add("racecar");
|
||||
expected.add("level");
|
||||
|
||||
assertEquals(expected, ex.findPalindromes(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPalindrome1() {
|
||||
String input = "hello world";
|
||||
|
||||
// palindrome words
|
||||
List<String> expected = new ArrayList<>();
|
||||
|
||||
assertEquals(expected, ex.findPalindromes(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPalindrome2() {
|
||||
String input = "Step on no pets";
|
||||
|
||||
// palindrome words
|
||||
List<String> expected = new ArrayList<>();
|
||||
|
||||
assertEquals(expected, ex.findPalindromes(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPalindrome3() {
|
||||
String input = """
|
||||
Madam, did you see Bob running? I asked Kayak and radar to wait at the civic center.\s
|
||||
The level of security was high, but I noticed a racecar driving past. A deed was done in the noon,\s
|
||||
and many said it was a referable situation.
|
||||
""";
|
||||
|
||||
// palindrome words
|
||||
List<String> expected = new ArrayList<>();
|
||||
expected.add("Madam");
|
||||
expected.add("did");
|
||||
expected.add("Bob");
|
||||
expected.add("Kayak");
|
||||
expected.add("radar");
|
||||
expected.add("civic");
|
||||
expected.add("level");
|
||||
expected.add("racecar");
|
||||
expected.add("deed");
|
||||
expected.add("noon");
|
||||
|
||||
assertEquals(expected, ex.findPalindromes(input));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestPasswords {
|
||||
static BonusExercises ex;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
ex = new BonusExercises();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPasswords0() {
|
||||
assertEquals(1, ex.findValidPasswords("P@ssw0rd is my secret"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPasswords1() {
|
||||
assertEquals(3, ex.findValidPasswords("""
|
||||
Alice's new password is SecureP@ss1 but Bob still uses weakpass123.\s
|
||||
Charlie upgraded to Ultra_Strong99! while David set his to Admin123 (which is not secure).\s
|
||||
Their boss? He went with SuperSafe#42 and banned "password123"."""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPasswords2() {
|
||||
assertEquals(4, ex.findValidPasswords("""
|
||||
[09:15] Dev1: Just changed my password to CodeMaster@2025. \s
|
||||
[09:17] Dev2: Haha, mine's still qwerty123, no special chars. \s
|
||||
[09:19] Dev3: I use GitHubSuper#1 but need a better one. \s
|
||||
[09:21] Dev4: AdminPass42! is good, right? \s
|
||||
[09:23] Dev5: No, too simple. I switched to UltraSecure$99 last week. \s
|
||||
[09:25] Dev6: Wait, are we sharing passwords here? \uD83D\uDE02 \s
|
||||
"""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPasswords3() {
|
||||
assertEquals(0, ex.findValidPasswords("NoSpecial1 WeakPass! NoDigits@"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user