### Question:
SocialNetworkConn { public static long earliestTimeToConnectAllMember(int n, List<Log> sortedTimeStampLog) { if (n < 1) { throw new IllegalArgumentException("n should >= 1"); } if (n == 1) { return 0; } WeightedQuickUnionUF uf = new WeightedQuickUnionUF(n); for (Log log : sortedTimeStampLog) { uf.union(log.peopleA, log.peopleB); if (uf.count() == 1) { return log.timstamp; } } return -1; }  static long earliestTimeToConnectAllMember(int n, List<Log> sortedTimeStampLog);  }### Answer:
@Test public void testEmptyLog() { List<SocialNetworkConn.Log> logs = new ArrayList<>(); Assert.assertEquals(0, SocialNetworkConn.earliestTimeToConnectAllMember(1, logs)); for (int i = 2; i < 10; i++) { Assert.assertEquals(-1, SocialNetworkConn.earliestTimeToConnectAllMember(i, logs)); } }
@Test public void testFailedLog() { List<SocialNetworkConn.Log> logs = new ArrayList<>(); logs.add(new SocialNetworkConn.Log(1, 1, 2)); Assert.assertEquals(-1, SocialNetworkConn.earliestTimeToConnectAllMember(3, logs)); }
@Test public void testSuccessLogBeforeFinal() { List<SocialNetworkConn.Log> logs = new ArrayList<>(); logs.add(new SocialNetworkConn.Log(3, 1, 2)); logs.add(new SocialNetworkConn.Log(4, 0, 2)); logs.add(new SocialNetworkConn.Log(5, 0, 1)); Assert.assertEquals(4, SocialNetworkConn.earliestTimeToConnectAllMember(3, logs)); }
@Test public void testSuccessLogAtFinal() { List<SocialNetworkConn.Log> logs = new ArrayList<>(); logs.add(new SocialNetworkConn.Log(3, 1, 2)); logs.add(new SocialNetworkConn.Log(4, 2, 2)); logs.add(new SocialNetworkConn.Log(5, 0, 2)); Assert.assertEquals(5, SocialNetworkConn.earliestTimeToConnectAllMember(3, logs)); }
@Test public void testDuplicateLog() { List<SocialNetworkConn.Log> logs = new ArrayList<>(); logs.add(new SocialNetworkConn.Log(3, 1, 2)); logs.add(new SocialNetworkConn.Log(3, 1, 2)); logs.add(new SocialNetworkConn.Log(3, 1, 2)); logs.add(new SocialNetworkConn.Log(4, 2, 1)); logs.add(new SocialNetworkConn.Log(4, 2, 1)); logs.add(new SocialNetworkConn.Log(5, 0, 2)); logs.add(new SocialNetworkConn.Log(5, 0, 2)); Assert.assertEquals(5, SocialNetworkConn.earliestTimeToConnectAllMember(3, logs)); }