|
| 1 | +package com.fishercoder; |
| 2 | + |
| 3 | +import com.fishercoder.solutions._721; |
| 4 | +import org.junit.BeforeClass; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import java.util.ArrayList; |
| 8 | +import java.util.Arrays; |
| 9 | +import java.util.List; |
| 10 | + |
| 11 | +public class _721Test { |
| 12 | + private static _721.Solution1 solution1; |
| 13 | + private static _721.Solution2 solution2; |
| 14 | + private static List<List<String>> accounts; |
| 15 | + private static List<List<String>> expected; |
| 16 | + |
| 17 | + @BeforeClass |
| 18 | + public static void setup() { |
| 19 | + solution1 = new _721.Solution1(); |
| 20 | + solution2 = new _721.Solution2(); |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + public void test1() throws Exception { |
| 25 | + accounts = new ArrayList<>(); |
| 26 | + List<String> account1 = new ArrayList<>(Arrays.asList("John", "johnsmith@mail.com", "john00@mail.com")); |
| 27 | + List<String> account2 = new ArrayList<>(Arrays.asList("John", "johnnybravo@mail.com")); |
| 28 | + List<String> account3 = new ArrayList<>(Arrays.asList("John", "johnsmith@mail.com", "john_newyork@mail.com")); |
| 29 | + List<String> account4 = new ArrayList<>(Arrays.asList("Mary", "mary@mail.com")); |
| 30 | + accounts.add(account1); |
| 31 | + accounts.add(account2); |
| 32 | + accounts.add(account3); |
| 33 | + accounts.add(account4); |
| 34 | + |
| 35 | + expected = new ArrayList<>(); |
| 36 | + List<String> expected1 = new ArrayList<>(Arrays.asList("Mary", "mary@mail.com")); |
| 37 | + List<String> expected2 = new ArrayList<>(Arrays.asList("John", "john00@mail.com", "john_newyork@mail.com", "johnsmith@mail.com")); |
| 38 | + List<String> expected3 = new ArrayList<>(Arrays.asList("John", "johnnybravo@mail.com")); |
| 39 | + expected.add(expected1); |
| 40 | + expected.add(expected2); |
| 41 | + expected.add(expected3); |
| 42 | + |
| 43 | + assertEqualsIgnoreOrdering(expected, solution1.accountsMerge(accounts)); |
| 44 | + assertEqualsIgnoreOrdering(expected, solution2.accountsMerge(accounts)); |
| 45 | + } |
| 46 | + |
| 47 | + private void assertEqualsIgnoreOrdering(List<List<String>> expected, List<List<String>> actual) throws Exception { |
| 48 | + //TODO: implement this method |
| 49 | + if (true) { |
| 50 | + return; |
| 51 | + } else { |
| 52 | + throw new Exception(); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void test2() throws Exception { |
| 58 | + accounts = new ArrayList<>(); |
| 59 | + List<String> account1 = new ArrayList<>(Arrays.asList("Alex", "Alex5@m.co", "Alex4@m.co", "Alex0@m.co")); |
| 60 | + List<String> account2 = new ArrayList<>(Arrays.asList("Ethan", "Ethan3@m.co", "Ethan3@m.co", "Ethan0@m.co")); |
| 61 | + List<String> account3 = new ArrayList<>(Arrays.asList("Kevin", "Kevin4@m.co", "Kevin2@m.co", "Kevin2@m.co")); |
| 62 | + List<String> account4 = new ArrayList<>(Arrays.asList("Gabe", "Gabe0@m.co", "Gabe3@m.co", "Gabe2@m.co")); |
| 63 | + List<String> account5 = new ArrayList<>(Arrays.asList("Gabe", "Gabe3@m.co", "Gabe4@m.co", "Gabe2@m.co")); |
| 64 | + accounts.add(account1); |
| 65 | + accounts.add(account2); |
| 66 | + accounts.add(account3); |
| 67 | + accounts.add(account4); |
| 68 | + accounts.add(account5); |
| 69 | + |
| 70 | + expected = new ArrayList<>(); |
| 71 | + List<String> expected1 = new ArrayList<>(Arrays.asList("Alex", "Alex0@m.co", "Alex4@m.co", "Alex5@m.co")); |
| 72 | + List<String> expected2 = new ArrayList<>(Arrays.asList("Kevin", "Kevin2@m.co", "Kevin4@m.co")); |
| 73 | + List<String> expected3 = new ArrayList<>(Arrays.asList("Ethan", "Ethan0@m.co", "Ethan3@m.co")); |
| 74 | + List<String> expected4 = new ArrayList<>(Arrays.asList("Gabe", "Gabe0@m.co", "Gabe2@m.co", "Gabe3@m.co", "Gabe4@m.co")); |
| 75 | + expected.add(expected1); |
| 76 | + expected.add(expected2); |
| 77 | + expected.add(expected3); |
| 78 | + expected.add(expected4); |
| 79 | + |
| 80 | + assertEqualsIgnoreOrdering(expected, solution1.accountsMerge(accounts)); |
| 81 | + assertEqualsIgnoreOrdering(expected, solution2.accountsMerge(accounts)); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void test3() throws Exception { |
| 86 | + accounts = new ArrayList<>(); |
| 87 | + List<String> account1 = new ArrayList<>(Arrays.asList("David", "David0@m.co", "David1@m.co")); |
| 88 | + List<String> account2 = new ArrayList<>(Arrays.asList("David", "David3@m.co", "David4@m.co")); |
| 89 | + List<String> account3 = new ArrayList<>(Arrays.asList("David", "David4@m.co", "David5@m.co")); |
| 90 | + List<String> account4 = new ArrayList<>(Arrays.asList("David", "David2@m.co", "David3@m.co")); |
| 91 | + List<String> account5 = new ArrayList<>(Arrays.asList("David", "David1@m.co", "David2@m.co")); |
| 92 | + accounts.add(account1); |
| 93 | + accounts.add(account2); |
| 94 | + accounts.add(account3); |
| 95 | + accounts.add(account4); |
| 96 | + accounts.add(account5); |
| 97 | + |
| 98 | + expected = new ArrayList<>(); |
| 99 | + List<String> expected1 = new ArrayList<>(Arrays.asList("David", "David0@m.co", "David1@m.co", "David2@m.co", "David3@m.co", "David4@m.co", "David5@m.co")); |
| 100 | + expected.add(expected1); |
| 101 | + |
| 102 | + assertEqualsIgnoreOrdering(expected, solution1.accountsMerge(accounts)); |
| 103 | + assertEqualsIgnoreOrdering(expected, solution2.accountsMerge(accounts)); |
| 104 | + } |
| 105 | + |
| 106 | +} |
0 commit comments