24 package org.lightjason.agentspeak.action.builtin;
26 import org.apache.commons.lang3.RandomStringUtils;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
57 import javax.annotation.Nonnull;
58 import java.io.ByteArrayInputStream;
59 import java.io.InputStream;
60 import java.nio.charset.StandardCharsets;
61 import java.util.AbstractMap;
62 import java.util.ArrayList;
63 import java.util.Collections;
64 import java.util.List;
66 import java.util.logging.LogManager;
67 import java.util.stream.Collectors;
68 import java.util.stream.IntStream;
69 import java.util.stream.Stream;
86 LogManager.getLogManager().reset();
99 new CAgent.
CGenerator(
new ByteArrayInputStream(
"".getBytes( StandardCharsets.UTF_8 ) ), Collections.emptySet() ).generatesingle(),
101 Collections.emptyList()
114 final List<ITerm> l_return =
new ArrayList<>();
118 Collections.emptyList(),
122 Assert.assertEquals( l_return.size(), 1 );
123 Assert.assertTrue( l_return.get( 0 ).raw() instanceof List<?> );
124 Assert.assertEquals( l_return.get( 0 ).<List<?>>raw().size(), 0 );
131 Collections.emptyList(),
135 Assert.assertEquals( l_return.size(), 2 );
136 Assert.assertTrue( l_return.get( 1 ).raw() instanceof List<?> );
137 Assert.assertEquals( l_return.get( 1 ).<List<?>>raw().size(), 1 );
138 Assert.assertTrue( l_return.get( 1 ).<List<?>>raw().get( 0 ) instanceof AbstractMap.Entry<?, ?> );
139 Assert.assertEquals( l_return.get( 1 ).<List<AbstractMap.Entry<String,
ILiteral>>>raw().get( 0 ).getKey(), l_trigger.
type().
sequence() );
140 Assert.assertEquals( l_return.get( 1 ).<List<AbstractMap.Entry<String,
ILiteral>>>raw().get( 0 ).getValue(), l_trigger.
literal() );
154 Stream.of( l_plan ).map(
CRawTerm::from ).collect( Collectors.toList() ),
155 Collections.emptyList()
158 Assert.assertEquals( m_context.
agent().
plans().size(), 1 );
159 Assert.assertArrayEquals(
161 Stream.of( l_plan ).toArray()
174 final List<ITerm> l_return =
new ArrayList<>();
177 Collections.emptyList(),
181 Assert.assertEquals( l_return.size(), 1 );
182 Assert.assertTrue( l_return.get( 0 ).<Number>raw().longValue() > 0 );
193 final List<ITerm> l_return =
new ArrayList<>();
198 Collections.emptyList(),
202 Assert.assertTrue( l_return.isEmpty() );
209 Stream.of(
"+!",
"testgetplan" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
213 Assert.assertEquals( l_return.size(), 1 );
214 Assert.assertTrue( l_return.get( 0 ).raw() instanceof List<?> );
215 Assert.assertEquals( l_return.get( 0 ).<List<?>>raw().size(), 1 );
216 Assert.assertArrayEquals( l_return.get( 0 ).<List<?>>raw().toArray(), Stream.of( l_plan ).toArray() );
232 Stream.of(
"+!",
"testremoveplan" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
233 Collections.emptyList()
248 Stream.of(
"+!",
"testremoveerrorplan" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
249 Collections.emptyList()
261 IntStream.range( 0, 100 )
262 .mapToObj( i -> RandomStringUtils.random( 12,
"abcdefghijklmnop" ) )
271 Collections.emptyList(),
272 Collections.emptyList()
285 final List<ITerm> l_return =
new ArrayList<>();
286 final Set<String> l_list = IntStream.range( 0, 100 )
287 .mapToObj( i -> RandomStringUtils.random( 12,
"abcdefghijklmnop" ) )
289 .collect( Collectors.toSet() );
295 Collections.emptyList(),
300 Assert.assertEquals( l_return.size(), 1 );
301 Assert.assertTrue( l_return.get( 0 ).raw() instanceof List<?> );
305 .<List<ILiteral>>raw()
307 .map( i -> i.fqnfunctor().toString() )
308 .allMatch( l_list::contains )
322 m_context.
agent().call();
324 catch (
final Exception l_exception )
326 Assert.assertTrue( l_exception.getMessage(), false );
351 super( p_configuration );
362 CGenerator(
final InputStream p_stream,
final Set<IAction> p_actions )
throws Exception
364 super( p_stream, p_actions );
397 super( Collections.emptyList(), Collections.emptySet(), 0 );
398 m_trigger = p_trigger;
final ITrigger trigger()
returns the trigger event
plan statistic to count execution values
CGenerator(final InputStream p_stream, final Set< IAction > p_actions)
static IPlanStatistic from( @Nonnull final IPlan p_plan)
factory
final void removeplanerror()
test remove plan error
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 > condition(final IContext p_context)
execute the plan condition
IContext m_context
agent context
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 void cycletime()
test cycle-time
base structure of instantiable elements
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
adds a plan to the plan-base.
static final long serialVersionUID
serial id
final void clearbeliefbase()
test clear-beliefbase
base test class with helpers
Multimap< ITrigger, IPlanStatistic > plans()
returns the internal map of plans
IContext next()
execute agent cycle
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
final void removeplan()
test remove plan
final void getplan()
test get plan
removes a plan by the plan trigger.
final ITrigger m_trigger
trigger
static ITrigger from( @Nonnull final EType p_event, @Nonnull final ILiteral p_literal)
creates a trigger event^
action to get plan objects.
execution context with local data
final String sequence()
returns the trigger sequence
external action interface
clears all elements from the beliefbase.
action to get plan-information as list.
final CAgent generatesingle(final Object... p_data)
action to get cycle time.
CAgent(final IAgentConfiguration< CAgent > p_configuration)
ctor
final void addplan()
test add plan
result for an immutable fuzzy value
default generic literal class for agent beliefs a literal consists of a functor, an optional list of ...
interface to define the agent configuration
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
EType type()
returns the type of the event
CEmptyPlan(final ITrigger p_trigger)
ctor
final Map< Integer, ITrigger > m_trigger
execution trigger with content hash
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
ITrigger trigger()
returns the trigger event
static ILiteral from( @Nonnull final String p_functor, @Nullable final ITerm... p_values)
factory
int size()
returns the size of literals
returns a list of all belief literals.
IView add( @Nonnull final ILiteral... p_literal)
adds a literal in the current structure
ILiteral literal()
returns the literal of the event
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
IView beliefbase()
returns the beliefbase
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
void initialize()
initialize
IPlan plan()
plan reference
final void belieflist()
test belieflist
final void planlist()
test plan list
term structure for simple datatypes
IAgent<?> agent()
returns the agent of the context
final IAgentConfiguration< T > m_configuration
configuration of an agent