24 package org.lightjason.agentspeak.action.builtin;
26 import com.codepoetics.protonpack.StreamUtils;
27 import com.tngtech.java.junit.dataprovider.DataProvider;
28 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
29 import com.tngtech.java.junit.dataprovider.UseDataProvider;
30 import org.apache.commons.lang3.tuple.ImmutableTriple;
31 import org.apache.commons.lang3.tuple.Triple;
32 import org.junit.Assert;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
51 import java.lang.reflect.InvocationTargetException;
52 import java.util.ArrayList;
53 import java.util.Arrays;
54 import java.util.HashMap;
55 import java.util.List;
57 import java.util.stream.Collectors;
58 import java.util.stream.IntStream;
59 import java.util.stream.Stream;
65 @RunWith( DataProviderRunner.class )
82 Stream.of(
true,
false,
true,
false,
false,
true ),
102 Stream.of(
false,
true,
false,
true,
true,
false ),
113 Stream.of(
true,
true ),
134 Stream.of(
false,
false ),
151 @SuppressWarnings(
"varargs" )
152 private static Stream<Object> testcase( final Stream<Object> p_input, final Stream<Class<?>> p_classes, final Stream<Object>... p_classresult )
154 final List<ITerm> l_input = p_input.map(
CRawTerm::from ).collect( Collectors.toList() );
156 return StreamUtils.zip(
158 Arrays.stream( p_classresult ),
159 ( i, j ) ->
new ImmutableTriple<>( l_input, i, j )
173 @UseDataProvider(
"generate" )
174 public final
void execute( final Triple<List<
ITerm>, Class<? extends
IAction>, Stream<Object>> p_input )
175 throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException
177 final List<ITerm> l_return =
new ArrayList<>();
179 p_input.getMiddle().getConstructor().newInstance().execute(
185 Assert.assertArrayEquals(
186 l_return.stream().map(
ITerm::raw ).toArray(),
187 p_input.getRight().toArray()
197 final List<ITerm> l_return =
new ArrayList<>();
201 Stream.of( l_return, l_return,
new Object() ).map(
CRawTerm::from ).collect( Collectors.toList() ),
205 Assert.assertEquals( l_return.size(), 2 );
206 Assert.assertTrue( l_return.get( 0 ).<Boolean>raw() );
207 Assert.assertFalse( l_return.get( 1 ).<Boolean>raw() );
210 final List<Integer> l_list1 = IntStream.range( 0, 5 ).boxed().collect( Collectors.toList() );
211 final List<Integer> l_list2 = IntStream.range( 0, 5 ).boxed().collect( Collectors.toList() );
215 Stream.of( l_list1, l_list2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
219 Assert.assertEquals( l_return.size(), 3 );
220 Assert.assertTrue( l_return.get( 2 ).<Boolean>raw() );
223 final Map<Integer, Integer> l_map1 =
new HashMap<>();
225 final Map<Integer, Integer> l_map2 =
new HashMap<>();
230 Stream.of( l_map1, l_map2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
234 Assert.assertEquals( l_return.size(), 4 );
235 Assert.assertFalse( l_return.get( 3 ).<Boolean>raw() );
244 final Object l_object =
new Object();
245 final List<ITerm> l_return =
new ArrayList<>();
249 Stream.of( l_object, l_object,
new Object() ).map(
CRawTerm::from ).collect( Collectors.toList() ),
253 Assert.assertEquals( l_return.size(), 2 );
254 Assert.assertFalse( l_return.get( 0 ).<Boolean>raw() );
255 Assert.assertTrue( l_return.get( 1 ).<Boolean>raw() );
counts the number of true values.
base test class with helpers
static Object [] generate()
data provider generator
IContext EMPTYPLAN
empty context with plan
combines all arguments to a single result with the and-operator.
final void equal()
test equal
checks elements of inequality.
count the number of false values.
execution context with local data
external action interface
combines all arguments to a single result with the xor-operator.
checks elements of equality.
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
< T > T raw()
cast to any raw value type
checks any elements are equal to the first argument.
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
checks all elements are equal to the first argument.
combines all arguments to a single result with the or-operator.
term structure for simple datatypes
final void notequal()
test not-equal