### Question:
Tuples { public Tuples() { } Tuples();  Tuples(Collection<T>... coll);  Tuples(List<Collection<T>> collections); void add(Iterable<T> c); Iterator<List<T>> tuples();  }### Answer:
@Test public void test2() { List<String> l1 = new ArrayList<>(); List<String> l2 = new ArrayList<>(); Collections.addAll(l1, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); Collections.addAll(l2, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"); Tuples<String> t = new Tuples(l1, l2); Iterator<List<String>> itr = t.tuples(); int count = 0; int expectedCount = l1.size() * l2.size(); for (String x1 : l1) { for (String x2 : l2) { Assert.assertTrue(itr.hasNext()); List<String> item = itr.next(); Assert.assertEquals(x1, item.get(0)); Assert.assertEquals(x2, item.get(1)); count++; } } Assert.assertEquals(expectedCount, count); }
@Test public void test4() { List<String> l1 = new ArrayList<>(); List<String> l2 = new ArrayList<>(); List<String> l3 = new ArrayList<>(); List<String> l4 = new ArrayList<>(); Collections.addAll(l1, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); Collections.addAll(l2, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"); Collections.addAll(l3, "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"); Collections.addAll(l4, "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ"); int count = 0; int expectedCount = l1.size() * l2.size() * l3.size() * l4.size(); Tuples<String> t = new Tuples(l1, l2, l3, l4); Iterator<List<String>> itr = t.tuples(); for (String x1 : l1) { for (String x2 : l2) { for (String x3 : l3) { for (String x4 : l4) { Assert.assertTrue(itr.hasNext()); List<String> item = itr.next(); Assert.assertEquals(x1, item.get(0)); Assert.assertEquals(x2, item.get(1)); Assert.assertEquals(x3, item.get(2)); Assert.assertEquals(x4, item.get(3)); count++; } } } } Assert.assertEquals(expectedCount, count); }