24 package org.lightjason.agentspeak.action.builtin;
26 import com.codepoetics.protonpack.StreamUtils;
27 import com.tngtech.java.junit.dataprovider.DataProvider;
28 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
29 import com.tngtech.java.junit.dataprovider.UseDataProvider;
30 import org.junit.Assert;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
51 import java.io.UnsupportedEncodingException;
52 import java.util.AbstractMap;
53 import java.util.ArrayList;
54 import java.util.Collections;
55 import java.util.List;
56 import java.util.Locale;
57 import java.util.stream.Collectors;
58 import java.util.stream.Stream;
64 @RunWith( DataProviderRunner.class )
76 Stream.of(
"fooo",
"#!$foo",
"1234o097",
"AboCDef",
"foo",
"BARo" ).collect( Collectors.toList() )
86 @UseDataProvider(
"generate" )
87 public final
void base64( final List<String> p_input )
89 final List<ITerm> l_return =
new ArrayList<>();
90 final List<ITerm> l_result =
new ArrayList<>();
94 p_input.stream().map(
CRawTerm::from ).collect( Collectors.toList() ),
106 l_result.stream().map(
ITerm::<String>raw ),
107 AbstractMap.SimpleImmutableEntry::new
108 ).forEach( i -> Assert.assertEquals( i.getKey(), i.getValue() ) );
123 Stream.of(
new String(
"test encodingwith german additional character: öäß".getBytes(
"UTF-16" ),
"UTF-16" ) )
125 .collect( Collectors.toList() ),
126 Collections.emptyList()
138 @UseDataProvider(
"generate" )
139 public final
void concat( final List<String> p_input )
141 final List<ITerm> l_return =
new ArrayList<>();
145 p_input.stream().map(
CRawTerm::from ).collect( Collectors.toList() ),
150 l_return.get( 0 ).<String>raw(),
151 p_input.stream().collect( Collectors.joining() )
162 @UseDataProvider(
"generate" )
163 public final
void contains( final List<String> p_input )
165 final List<ITerm> l_return =
new ArrayList<>();
170 Stream.of( p_input.stream().collect( Collectors.joining() ) ),
178 .allMatch(
ITerm::<Boolean>raw )
189 @UseDataProvider(
"generate" )
190 public final
void lower( final List<String> p_input )
192 final List<ITerm> l_return =
new ArrayList<>();
196 p_input.stream().map(
CRawTerm::from ).collect( Collectors.toList() ),
202 p_input.stream().map( i -> i.toLowerCase( Locale.ROOT ) ),
203 l_return.stream().map(
ITerm::<String>raw ),
204 AbstractMap.SimpleImmutableEntry::new
205 ).forEach( i -> Assert.assertEquals( i.getKey(), i.getValue() ) );
215 @UseDataProvider(
"generate" )
216 public final
void reverse( final List<String> p_input )
218 final List<ITerm> l_return =
new ArrayList<>();
222 p_input.stream().map(
CRawTerm::from ).collect( Collectors.toList() ),
228 p_input.stream().map( i ->
new StringBuilder( i ).reverse().toString() ),
229 l_return.stream().map(
ITerm::<String>raw ),
230 AbstractMap.SimpleImmutableEntry::new
231 ).forEach( i -> Assert.assertEquals( i.getKey(), i.getValue() ) );
241 @UseDataProvider(
"generate" )
242 public final
void size( final List<String> p_input )
244 final List<ITerm> l_return =
new ArrayList<>();
248 p_input.stream().map(
CRawTerm::from ).collect( Collectors.toList() ),
254 p_input.stream().mapToLong( String::length ).boxed(),
255 l_return.stream().map(
ITerm::<Number>raw ).map( Number::longValue ),
256 AbstractMap.SimpleImmutableEntry::new
257 ).forEach( i -> Assert.assertEquals( i.getKey(), i.getValue() ) );
267 @UseDataProvider(
"generate" )
268 public final
void random( final List<String> p_input )
270 final List<ITerm> l_return =
new ArrayList<>();
275 Stream.of( p_input.stream().collect( Collectors.joining() ) ),
276 p_input.stream().mapToInt( String::length ).boxed()
282 p_input.stream().mapToInt( String::length ).boxed(),
283 l_return.stream().map(
ITerm::<String>raw ).mapToInt( String::length ).boxed(),
284 AbstractMap.SimpleImmutableEntry::new
285 ).forEach( i -> Assert.assertEquals( i.getKey(), i.getValue() ) );
295 @UseDataProvider(
"generate" )
296 public final
void upper( final List<String> p_input )
298 final List<ITerm> l_return =
new ArrayList<>();
302 p_input.stream().map(
CRawTerm::from ).collect( Collectors.toList() ),
308 p_input.stream().map( i -> i.toUpperCase( Locale.ROOT ) ),
309 l_return.stream().map(
ITerm::<String>raw ),
310 AbstractMap.SimpleImmutableEntry::new
311 ).forEach( i -> Assert.assertEquals( i.getKey(), i.getValue() ) );
321 final List<ITerm> l_return =
new ArrayList<>();
325 Stream.of(
"this is an input text",
"this",
"th",
"is" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
329 Assert.assertEquals( l_return.size(), 3 );
330 Assert.assertTrue( l_return.get( 0 ).<Boolean>raw() );
331 Assert.assertTrue( l_return.get( 1 ).<Boolean>raw() );
332 Assert.assertFalse( l_return.get( 2 ).<Boolean>raw() );
342 final List<ITerm> l_return =
new ArrayList<>();
346 Stream.of(
"this is a new input text with a cool ending",
"ing",
"this",
"g" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
350 Assert.assertEquals( l_return.size(), 3 );
351 Assert.assertTrue( l_return.get( 0 ).<Boolean>raw() );
352 Assert.assertFalse( l_return.get( 1 ).<Boolean>raw() );
353 Assert.assertTrue( l_return.get( 2 ).<Boolean>raw() );
366 Collections.emptyList(),
367 Collections.emptyList()
379 final List<ITerm> l_return =
new ArrayList<>();
383 Stream.of(
"kitten",
"sitting",
"singing" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
387 Assert.assertEquals( l_return.size(), 2 );
388 Assert.assertEquals( l_return.get( 0 ).<Number>raw().intValue(), 3 );
389 Assert.assertEquals( l_return.get( 1 ).<Number>raw().intValue(), 5 );
399 final List<ITerm> l_return =
new ArrayList<>();
403 Stream.of(
"test",
"tests",
"this a complete other string",
"test" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
407 Assert.assertEquals( l_return.size(), 3 );
408 Assert.assertEquals( l_return.get( 0 ).<Number>raw().doubleValue(), 0.04878048780487805, 0.0001 );
409 Assert.assertEquals( l_return.get( 1 ).<Number>raw().doubleValue(), 0.38333333333333336, 0.0001 );
410 Assert.assertEquals( l_return.get( 2 ).<Number>raw().doubleValue(), 0, 0 );
415 Stream.of(
"GZIP",
"test",
"tests",
"this a complete other string",
"test" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
419 Assert.assertEquals( l_return.size(), 6 );
420 Assert.assertEquals( l_return.get( 3 ).<Number>raw().doubleValue(), 0.12, 0 );
421 Assert.assertEquals( l_return.get( 4 ).<Number>raw().doubleValue(), 0.5833333333333334, 0.0001 );
422 Assert.assertEquals( l_return.get( 5 ).<Number>raw().doubleValue(), 0, 0 );
435 Collections.emptyList(),
436 Collections.emptyList()
final void levenshtein()
test levenshtein 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
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
action to check string for starts-with.
base test class with helpers
action to create an upper-case string.
action to decodes a string with Base64.
IContext EMPTYPLAN
empty context with plan
action to encodes a string with Base64.
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
action to concat / join all strings.
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
action to get the string length.
final void levenshteinerror()
tets for levenshtein distance error
final void ncderror()
test normalized compression distance error
execution context with local data
action to check string for containing another string.
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
calculates the normalized-compression-distance.
action to create random strings, with a definied length.
calculates the levenshtein 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
checks elements are containing in set.
action to check string for ends-with.
action to create a lower-case string.
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
final void endswidth()
test ends-with
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
action to reverse a string.
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 void base64decodeerror()
test base64 decode with errors
static Object [] generate()
data provider generator
final void ncd()
test normalized compression 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
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 startswith()
test starts-with
returns the size of the collection.
term structure for simple datatypes