24 package org.lightjason.agentspeak.action.builtin;
26 import com.codepoetics.protonpack.StreamUtils;
27 import org.junit.Assert;
28 import org.junit.Test;
44 import java.util.AbstractMap;
45 import java.util.ArrayList;
46 import java.util.Collections;
47 import java.util.HashMap;
48 import java.util.List;
50 import java.util.concurrent.ConcurrentHashMap;
51 import java.util.stream.Collectors;
52 import java.util.stream.Stream;
67 final List<ITerm> l_return =
new ArrayList<>();
71 Collections.emptyList(),
75 Assert.assertEquals( l_return.size(), 1 );
76 Assert.assertTrue( l_return.get( 0 ).<Map<?, ?>>raw().isEmpty() );
81 Stream.of(
"a", 1,
"b", 2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
85 Assert.assertEquals( l_return.size(), 2 );
86 Assert.assertFalse( l_return.get( 1 ).<Map<?, ?>>raw().isEmpty() );
88 Assert.assertArrayEquals( l_return.get( 1 ).<Map<?, ?>>raw().keySet().toArray(), Stream.of(
"a",
"b" ).toArray() );
89 Assert.assertArrayEquals( l_return.get( 1 ).<Map<?, ?>>raw().values().toArray(), Stream.of( 1, 2 ).toArray() );
94 Collections.emptyList(),
98 Assert.assertEquals( l_return.size(), 3 );
99 Assert.assertTrue( l_return.get( 2 ).<Map<?, ?>>raw() instanceof ConcurrentHashMap<?, ?> );
109 final Map<?, ?> l_map = StreamUtils.zip(
110 Stream.of(
"foo",
"bar",
"yyy",
"xxx" ),
111 Stream.of( 1, 2, 3, 4 ),
112 AbstractMap.SimpleImmutableEntry::new
113 ).collect( Collectors.toMap( AbstractMap.SimpleImmutableEntry::getKey, AbstractMap.SimpleImmutableEntry::getValue ) );
116 final List<ITerm> l_return =
new ArrayList<>();
120 Stream.of(
CRawTerm.
from( l_map ) ).collect( Collectors.toList() ),
126 Stream.of(
CRawTerm.
from( l_map ) ).collect( Collectors.toList() ),
131 Assert.assertEquals( l_return.size(), 2 );
133 Assert.assertEquals( l_return.get( 0 ).<List<?>>raw().size(), 4 );
134 Assert.assertEquals( l_return.get( 1 ).<List<?>>raw().size(), 4 );
136 Assert.assertArrayEquals( l_return.get( 0 ).<List<?>>raw().toArray(), Stream.of(
"bar",
"foo",
"xxx",
"yyy" ).toArray() );
137 Assert.assertArrayEquals( l_return.get( 1 ).<List<?>>raw().toArray(), Stream.of( 2, 1, 3, 4 ).toArray() );
147 final Map<?, ?> l_map =
new HashMap<>();
151 Stream.of(
"v", 1, l_map ).map(
CRawTerm::from ).collect( Collectors.toList() ),
153 Collections.emptyList()
156 Assert.assertEquals( l_map.size(), 1 );
157 Assert.assertArrayEquals( l_map.keySet().toArray(), Stream.of(
"v" ).toArray() );
158 Assert.assertArrayEquals( l_map.values().toArray(), Stream.of( 1 ).toArray() );
165 Stream.of(
"v", 666, l_map ).map(
CRawTerm::from ).collect( Collectors.toList() ),
167 Collections.emptyList()
170 Assert.assertEquals( l_map.size(), 1 );
171 Assert.assertArrayEquals( l_map.keySet().toArray(), Stream.of(
"v" ).toArray() );
172 Assert.assertArrayEquals( l_map.values().toArray(), Stream.of( 1 ).toArray() );
182 final Map<?, ?> l_map =
new HashMap<>();
186 Stream.of( l_map,
"xx", 2,
"yyy", 3 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
187 Collections.emptyList()
190 Assert.assertEquals( l_map.size(), 2 );
191 Assert.assertArrayEquals( l_map.keySet().toArray(), Stream.of(
"xx",
"yyy" ).toArray() );
192 Assert.assertArrayEquals( l_map.values().toArray(), Stream.of( 2, 3 ).toArray() );
197 Stream.of( l_map,
"xx", 100,
"zz", 4 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
198 Collections.emptyList()
201 Assert.assertEquals( l_map.size(), 3 );
202 Assert.assertArrayEquals( l_map.keySet().toArray(), Stream.of(
"xx",
"zz",
"yyy" ).toArray() );
203 Assert.assertArrayEquals( l_map.values().toArray(), Stream.of( 2, 4, 3 ).toArray() );
211 public final void remove()
213 final List<ITerm> l_return =
new ArrayList<>();
214 final Map<Object, Object> l_map =
new HashMap<>();
222 Stream.of( l_map,
"a",
"z" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
226 Assert.assertEquals( l_map.size(), 1 );
227 Assert.assertEquals( l_return.size(), 2 );
228 Assert.assertArrayEquals( l_return.stream().map(
ITerm::raw ).toArray(), Stream.of( 1, 3 ).toArray() );
238 final List<ITerm> l_return =
new ArrayList<>();
239 final Map<Object, Object> l_map =
new HashMap<>();
247 Stream.of( l_map,
"i",
"j",
"o" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
251 Assert.assertEquals( l_return.size(), 3 );
252 Assert.assertEquals( l_return.get( 0 ).<Number>raw(), 1 );
253 Assert.assertEquals( l_return.get( 1 ).<Number>raw(), 2 );
254 Assert.assertNull( l_return.get( 2 ).<Number>raw() );
264 final List<ITerm> l_return =
new ArrayList<>();
266 final Map<Object, Object> l_map1 =
new HashMap<>();
267 l_map1.put(
"g", 123 );
269 final Map<Object, Object> l_map2 =
new HashMap<>();
270 l_map2.put(
"g",
"text" );
274 Stream.of(
"g", l_map1, l_map2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
278 Assert.assertEquals( l_return.size(), 2 );
279 Assert.assertEquals( l_return.get( 0 ).<Number>raw(), 123 );
280 Assert.assertEquals( l_return.get( 1 ).raw(),
"text" );
adds an single element to multiple map arguments.
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
base test class with helpers
IContext EMPTYPLAN
empty context with plan
adds an single element pair to all map iif not exists.
final void getsingle()
test get-single
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
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
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 getmultiple()
test get-multiple
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 create()
test map create
final void putsingle()
test map putsingle
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 multiple element to a single map iif not exists.
final void putmultiple()
test multiple put
< T > T raw()
cast to any raw value type
returns all key values of the map.
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
removes elements from the map.
returns a single element of all map elements.
final void keysvalues()
test map keys
returns all values of the map.
removes an element of the list by the index.
adds all elements to a single map argument.
returns a multiple element of a single map.
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
term structure for simple datatypes