@Test public void testClosureAlwaysIncludesStart() { Navigator<String> navigator = Navigators.forMultimap(ImmutableSetMultimap.<String, String>of()); assertEquals(ImmutableSet.of("A"), ImmutableSet.copyOf(Navigators.closure(navigator, "A"))); assertEquals( ImmutableSet.of("A"), ImmutableSet.copyOf(Navigators.closureOfMany(navigator, ImmutableList.of("A")))); }
@Test public void testClosure() { TransitiveRelation<String> relation = Relations.newTransitiveRelation(); relation.relate("A", "B"); relation.relate("B", "C"); Navigator<String> direct = relation.direct(); assertEquals( ImmutableSet.of("A", "B", "C"), ImmutableSet.copyOf(Navigators.closure(direct, "A"))); assertEquals(ImmutableSet.of("B", "C"), ImmutableSet.copyOf(Navigators.closure(direct, "B"))); assertEquals(ImmutableSet.of("C"), ImmutableSet.copyOf(Navigators.closure(direct, "C"))); }
@Test public void testForMultimap_domain() { Navigator<String> navigator = Navigators.forMultimap(ImmutableSetMultimap.of("a", "a1", "a", "a2", "b", "b")); assertEquals(ImmutableSet.of("a", "b"), ImmutableSet.copyOf(navigator.domain())); }
@Test public void testForFunction_Serializable() { Navigator<Integer> navigator = SerializationUtils.serializedCopy( Navigators.forFunction(ImmutableSet.of(1, 2, 3), new MyFun())); assertEquals(ImmutableSet.of(1, 2, 3), ImmutableSet.copyOf(navigator.domain())); assertEquals(ImmutableSet.of(2, 2), ImmutableSet.copyOf(navigator.related(1))); assertEquals(ImmutableSet.of(4, 3), ImmutableSet.copyOf(navigator.related(2))); assertEquals(ImmutableSet.of(6, 4), ImmutableSet.copyOf(navigator.related(3))); }
@Test public void testForFunction() { Navigator<Integer> navigator = Navigators.forFunction( ImmutableSet.of(1, 2, 3), new Function<Integer, Set<Integer>>() { public Set<Integer> apply(Integer value) { return ImmutableSet.of(value * 2, value + 1); } }); assertEquals(ImmutableSet.of(1, 2, 3), ImmutableSet.copyOf(navigator.domain())); assertEquals(ImmutableSet.of(2, 2), ImmutableSet.copyOf(navigator.related(1))); assertEquals(ImmutableSet.of(4, 3), ImmutableSet.copyOf(navigator.related(2))); assertEquals(ImmutableSet.of(6, 4), ImmutableSet.copyOf(navigator.related(3))); }