BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
standardchildrenstrategies.test.cpp File Reference

Implements class CLASS? More...

Include dependency graph for standardchildrenstrategies.test.cpp:

Go to the source code of this file.

Classes

struct  StandardChildrenStrategiesTest::ChildrenData
 
class  StandardChildrenStrategiesTest
 
class  StandardChildrenStrategiesTest::TestItem
 Helper class with two properties and one top level item on board. More...
 

Functions

 TEST_F (StandardChildrenStrategiesTest, AllChildrenStrategy)
 Testing AllChildrenStrategy. More...
 
 TEST_F (StandardChildrenStrategiesTest, PropertyItemsFlatStrategy)
 Testing PropertyItemsFlatStrategy. More...
 
 TEST_F (StandardChildrenStrategiesTest, PropertyItemsStrategy)
 Testing PropertyItemsStrategy. More...
 
 TEST_F (StandardChildrenStrategiesTest, TopItemsStrategy)
 Testing TopItemsStrategy. More...
 

Detailed Description

Implements class CLASS?

Homepage:\n http://www.bornagainproject.org
License:\n GNU General Public License v3 or higher (see COPYING)
Authors
Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)

Definition in file standardchildrenstrategies.test.cpp.

Function Documentation

◆ TEST_F() [1/4]

Testing AllChildrenStrategy.

Definition at line 67 of file standardchildrenstrategies.test.cpp.

68 {
69  AllChildrenStrategy strategy;
70 
71  // nullptr
72  auto children = strategy.children(nullptr);
73  EXPECT_EQ(children.size(), 0);
74 
75  // empty item
76  SessionItem item1("model_type");
77  children = strategy.children(&item1);
78  EXPECT_EQ(children.size(), 0);
79 
80  // VectorItem
81  VectorItem item2;
82  children = strategy.children(&item2);
83  EXPECT_EQ(children.size(), 3);
84 
85  // CompoundItem
86  CompoundItem item3;
87  item3.addProperty("height", 42.0);
88  children = strategy.children(&item3);
89  EXPECT_EQ(children.size(), 1);
90 
91  // TestItem
92  TestItem item4;
93  children = strategy.children(&item4);
94  EXPECT_EQ(children.size(), 3);
95 
96  // GroupItem
99  children = strategy.children(&item5);
100  EXPECT_EQ(children.size(), 3); // number of registered children
101 }
Strategy to find children of given item: gives all actual children back.
std::vector< SessionItem * > children(const SessionItem *item) const override
Returns vector of children of given item.
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.h:28
T * addProperty(const std::string &name)
Adds property item of given type.
Definition: compounditem.h:43
void setCurrentType(const std::string &model_type)
Sets item corresponding to given model type.
Definition: groupitem.cpp:58
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
Vector item with three x,y,z property items.
Definition: vectoritem.h:24
Represents a group item holding a collection of shapes.
Definition: toyitems.h:119
const ModelView::model_type CylinderItemType
Definition: toyitems.h:35

References ModelView::CompoundItem::addProperty(), ModelView::AllChildrenStrategy::children(), ToyItems::Constants::CylinderItemType, and ModelView::GroupItem::setCurrentType().

Here is the call graph for this function:

◆ TEST_F() [2/4]

Testing PropertyItemsFlatStrategy.

Definition at line 198 of file standardchildrenstrategies.test.cpp.

