MarketDataUtils { public static <T> List<List<T>> cartesianProduct(List<List<T>> inputs) { return cartesianProduct(ImmutableList.<T>of(), inputs); } private  MarketDataUtils(); static MulticurveProviderDiscount replaceCurve(MulticurveProviderDiscount multicurve,
                                                        YieldAndDiscountCurve curve); static List<List<T>> cartesianProduct(List<List<T>> inputs); @SafeVarargs static List<List<T>> cartesianProduct(List<T>... inputs);  }
@Test public void cartesianProductNoList() { List<?> expected = ImmutableList.of(ImmutableList.of()); assertEquals(expected, MarketDataUtils.cartesianProduct()); }
@Test public void cartesianProductEmptyList() { List<?> list = ImmutableList.of(); assertEquals(list, MarketDataUtils.cartesianProduct(list)); }
@Test public void cartesianProductOneItem() { List<Integer> list = ImmutableList.of(1); List<List<Integer>> expected = ImmutableList.<List<Integer>>of(ImmutableList.of(1)); assertEquals(expected, MarketDataUtils.cartesianProduct(list)); }
@Test public void cartesianProductOneList() { List<Integer> list = ImmutableList.of(1, 2, 3); List<List<Integer>> expected = ImmutableList.<List<Integer>>of(ImmutableList.of(1), ImmutableList.of(2), ImmutableList.of(3)); assertEquals(expected, MarketDataUtils.cartesianProduct(list)); }
@Test public void cartesianProductOneListEmpty() { List<Integer> list = ImmutableList.of(1, 2, 3); List<Integer> empty = ImmutableList.of(); List<List<Integer>> expected = ImmutableList.of(); assertEquals(expected, MarketDataUtils.cartesianProduct(list, empty)); assertEquals(expected, MarketDataUtils.cartesianProduct(empty, list)); }
@Test public void cartesianProductTwoLists() { List<String> list1 = ImmutableList.of("1", "2", "3"); List<String> list2 = ImmutableList.of("a", "b"); List<List<String>> expected = ImmutableList.<List<String>>of( ImmutableList.of("1", "a"), ImmutableList.of("1", "b"), ImmutableList.of("2", "a"), ImmutableList.of("2", "b"), ImmutableList.of("3", "a"), ImmutableList.of("3", "b")); assertEquals(expected, MarketDataUtils.cartesianProduct(list1, list2)); }
@Test public void cartesianProductThreeLists() { List<String> list1 = ImmutableList.of("1", "2"); List<String> list2 = ImmutableList.of("a", "b"); List<String> list3 = ImmutableList.of("x", "y"); List<List<String>> expected = ImmutableList.<List<String>>of( ImmutableList.of("1", "a", "x"), ImmutableList.of("1", "a", "y"), ImmutableList.of("1", "b", "x"), ImmutableList.of("1", "b", "y"), ImmutableList.of("2", "a", "x"), ImmutableList.of("2", "a", "y"), ImmutableList.of("2", "b", "x"), ImmutableList.of("2", "b", "y")); assertEquals(expected, MarketDataUtils.cartesianProduct(list1, list2, list3)); }