-
Notifications
You must be signed in to change notification settings - Fork 21.1k
Expand file tree
/
Copy pathAccountMergeTest.java
More file actions
61 lines (42 loc) · 2.29 KB
/
AccountMergeTest.java
File metadata and controls
61 lines (42 loc) · 2.29 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
package com.thealgorithms.graph;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import org.junit.jupiter.api.Test;
class AccountMergeTest {
@Test
void testMergeAccountsWithSharedEmails() {
List<List<String>> accounts = List.of(List.of("abc", "abc@mail.com", "abx@mail.com"), List.of("abc", "abc@mail.com", "aby@mail.com"), List.of("Mary", "mary@mail.com"), List.of("John", "johnnybravo@mail.com"));
List<List<String>> merged = AccountMerge.mergeAccounts(accounts);
List<List<String>> expected = List.of(List.of("John", "johnnybravo@mail.com"), List.of("Mary", "mary@mail.com"), List.of("abc", "abc@mail.com", "abx@mail.com", "aby@mail.com"));
assertEquals(expected, merged);
}
@Test
void testAccountsWithSameNameButNoSharedEmailStaySeparate() {
List<List<String>> accounts = List.of(List.of("Alex", "alex1@mail.com"), List.of("Alex", "alex2@mail.com"));
List<List<String>> merged = AccountMerge.mergeAccounts(accounts);
List<List<String>> expected = List.of(List.of("Alex", "alex1@mail.com"), List.of("Alex", "alex2@mail.com"));
assertEquals(expected, merged);
}
@Test
void testEmptyInput() {
assertEquals(List.of(), AccountMerge.mergeAccounts(List.of()));
}
@Test
void testNullInput() {
assertEquals(List.of(), AccountMerge.mergeAccounts(null));
}
@Test
void testTransitiveMergeAndDuplicateEmails() {
List<List<String>> accounts = List.of(List.of("A", "a1@mail.com", "a2@mail.com"), List.of("A", "a2@mail.com", "a3@mail.com"), List.of("A", "a3@mail.com", "a4@mail.com", "a4@mail.com"));
List<List<String>> merged = AccountMerge.mergeAccounts(accounts);
List<List<String>> expected = List.of(List.of("A", "a1@mail.com", "a2@mail.com", "a3@mail.com", "a4@mail.com"));
assertEquals(expected, merged);
}
@Test
void testAccountsWithNoEmailsArePreserved() {
List<List<String>> accounts = List.of(List.of("Alex"), List.of("Alex", "alex1@mail.com"), List.of("Bob"));
List<List<String>> merged = AccountMerge.mergeAccounts(accounts);
List<List<String>> expected = List.of(List.of("Alex"), List.of("Alex", "alex1@mail.com"), List.of("Bob"));
assertEquals(expected, merged);
}
}