@Test public void createABAndBAWithConstantPV() { Transformer<ParikhVector, ParikhVector> constantTransformer = TransformerUtils.constantTransformer(new ParikhVector()); CreateLTS create = new CreateLTS(constantTransformer); create.addWord(Arrays.asList("a", "b")); create.addWord(Arrays.asList("b", "a")); TransitionSystem ts = create.getTransitionSystem(); assertThat(ts, not(sameInstance(create.getTransitionSystem()))); assertThat(ts.getNodes(), hasSize(1)); assertThat(ts.getEdges(), hasSize(2)); assertThat(ts.getInitialState(), not(nullValue())); assertThat(ts.getAlphabet(), containsInAnyOrder("a", "b")); State s0 = ts.getInitialState(); assertThat(s0.getPostsetNodesByLabel("a"), hasSize(1)); assertThat(s0.getPostsetNodesByLabel("b"), hasSize(1)); }
/** * Test collect. */ @Test public void testCollect(){ List<String> list = toList("xinge", "feilong1", "feilong2", "feilong2"); Transformer<String, Object> nullTransformer = TransformerUtils.nullTransformer(); List<Object> collect = CollectionsUtil.collect(list, nullTransformer); Object[] objects = { null, null, null, null }; assertThat(collect, hasItems(objects)); }
/** * Test collect 2. */ @Test public void testCollect2(){ List<User> list = toList(// new User("张飞", 23), new User("关羽", 24), new User("刘备", 25)); Transformer<User, String> invokerTransformer = TransformerUtils.invokerTransformer("getName"); assertThat(CollectionsUtil.collect(list, invokerTransformer), hasItems("张飞", "关羽", "刘备")); }
/** * Test collect3. */ @Test public void testCollect3(){ List<User> list = toList(// new User("张飞", 23), new User("关羽", 24), new User("刘备", 25)); List<String> collect1 = CollectionsUtil.collect(list, TransformerUtils.constantTransformer("jintian")); assertThat(collect1, hasItems("jintian", "jintian", "jintian")); }
/** * Test collect iterator. */ @Test public void testCollectIterator(){ List<String> list = toList("xinge", "feilong1", "feilong2", "feilong2"); Transformer<String, Object> nullTransformer = TransformerUtils.nullTransformer(); List<Object> collect = CollectionsUtil.collect(list.iterator(), nullTransformer); Object[] objects = { null, null, null, null }; assertThat(collect, hasItems(objects)); }
/** * Test group null collection. */ @Test public void testGroupNullCollection(){ assertEquals( emptyMap(), group( null, BeanPredicateUtil.comparatorPredicate("age", 20, Criterion.LESS), TransformerUtils.constantTransformer(5))); }
/** * Test group empty collection. */ @Test public void testGroupEmptyCollection(){ assertEquals( emptyMap(), group( new ArrayList<>(), BeanPredicateUtil.comparatorPredicate("age", 20, Criterion.LESS), TransformerUtils.constantTransformer(5))); }
/** * Test group null predicate. */ @Test public void testGroupNullPredicate(){ User zhangfei28 = new User("张飞", 28); User liubei32 = new User("刘备", 32); User liubei30 = new User("刘备", 30); List<User> list = toList(zhangfei28, liubei32, liubei30); Map<Integer, List<User>> map = CollectionsUtil.group(list, null, TransformerUtils.<User, Integer> constantTransformer(5)); assertEquals(1, map.size()); assertThat(map, allOf(hasEntry(5, toList(zhangfei28, liubei32, liubei30)))); }
/** * Test group not predicate. */ @Test public void testGroupNotPredicate(){ List<User> list = toList(new User("张飞", 10), new User("刘备", 10)); Predicate<User> comparatorPredicate = BeanPredicateUtil.comparatorPredicate("age", 20, Criterion.EQUAL); assertEquals(emptyMap(), CollectionsUtil.group(list, comparatorPredicate, TransformerUtils.<User, Integer> constantTransformer(5))); }
/** * Test collect null iterable. */ @Test public void testCollectNullIterable(){ assertEquals(null, CollectionsUtil.collect((List<Long>) null, TransformerUtils.stringValueTransformer())); }
/** * Test collect empty iterable. */ @Test public void testCollectEmptyIterable(){ assertEquals(emptyList(), CollectionsUtil.collect(new ArrayList<Long>(), TransformerUtils.stringValueTransformer())); }
/** * Test collect null iterator. */ @Test public void testCollectNullIterator(){ assertEquals(null, CollectionsUtil.collect((Iterator<Long>) null, TransformerUtils.stringValueTransformer())); }
/** * Test collect empty iterator. */ @Test public void testCollectEmptyIterator(){ assertEquals(emptyList(), CollectionsUtil.collect((new ArrayList<Long>()).iterator(), TransformerUtils.stringValueTransformer())); }
/** * Test group null collection. */ @Test public void testGroupNullCollection(){ assertEquals(emptyMap(), group(null, TransformerUtils.constantTransformer(5))); }
/** * Test group empty collection. */ @Test public void testGroupEmptyCollection(){ assertEquals(emptyMap(), group(new ArrayList<>(), TransformerUtils.constantTransformer(5))); }