199 {
200  PropertyItemsFlatStrategy strategy;
201 
202  // nullptr
203  {
204  auto children = strategy.children(nullptr);
205  EXPECT_EQ(children.size(), 0);
206  }
207 
208  // empty item
209  {
210  SessionItem item("model_type");
211  auto children = strategy.children(&item);
212  EXPECT_EQ(children.size(), 0);
213  }
214 
215  // VectorItem
216  {
217  VectorItem item;
218  auto children = strategy.children(&item);
219  EXPECT_EQ(children.size(), 3);
220  }
221 
222  // CompoundItem
223  {
224  CompoundItem item;
225  item.addProperty("height", 42.0);
226  auto children = strategy.children(&item);
227  EXPECT_EQ(children.size(), 1);
228  }
229 
230  // TestItem
231  {
232  TestItem item;
233  auto children = strategy.children(&item);
234  EXPECT_EQ(children.size(), 2);
235  }
236 
237  // GroupItem
238  {
241  auto children = strategy.children(&item);
242  EXPECT_EQ(children.size(), 2);
243 
244  std::vector<ChildrenData> expected_children_data{
247  EXPECT_EQ(children_data(children), expected_children_data);
248  }
249 
250  // ParticleItem
251  {
253  auto children = strategy.children(&item);
254  EXPECT_EQ(children.size(), 3);
255 
256  std::vector<ChildrenData> expected_children_data{
260 
261  EXPECT_EQ(children_data(children), expected_children_data);
262  }
263 }
Strategy to find children of given item: flat alignment.
std::vector< SessionItem * > children(const SessionItem *item) const override
Returns vector of children of given item.
static const std::string P_HEIGHT
Definition: toyitems.h:91
static const std::string P_RADIUS
Definition: toyitems.h:90
Represents a particle, with a position, and a selection of possible shapes.
Definition: toyitems.h:62
static const std::string P_SHAPES
Definition: toyitems.h:65
static const std::string P_POSITION
Definition: toyitems.h:64
static const std::string P_RADIUS
Definition: toyitems.h:100
const model_type PropertyType
Definition: mvvm_types.h:59
const model_type VectorItemType
Definition: mvvm_types.h:61
const ModelView::model_type ShapeGroupItemType
Definition: toyitems.h:39

References ModelView::CompoundItem::addProperty(), ModelView::PropertyItemsFlatStrategy::children(), ToyItems::Constants::CylinderItemType, ToyItems::CylinderItem::P_HEIGHT, ToyItems::ParticleItem::P_POSITION, ToyItems::CylinderItem::P_RADIUS, ToyItems::SphereItem::P_RADIUS, ToyItems::ParticleItem::P_SHAPES, ModelView::Constants::PropertyType, ModelView::GroupItem::setCurrentType(), ToyItems::Constants::ShapeGroupItemType, and ModelView::Constants::VectorItemType.

Here is the call graph for this function:

◆ TEST_F() [3/4]

Testing PropertyItemsStrategy.

Definition at line 143 of file standardchildrenstrategies.test.cpp.

144 {
145  PropertyItemsStrategy strategy;
146 
147  // nullptr
148  {
149  auto children = strategy.children(nullptr);
150  EXPECT_EQ(children.size(), 0);
151  }
152 
153  // empty item
154  {
155  SessionItem item("model_type");
156  auto children = strategy.children(&item);
157  EXPECT_EQ(children.size(), 0);
158  }
159 
160  // VectorItem
161  {
162  VectorItem item;
163  auto children = strategy.children(&item);
164  EXPECT_EQ(children.size(), 3);
165  }
166 
167  // CompoundItem
168  {
169  CompoundItem item;
170  item.addProperty("height", 42.0);
171  auto children = strategy.children(&item);
172  EXPECT_EQ(children.size(), 1);
173  }
174 
175  // TestItem
176  {
177  TestItem item;
178  auto children = strategy.children(&item);
179  EXPECT_EQ(children.size(), 2);
180  }
181 
182  // GroupItem
183  {
186  auto children = strategy.children(&item);
187  EXPECT_EQ(children.size(), 2);
188 
189  std::vector<ChildrenData> expected_children_data{
192  EXPECT_EQ(children_data(children), expected_children_data);
193  }
194 }
Strategy to find children of given item: only property item will be given, all top level items will b...
std::vector< SessionItem * > children(const SessionItem *item) const override
Returns vector of children of given item.

References ModelView::CompoundItem::addProperty(), ModelView::PropertyItemsStrategy::children(), ToyItems::Constants::CylinderItemType, ToyItems::CylinderItem::P_HEIGHT, ToyItems::CylinderItem::P_RADIUS, ModelView::Constants::PropertyType, and ModelView::GroupItem::setCurrentType().

Here is the call graph for this function:

◆ TEST_F() [4/4]

Testing TopItemsStrategy.

Definition at line 105 of file standardchildrenstrategies.test.cpp.

106 {
107  TopItemsStrategy strategy;
108 
109  // nullptr
110  auto children = strategy.children(nullptr);
111  EXPECT_EQ(children.size(), 0);
112 
113  // empty item
114  SessionItem item1("model_type");
115  children = strategy.children(&item1);
116  EXPECT_EQ(children.size(), 0);
117 
118  // VectorItem
119  VectorItem item2;
120  children = strategy.children(&item2);
121  EXPECT_EQ(children.size(), 0);
122 
123  // CompoundItem
124  CompoundItem item3;
125  item3.addProperty("height", 42.0);
126  children = strategy.children(&item3);
127  EXPECT_EQ(children.size(), 0);
128 
129  // TestItem
130  TestItem item4;
131  children = strategy.children(&item4);
132  EXPECT_EQ(children.size(), 1);
133 
134  // GroupItem
137  children = strategy.children(&item5);
138  EXPECT_EQ(children.size(), 3); // number of registered children
139 }
Strategy to find children of given item: only top level items will be given, all property items will ...
std::vector< SessionItem * > children(const SessionItem *item) const override
Returns vector of children of given item.

References ModelView::CompoundItem::addProperty(), ModelView::TopItemsStrategy::children(), ToyItems::Constants::CylinderItemType, and ModelView::GroupItem::setCurrentType().

Here is the call graph for this function: