24 package org.lightjason.agentspeak.language;
26 import com.codepoetics.protonpack.StreamUtils;
27 import org.junit.Assert;
28 import org.junit.Test;
38 import java.util.stream.Stream;
55 Assert.assertEquals( l_emptyliteral.
functor(),
"bar" );
57 Assert.assertFalse( l_emptyliteral.
hasAt() );
64 Assert.assertEquals( l_valueliteral.
functor(),
"value" );
66 Assert.assertFalse( l_valueliteral.
hasAt() );
71 Stream.of( 5,
"hello" ),
73 ( i, j ) -> i.equals( j.raw() )
87 Assert.assertTrue(
CCommon.rawvalueAssignableTo( l_stringterm, String.class ) );
88 Assert.assertEquals( l_stringterm.
raw(),
"hello" );
91 final double l_value = Math.random();
94 Assert.assertTrue(
CCommon.rawvalueAssignableTo( l_numberterm, Number.class ) );
95 Assert.assertTrue(
CCommon.rawvalueAssignableTo( l_numberterm, Double.class ) );
96 Assert.assertEquals(
"number value", l_numberterm.
raw(), l_value, 0 );
103 @Test( expected = RuntimeException.class )
116 final double l_value = Math.random();
119 Assert.assertEquals( l_constant.
functor(),
"C" );
121 Assert.assertTrue(
CCommon.rawvalueAssignableTo( l_constant, Number.class ) );
122 Assert.assertTrue(
CCommon.rawvalueAssignableTo( l_constant, Double.class ) );
123 Assert.assertEquals(
"constant number value", l_constant.
raw(), l_value, 0 );
133 new CConstant<>(
"const/value",
"test" ).shallowcopysuffix().functor(),
146 @Test( expected = IllegalStateException.class )
151 Assert.assertTrue( l_variable.
any() );
152 Assert.assertFalse( l_variable.allocated() );
154 l_variable.thrownotallocated();
161 @Test( expected = IllegalArgumentException.class )
190 Assert.assertEquals(
new CVariable<>(
"data" ).toString(),
"data()" );
191 Assert.assertEquals(
new CVariable<>(
"data",
"value" ).toString(),
"data(value)" );
204 double l_value = Math.random();
207 Assert.assertEquals( l_variable.
functor(),
"V" );
208 Assert.assertTrue( l_variable.
allocated() );
209 Assert.assertFalse( l_variable.
mutex() );
211 Assert.assertTrue(
CCommon.rawvalueAssignableTo( l_variable, Number.class ) );
212 Assert.assertTrue(
CCommon.rawvalueAssignableTo( l_variable, Double.class ) );
215 Assert.assertEquals(
"get variable number value", l_variable.
raw(), l_value, 0 );
217 l_value = Math.random();
218 l_variable.
set( l_value );
220 Assert.assertEquals(
"set variable number value", l_variable.
raw(), l_value, 0 );
222 l_variable.
set( null );
223 Assert.assertFalse( l_variable.
allocated() );
244 double l_value = Math.random();
247 Assert.assertEquals( l_variable.
functor(),
"V" );
248 Assert.assertTrue( l_variable.
allocated() );
249 Assert.assertTrue( l_variable.
mutex() );
251 Assert.assertTrue(
CCommon.rawvalueAssignableTo( l_variable, Number.class ) );
252 Assert.assertTrue(
CCommon.rawvalueAssignableTo( l_variable, Double.class ) );
255 Assert.assertEquals(
"get mutex variable number value", l_variable.
raw(), l_value, 0 );
257 l_value = Math.random();
258 l_variable.
set( l_value );
260 Assert.assertEquals(
"set mutex variable number value", l_variable.
raw(), l_value, 0 );
262 l_variable.
set( null );
263 Assert.assertFalse( l_variable.
allocated() );
274 Assert.assertEquals( l_variable.shallowcopysuffix().fqnfunctor(),
CPath.
from(
"copy" ) );
275 Assert.assertEquals( l_variable.shallowcopy(
CPath.
from(
"xxx" ) ).fqnfunctor(),
CPath.
from(
"xxx/prefix/copy" ) );
276 Assert.assertEquals( l_variable.shallowcopysuffix().<Object>raw(), l_variable.<Object>raw() );
280 Assert.assertNotEquals( l_deep.<Object>raw(), l_variable.<Object>raw() );
282 final ITerm l_deepsuffix = l_variable.deepcopysuffix();
284 Assert.assertNotEquals( l_deepsuffix.<Object>raw(), l_variable.<Object>raw() );
297 Assert.assertFalse( l_relocate.
mutex() );
299 Assert.assertEquals( l_variable.
functor(),
"RA" );
300 Assert.assertEquals( l_relocate.
functor(),
"RA" );
302 Assert.assertFalse( l_variable.
allocated() );
303 Assert.assertFalse( l_relocate.
allocated() );
309 l_relocate.
set(
"relocated foo" );
310 Assert.assertTrue( l_relocate.
allocated() );
311 Assert.assertEquals( l_relocate.
raw(),
"relocated foo" );
314 l_relocate.relocate();
315 Assert.assertTrue( l_variable.
allocated() );
316 Assert.assertEquals( l_variable.
raw(),
"relocated foo" );
329 Assert.assertTrue( l_relocate.
mutex() );
331 Assert.assertEquals( l_variable.
functor(),
"RAM" );
332 Assert.assertEquals( l_relocate.
functor(),
"RAM" );
334 Assert.assertFalse( l_variable.
allocated() );
335 Assert.assertFalse( l_relocate.
allocated() );
341 l_relocate.
set(
"relocated mutex foo" );
342 Assert.assertTrue( l_relocate.
allocated() );
343 Assert.assertEquals( l_relocate.
raw(),
"relocated mutex foo" );
346 l_relocate.relocate();
347 Assert.assertTrue( l_variable.
allocated() );
348 Assert.assertEquals( l_variable.
raw(),
"relocated mutex foo" );
IVariable< T > set( @Nullable final T p_value)
sets the value
final void constant()
test constant structure
final String functor()
returns the functor without path
final void variable()
checks the variable structure
final void constantcopy()
test constant copy
boolean allocated()
returns allocated state
final boolean hasVariable()
checks if the literal has variables
base test class with helpers
IVariable< T > set( @Nullable final T p_value)
sets the value
final void variablefunctor()
test variable functor
static IPath from( @Nonnull final String p_string)
factor method to build path
final void rawterm()
test raw-term structure
class to create a path structure
test for language components
final void variableany()
check any variable
Stream< ITerm > values(final IPath... p_path)
returns a stream over value items
final void relocatevariablerelocate()
test realocated variable
final void variablevalueassignable()
test exception on value asiable
IPath fqnfunctor()
returns the full-qualified functor with path and name
final void relocatevariablemutex()
test realocated variable
final void variablecopy()
test variable shallow-copy
boolean any()
flag to define a "any variable"
boolean emptyValues()
check for empty values
final void variableequals()
variable equals
boolean mutex()
flag to check if variable has is concurrency- / thread-safe
class for a mutex relocated variable
String functor()
returns the functor without path
default generic literal class for agent beliefs a literal consists of a functor, an optional list of ...
< T > T raw()
cast to any raw value type
final void variabletostring()
test tostring
class for a relocated variable
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
final void variablemutex()
check the mutex variable
class for any helper calls
static ILiteral from( @Nonnull final String p_functor, @Nullable final ITerm... p_values)
factory
default variable definition
final void constantaccess()
test constant access structure
final void literal()
test literal structure
boolean hasVariable()
checks if the literal has variables
boolean mutex()
flag to check if variable has is concurrency- / thread-safe
boolean allocated()
returns allocated state
term structure for simple datatypes
boolean hasAt()
returns if the literal has an @ prefix
public< N > N raw()
cast to any raw value type