LightJason - AgentSpeak(L++)
TestCView.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.beliefbase;
25 
26 import org.apache.commons.lang3.RandomStringUtils;
27 import org.junit.Test;
34 
35 import java.util.stream.IntStream;
36 
37 import static org.junit.Assert.assertEquals;
38 
39 
43 public final class TestCView extends IBaseTest
44 {
45 
49  @Test
50  public final void testTree()
51  {
52  final int l_max = 1000;
53  final IView l_beliefbase = new CBeliefbase( new CMultiStorage<>() ).create( "root" );
54  final IViewGenerator l_generator = new CGenerator();
55 
56  IntStream.range( 0, l_max )
57  .boxed()
58  .map( i -> CLiteral.from( RandomStringUtils.random( 12, "~abcdefghijklmnopqrstuvwxyz/".toCharArray() ) ) )
59  .forEach( i -> l_beliefbase.generate( l_generator, i.functorpath() ).add( i ) );
60 
61  assertEquals( "number of beliefs is incorrect", l_beliefbase.size(), l_max );
62  }
63 
64 
68  @Test
69  public final void testManual()
70  {
71  final IView l_beliefbase = new CBeliefbase( new CMultiStorage<>() ).create( "root" );
72  final IViewGenerator l_gen = new CGenerator();
73 
74  l_beliefbase.add( CLiteral.from( "toplevel" ) )
75 
76  .generate( l_gen, CPath.from( "first" ) )
77  .add( CLiteral.from( "first/sub1" ) )
78  .add( CLiteral.from( "first/sub2" ) )
79 
80  .generate( l_gen, CPath.from( "second/sub" ) )
81  .add( CLiteral.from( "second/sub3" ) )
82  .add( CLiteral.from( "second/sub4" ) )
83 
84  .add( CLiteral.from( "second/sub/sub5" ) );
85 
86 
87  assertEquals( "number of beliefs is incorrect", l_beliefbase.size(), 6 );
88  }
89 
90 
94  private static final class CGenerator implements IViewGenerator
95  {
96 
97  @Override
98  public final IView apply( final String p_name, final IView p_parent )
99  {
100  return new CBeliefbase( new CMultiStorage<>() ).create( p_name, p_parent );
101  }
102  }
103 
104 }
base test class with helpers
Definition: IBaseTest.java:33
static IPath from( @Nonnull final String p_string)
factor method to build path
Definition: CPath.java:166
class to create a path structure
Definition: CPath.java:53
view for a beliefbase that creates any access to the underlying data structures
Definition: IView.java:44
final IView apply(final String p_name, final IView p_parent)
Definition: TestCView.java:98
thread-safe storage of the data of single- and multi-elements
final void testTree()
random test tree structure
Definition: TestCView.java:50
default generic literal class for agent beliefs a literal consists of a functor, an optional list of ...
Definition: CLiteral.java:64
IView generate( @Nonnull final IViewGenerator p_generator, @Nonnull final IPath... p_paths)
generates path structure
interface for generating non-existing beliefbases views
final void testManual()
manual test of tree structure
Definition: TestCView.java:69
static ILiteral from( @Nonnull final String p_functor, @Nullable final ITerm... p_values)
factory
Definition: CLiteral.java:161
final IView create( @Nonnull final String p_name)
returns a new view of the belief base
int size()
returns the size of literals
IView add( @Nonnull final ILiteral... p_literal)
adds a literal in the current structure
beliefbase to generate any event-based data by reference counting