24 package org.lightjason.agentspeak.action.builtin;
26 import com.codepoetics.protonpack.StreamUtils;
27 import com.google.common.collect.HashMultimap;
28 import com.google.common.collect.Multimap;
29 import com.tngtech.java.junit.dataprovider.DataProvider;
30 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
31 import com.tngtech.java.junit.dataprovider.UseDataProvider;
32 import org.apache.commons.lang3.tuple.ImmutablePair;
33 import org.apache.commons.lang3.tuple.Pair;
34 import org.junit.Assert;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
45 import java.text.MessageFormat;
46 import java.util.AbstractMap;
47 import java.util.ArrayList;
48 import java.util.Collections;
49 import java.util.HashMap;
50 import java.util.List;
53 import java.util.stream.Collectors;
54 import java.util.stream.IntStream;
55 import java.util.stream.Stream;
61 @RunWith( DataProviderRunner.class )
75 Stream.of(
CRawTerm.
from(
new Object() ) ).collect( Collectors.toList() ),
80 Stream.of(
CRawTerm.
from(
new ArrayList<>() ) ).collect( Collectors.toList() ),
85 Stream.of(
CRawTerm.
from( Stream.of( 1,
"test" ).collect( Collectors.toList() ) ) ).collect( Collectors.toList() ),
90 Stream.of(
CRawTerm.
from(
new AbstractMap.SimpleEntry<>(
"a", 1 ) ) ).collect( Collectors.toList() ),
95 Stream.of(
CRawTerm.
from( Stream.of( 1, 1,
"test" ).collect( Collectors.toSet() ) ) ).collect( Collectors.toList() ),
101 CRawTerm.
from( Stream.of(
"abcd",
"xyz", 12, 12 ).collect( Collectors.toSet() ) ),
102 CRawTerm.
from( Stream.of( 1, 2, 3, 3, 4, 4 ).collect( Collectors.toList() ) )
103 ).collect( Collectors.toList() ),
109 StreamUtils.windowed( Stream.of( 1, 2, 3, 4 ), 2 ).collect( Collectors.toMap( i -> i.get( 0 ), i -> i.get( 1 ) ) )
110 ) ).collect( Collectors.toList() ),
116 StreamUtils.windowed( Stream.of( 1, 2, 3, 4 ), 2 ).collect( Collectors.toMap( i -> i.get( 0 ), i -> i.get( 1 ) ) )
117 ) ).collect( Collectors.toList() ),
130 @UseDataProvider(
"generate" )
131 public final
void size( final Pair<List<
ITerm>,
int[]> p_input )
133 final List<ITerm> l_return =
new ArrayList<>();
141 Assert.assertArrayEquals(
142 MessageFormat.format(
"elements {0}", p_input.getLeft() ),
143 l_return.stream().map( ITerm::<Number>raw ).mapToInt( Number::intValue ).toArray(),
155 final List<ITerm> l_return =
new ArrayList<>();
159 Stream.of(
new ArrayList<>(), HashMultimap.create(),
new HashMap<>(), Stream.of(
"1", 2 ).collect( Collectors.toList() ),
new Object() )
161 .collect( Collectors.toList() ),
165 Assert.assertEquals( l_return.size(), 5 );
166 Assert.assertArrayEquals( l_return.stream().map(
ITerm::<Boolean>raw ).toArray(), Stream.of(
true,
true,
true,
false,
false ).toArray() );
176 final List<Integer> l_list = IntStream.range( 0, 10 ).boxed().collect( Collectors.toList() );
177 final Set<Integer> l_set = IntStream.range( 10, 20 ).boxed().collect( Collectors.toSet() );
178 final Map<Integer, Integer> l_map = StreamUtils.windowed( IntStream.range( 100, 120 ).boxed(), 2 )
179 .collect( Collectors.toMap( i -> i.get( 0 ), i -> i.get( 1 ) ) );
181 final Multimap<Integer, Integer> l_multimap = HashMultimap.create();
182 IntStream.range( 0, 5 ).forEach( i -> IntStream.range( i, i + 5 ).forEach( j -> l_map.put( i, j ) ) );
186 Stream.of( l_list, l_set, l_map, l_multimap ).map(
CRawTerm::from ).collect( Collectors.toList() ),
187 Collections.emptyList()
190 Assert.assertTrue( l_list.isEmpty() );
191 Assert.assertTrue( l_set.isEmpty() );
192 Assert.assertTrue( l_map.isEmpty() );
final void clear()
test clear
base test class with helpers
IContext EMPTYPLAN
empty context with plan
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
execution context with local data
clears all elements of the collection.
checks a collection is empty.
final void empty()
test empty
static Object [] generate()
data provider generator
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
returns the size of the collection.
term structure for simple datatypes