LightJason - AgentSpeak(L++)
TestCActionCollectionTuple.java
Go to the documentation of this file.
1 /*
2  * @cond LICENSE
3  * ######################################################################################
4  * # LGPL License #
5  * # #
6  * # This file is part of the LightJason AgentSpeak(L++) #
7  * # Copyright (c) 2015-19, LightJason (info@lightjason.org) #
8  * # This program is free software: you can redistribute it and/or modify #
9  * # it under the terms of the GNU Lesser General Public License as #
10  * # published by the Free Software Foundation, either version 3 of the #
11  * # License, or (at your option) any later version. #
12  * # #
13  * # This program is distributed in the hope that it will be useful, #
14  * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15  * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16  * # GNU Lesser General Public License for more details. #
17  * # #
18  * # You should have received a copy of the GNU Lesser General Public License #
19  * # along with this program. If not, see http://www.gnu.org/licenses/ #
20  * ######################################################################################
21  * @endcond
22  */
23 
24 package org.lightjason.agentspeak.action.builtin;
25 
26 import org.junit.Assert;
27 import org.junit.Test;
35 
36 import java.util.AbstractMap;
37 import java.util.ArrayList;
38 import java.util.Collections;
39 import java.util.List;
40 import java.util.stream.Collectors;
41 import java.util.stream.Stream;
42 
43 
47 public final class TestCActionCollectionTuple extends IBaseTest
48 {
49 
53  @Test
54  public final void create()
55  {
56  final List<ITerm> l_return = new ArrayList<>();
57 
58  new CCreate().execute(
59  false, IContext.EMPTYPLAN,
60  Stream.of( "abcd", 123, "foobar", true ).map( CRawTerm::from ).collect( Collectors.toList() ),
61  l_return
62  );
63 
64  Assert.assertEquals( l_return.size(), 2 );
65 
66  Assert.assertEquals( l_return.get( 0 ).<AbstractMap.Entry<String, ?>>raw().getKey(), "abcd" );
67  Assert.assertEquals( l_return.get( 0 ).<AbstractMap.Entry<?, Number>>raw().getValue(), 123 );
68 
69  Assert.assertEquals( l_return.get( 1 ).<AbstractMap.Entry<String, ?>>raw().getKey(), "foobar" );
70  Assert.assertTrue( l_return.get( 1 ).<AbstractMap.Entry<?, Boolean>>raw().getValue() );
71  }
72 
76  @Test
77  public final void createerror()
78  {
79  Assert.assertFalse(
80  new CCreate().execute(
81  false, IContext.EMPTYPLAN,
82  Collections.emptyList(),
83  Collections.emptyList()
84  ).value()
85  );
86  }
87 
88 
92  @Test
93  public final void set()
94  {
95  final AbstractMap.Entry<String, String> l_data = new AbstractMap.SimpleEntry<>( "foo", "bar" );
96 
97  new CSet().execute(
98  false, IContext.EMPTYPLAN,
99  Stream.of( "blubblub", l_data ).map( CRawTerm::from ).collect( Collectors.toList() ),
100  Collections.emptyList()
101  );
102 
103  Assert.assertEquals( l_data.getValue(), "blubblub" );
104  }
105 
106 
110  @Test
111  public final void flat()
112  {
113  final List<ITerm> l_return = new ArrayList<>();
114 
115  new CFlat().execute(
116  false, IContext.EMPTYPLAN,
117  Stream.of( new AbstractMap.SimpleEntry<>( "foo", "bar" ), new AbstractMap.SimpleEntry<>( 1, 2 ) ).map( CRawTerm::from ).collect( Collectors.toList() ),
118  l_return
119  );
120 
121  Assert.assertEquals( l_return.size(), 4 );
122 
123  Assert.assertEquals( l_return.get( 0 ).raw(), "foo" );
124  Assert.assertEquals( l_return.get( 1 ).raw(), "bar" );
125 
126  Assert.assertEquals( l_return.get( 2 ).<Number>raw(), 1 );
127  Assert.assertEquals( l_return.get( 3 ).<Number>raw(), 2 );
128  }
129 
130 }
base test class with helpers
Definition: IBaseTest.java:33
IContext EMPTYPLAN
empty context with plan
Definition: IContext.java:47
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
Definition: IContext.java:42
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
Definition: list/CFlat.java:64
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
Definition: CRawTerm.java:104
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
Definition: CRawTerm.java:45