24 package org.lightjason.agentspeak.action.builtin;
26 import cern.colt.matrix.tbit.BitVector;
27 import cern.colt.matrix.tdouble.DoubleMatrix1D;
28 import com.codepoetics.protonpack.StreamUtils;
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.ImmutableTriple;
33 import org.apache.commons.lang3.tuple.Triple;
34 import org.junit.Assert;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
62 import java.lang.reflect.InvocationTargetException;
63 import java.util.ArrayList;
64 import java.util.Arrays;
65 import java.util.Collections;
66 import java.util.List;
67 import java.util.stream.Collectors;
68 import java.util.stream.Stream;
74 @RunWith( DataProviderRunner.class )
81 private static final BitVector VECTOR1 =
new BitVector( 3 );
86 private static final BitVector VECTOR2 =
new BitVector( 3 );
95 VECTOR1.put( 0,
true );
96 VECTOR1.put( 1,
false );
97 VECTOR1.put( 2,
false );
99 VECTOR2.put( 0,
false );
100 VECTOR2.put( 1,
false );
101 VECTOR2.put( 2,
true );
113 Stream.of( VECTOR1, VECTOR2 ),
128 Stream.of( VECTOR1, VECTOR2 ),
150 @SuppressWarnings(
"varargs" )
151 private static Stream<Object> testcase( final Stream<Object> p_input, final Stream<Class<?>> p_classes, final Stream<Object>... p_classresult )
153 final List<ITerm> l_input = p_input.map(
CRawTerm::from ).collect( Collectors.toList() );
155 return StreamUtils.zip(
157 Arrays.stream( p_classresult ),
158 ( i, j ) ->
new ImmutableTriple<>( l_input, i, j )
173 @UseDataProvider(
"generator" )
174 public final
void action( 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 p_input.getMiddle().toGenericString(),
187 l_return.stream().map(
ITerm::raw ).toArray(),
188 p_input.getRight().toArray()
198 final List<ITerm> l_return =
new ArrayList<>();
202 Stream.of( 3 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
206 Assert.assertEquals( l_return.size(), 1 );
207 Assert.assertTrue( l_return.get( 0 ).raw() instanceof BitVector );
208 Assert.assertEquals( l_return.get( 0 ).<BitVector>raw().size(), 3 );
217 final List<ITerm> l_return =
new ArrayList<>();
221 Stream.of( VECTOR2, 0 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
225 Assert.assertEquals( l_return.get( 0 ).<Boolean>raw(), false );
232 public final void set()
236 Stream.of( VECTOR2,
true, 0, 1 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
237 Collections.emptyList()
240 Assert.assertEquals( VECTOR2.get( 0 ), true );
241 Assert.assertEquals( VECTOR2.get( 1 ), true );
252 Stream.of( VECTOR2, 0 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
253 Collections.emptyList()
256 Assert.assertEquals( VECTOR2.get( 0 ), false );
265 final List<ITerm> l_return =
new ArrayList<>();
269 Stream.of( VECTOR2, 0, 2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
273 Assert.assertEquals( l_return.size(), 1 );
274 Assert.assertEquals( l_return.get( 0 ).<BitVector>raw(), VECTOR2 );
283 final List<ITerm> l_return =
new ArrayList<>();
287 Stream.of( VECTOR1, 1 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
291 Assert.assertEquals( l_return.get( 0 ).<Number>raw(), 0D );
300 final List<ITerm> l_return =
new ArrayList<>();
304 Stream.of( VECTOR1 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
308 Assert.assertEquals( l_return.size(), 1 );
309 Assert.assertTrue( l_return.get( 0 ).raw() instanceof List<?> );
310 Assert.assertArrayEquals( l_return.get( 0 ).<List<?>>raw().toArray(), Stream.of( 1D, 0D, 0D ).toArray() );
319 final List<ITerm> l_return =
new ArrayList<>();
323 Stream.of( VECTOR2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
327 Assert.assertEquals( l_return.size(), 1 );
328 Assert.assertTrue( l_return.get( 0 ).raw() instanceof DoubleMatrix1D );
329 Assert.assertArrayEquals( l_return.get( 0 ).<DoubleMatrix1D>raw().toArray(), Stream.of( 0, 0, 1 ).mapToDouble( i -> i ).toArray(), 0 );
performs the logical not-and operation to all bit vectors.
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 vector.
performs the logical and operation to all bit vectors.
performs the logical not operation to all bit vectors.
calculates the hamming distance.
sets the indexed bit to false within the bit vector.
converts the bit matrix to a blas matrix.
base test class with helpers
final void numericvalue()
test numericvalue
IContext EMPTYPLAN
empty context with plan
combines all arguments to a single result with the and-operator.
final void boolValue()
test boolean value
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 for the index tuple a numeric value.
final void clear()
test clear
final void tolist()
test toList
final void create()
test create
returns a copy of the vector.
execution context with local data
final void range()
test range
external action interface
static Object [] generator()
data provider generator
adds an element to the list.
returns the number of true values.
returns for the index a numeric value.
combines all arguments to a single result with the xor-operator.
converts a set to a list.
clears all elements of the collection.
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
performs the logical xor operation to all bit vectors.
returns the long values of the bit vector as list.
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 number of false values.
final void toblas()
test toblas
sets bit position by index and value.
< T > T raw()
cast to any raw value type
returns a new bit vector, based on the current.
converts the bit vector to a blas vector.
test for bit vector actions
final void initialize()
initialize
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
returns the number of false values.
returns the number of true values.
performs the logical or operation to all bit vectors.
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 for the index tuple a boolean value.
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
combines all arguments to a single result with the or-operator.
creates a list with a integer ranged list.
calculates the hamming distance.
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 a copy of the matrix.
returns the size of the collection.
performs the logical not-and operation to all bit matrices.
term structure for simple datatypes
returns for the index a boolean value.