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

Implements class CLASS? More...

Include dependency graph for path.test.cpp:

Go to the source code of this file.

Classes

class  PathTest
 

Functions

 TEST_F (PathTest, append)
 
 TEST_F (PathTest, fromString)
 
 TEST_F (PathTest, fromVector)
 
 TEST_F (PathTest, initialState)
 
 TEST_F (PathTest, itemFromPath)
 
 TEST_F (PathTest, PathFromItem)
 

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 path.test.cpp.

Function Documentation

◆ TEST_F() [1/6]

TEST_F ( PathTest  ,
append   
)

Definition at line 38 of file path.test.cpp.

39 {
40  Path path;
41  path.append(1);
42  EXPECT_EQ(path.str(), "1");
43 
44  path.append(2);
45  EXPECT_EQ(path.str(), "1,2");
46 
47  path.prepend(3);
48  EXPECT_EQ(path.str(), "3,1,2");
49 }
Supports navigation through SessionModel.
Definition: path.h:35
void prepend(PathElement element)
Definition: path.cpp:62
std::string str() const
Returns string representing path ("0,0,1,3").
Definition: path.cpp:49
void append(PathElement element)
Definition: path.cpp:57

References ModelView::Path::append(), ModelView::Path::prepend(), and ModelView::Path::str().

Here is the call graph for this function:

◆ TEST_F() [2/6]

TEST_F ( PathTest  ,
fromString   
)

Definition at line 57 of file path.test.cpp.

58 {
59  Path path = Path::fromString("3,2,3");
60  EXPECT_EQ(path.str(), "3,2,3");
61 }

References ModelView::Path::fromString(), and ModelView::Path::str().

Here is the call graph for this function:

◆ TEST_F() [3/6]

TEST_F ( PathTest  ,
fromVector   
)

Definition at line 51 of file path.test.cpp.

52 {
53  Path path = Path::fromVector({1, 2, 3});
54  EXPECT_EQ(path.str(), "1,2,3");
55 }

References ModelView::Path::fromVector(), and ModelView::Path::str().

Here is the call graph for this function:

◆ TEST_F() [4/6]

TEST_F ( PathTest  ,
initialState   
)

Definition at line 32 of file path.test.cpp.

33 {
34  Path path;
35  EXPECT_TRUE(path.str().empty());
36 }

References ModelView::Path::str().

Here is the call graph for this function:

◆ TEST_F() [5/6]

TEST_F ( PathTest  ,
itemFromPath   
)

Definition at line 103 of file path.test.cpp.

104 {
105  SessionModel model;
106 
107  // access to non-existing item
108  Path non_existing;
109  non_existing.append(8);
110  EXPECT_EQ(Utils::ItemFromPath(model, non_existing), nullptr);
111 
112  auto item0 = model.insertItem<SessionItem>();
113  item0->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
114  auto item1 = model.insertItem<SessionItem>();
115  item1->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
116  auto item2 = model.insertItem<SessionItem>();
117  item2->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
118 
119  EXPECT_EQ(Utils::ItemFromPath(model, Path::fromVector({0})), item0);
120  EXPECT_EQ(Utils::ItemFromPath(model, Path::fromVector({1})), item1);
121  EXPECT_EQ(Utils::ItemFromPath(model, Path::fromVector({2})), item2);
122 
123  auto child20 = model.insertItem<SessionItem>(item2);
124  child20->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
125  auto child200 = model.insertItem<SessionItem>(child20);
126  auto child201 = model.insertItem<SessionItem>(child20);
127 
128  EXPECT_EQ(Utils::ItemFromPath(model, Path::fromVector({2, 0})), child20);
129  EXPECT_EQ(Utils::ItemFromPath(model, Path::fromVector({2, 0, 0})), child200);
130  EXPECT_EQ(Utils::ItemFromPath(model, Path::fromVector({2, 0, 1})), child201);
131 }
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
MVVM_MODEL_EXPORT SessionItem * ItemFromPath(const SessionModel &moodel, const Path &path)
Returns item found in the model following given Path.
Definition: modelutils.cpp:36

References ModelView::Path::append(), ModelView::Path::fromVector(), ModelView::SessionModel::insertItem(), ModelView::Utils::ItemFromPath(), ModelView::SessionItem::registerTag(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [6/6]

TEST_F ( PathTest  ,
PathFromItem   
)

Definition at line 63 of file path.test.cpp.

64 {
65  SessionModel model;
66 
67  // unexisting path
68  EXPECT_TRUE(Utils::PathFromItem(nullptr).str().empty());
69  // yet another unexisting path
70  auto alienItem = std::make_unique<SessionItem>();
71  EXPECT_TRUE(Utils::PathFromItem(alienItem.get()).str().empty());
72 
73  // three children beneeth root item
74  auto item0 = model.insertItem<SessionItem>();
75  item0->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
76  auto item1 = model.insertItem<SessionItem>();
77  item1->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
78  auto item2 = model.insertItem<SessionItem>();
79  item2->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
80 
81  EXPECT_EQ(Utils::PathFromItem(item0).str(), "0");
82  EXPECT_EQ(Utils::PathFromItem(item1).str(), "1");
83  EXPECT_EQ(Utils::PathFromItem(item2).str(), "2");
84 
85  // adding granchildren to item0
86  auto child00 = model.insertItem<SessionItem>(item0);
87  auto child01 = model.insertItem<SessionItem>(item0);
88 
89  EXPECT_EQ(Utils::PathFromItem(child00).str(), "0,0");
90  EXPECT_EQ(Utils::PathFromItem(child01).str(), "0,1");
91 
92  // adding grandchildren to item2
93  auto child20 = model.insertItem<SessionItem>(item2);
94  child20->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
95 
96  auto child200 = model.insertItem<SessionItem>(child20);
97  auto child201 = model.insertItem<SessionItem>(child20);
98 
99  EXPECT_EQ(Utils::PathFromItem(child200).str(), "2,0,0");
100  EXPECT_EQ(Utils::PathFromItem(child201).str(), "2,0,1");
101 }
MVVM_MODEL_EXPORT Path PathFromItem(const SessionItem *item)
Constructs path to find given item. Item must belong to a model.
Definition: modelutils.cpp:22

References ModelView::SessionModel::insertItem(), ModelView::Utils::PathFromItem(), ModelView::SessionItem::registerTag(), ModelView::Path::str(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function: