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

Implements class CLASS? More...

Include dependency graph for data1ditem.test.cpp:

Go to the source code of this file.

Classes

class  Data1DItemTest
 Testing Data1DItem. More...
 

Functions

 TEST_F (Data1DItemTest, checkSignalsOnAxisChange)
 Checking the signals when axes changed. More...
 
 TEST_F (Data1DItemTest, checkSignalsOnBinValuesChange)
 Checking the signals when bin values changed. More...
 
 TEST_F (Data1DItemTest, initialState)
 Initial state. More...
 
 TEST_F (Data1DItemTest, setErrors)
 Checking the method ::setErrors. More...
 
 TEST_F (Data1DItemTest, setFixedBinAxis)
 Checking the method ::setFixedBinAxis. More...
 
 TEST_F (Data1DItemTest, setFixedBinAxisInModel)
 Sets fixed bin axis via model context. More...
 
 TEST_F (Data1DItemTest, setTemplatedFixedBinAxis)
 Sets fixed bin axis via templated method. More...
 
 TEST_F (Data1DItemTest, setTemplatedFixedBinAxisInModelContext)
 Sets fixed bin axis via templated method. More...
 
 TEST_F (Data1DItemTest, setValues)
 Checking the method ::setValues. 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 data1ditem.test.cpp.

Function Documentation

◆ TEST_F() [1/9]

TEST_F ( Data1DItemTest  ,
checkSignalsOnAxisChange   
)

Checking the signals when axes changed.

Definition at line 164 of file data1ditem.test.cpp.

165 {
166  SessionModel model;
167  auto item = model.insertItem<Data1DItem>();
168 
169  MockWidgetForItem widget(item);
170 
171  const std::string expected_value_tag{Data1DItem::P_VALUES};
172  const TagRow expected_axis_tagrow{Data1DItem::T_AXIS, 0};
173 
174  EXPECT_CALL(widget, onDataChange(_, _)).Times(0);
175  EXPECT_CALL(widget, onPropertyChange(item, expected_value_tag)).Times(1);
176  EXPECT_CALL(widget, onChildPropertyChange(_, _)).Times(2);
177  EXPECT_CALL(widget, onItemInserted(item, expected_axis_tagrow)).Times(1);
178  EXPECT_CALL(widget, onAboutToRemoveItem(_, _)).Times(0);
179 
180  // trigger change
181  item->setAxis<FixedBinAxisItem>(3, 0.0, 3.0);
182 }
Mock widget to test ItemMapper functionality.
Definition: mockwidgets.h:36
Represents one-dimensional data (axis and values).
Definition: data1ditem.h:30
Item to represent fixed bin axis.
Definition: axisitems.h:75
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
Aggregate to hold (tag, row) information for SessionModel.
Definition: tagrow.h:25

References ModelView::SessionModel::insertItem(), ModelView::Data1DItem::P_VALUES, and ModelView::Data1DItem::T_AXIS.

Here is the call graph for this function:

◆ TEST_F() [2/9]

TEST_F ( Data1DItemTest  ,
checkSignalsOnBinValuesChange   
)

Checking the signals when bin values changed.

Definition at line 186 of file data1ditem.test.cpp.

187 {
188  SessionModel model;
189  auto item = model.insertItem<Data1DItem>();
190  item->setAxis<FixedBinAxisItem>(3, 0.0, 3.0);
191 
192  MockWidgetForItem widget(item);
193 
194  EXPECT_CALL(widget, onDataChange(_, _)).Times(0);
195  EXPECT_CALL(widget, onPropertyChange(item, Data1DItem::P_VALUES)).Times(1);
196  EXPECT_CALL(widget, onChildPropertyChange(_, _)).Times(0);
197  EXPECT_CALL(widget, onItemInserted(_, _)).Times(0);
198  EXPECT_CALL(widget, onAboutToRemoveItem(_, _)).Times(0);
199 
200  // trigger change
201  item->setValues(std::vector<double>{1.0, 2.0, 3.0});
202 }
T * setAxis(Args &&... args)
Inserts axis of given type.
Definition: data1ditem.h:56

References ModelView::SessionModel::insertItem(), ModelView::Data1DItem::P_VALUES, and ModelView::Data1DItem::setAxis().

Here is the call graph for this function:

◆ TEST_F() [3/9]

TEST_F ( Data1DItemTest  ,
initialState   
)

Initial state.

Definition at line 36 of file data1ditem.test.cpp.

37 {
38  Data1DItem item;
39 
40  EXPECT_EQ(item.getItem(Data1DItem::T_AXIS), nullptr);
41  EXPECT_EQ(item.binCenters(), std::vector<double>());
42  EXPECT_EQ(item.binValues(), std::vector<double>());
43  EXPECT_EQ(item.binErrors(), std::vector<double>());
44  EXPECT_FALSE(item.hasData());
45 }
std::vector< double > binValues() const
Returns values stored in bins.
Definition: data1ditem.cpp:76
std::vector< double > binCenters() const
Sets axis. Bin content will be set to zero.
Definition: data1ditem.cpp:57
std::vector< double > binErrors() const
Returns value errors stored in bins.
Definition: data1ditem.cpp:93
SessionItem * getItem(const std::string &tag, int row=0) const
Returns item at given row of given tag.
bool hasData(int role=ItemDataRole::DATA) const
Returns true if item has data on board with given role.

References ModelView::Data1DItem::binCenters(), ModelView::Data1DItem::binErrors(), ModelView::Data1DItem::binValues(), ModelView::SessionItem::getItem(), ModelView::SessionItem::hasData(), and ModelView::Data1DItem::T_AXIS.

Here is the call graph for this function:

◆ TEST_F() [4/9]

TEST_F ( Data1DItemTest  ,
setErrors   
)

Checking the method ::setErrors.

Definition at line 147 of file data1ditem.test.cpp.

148 {
149  Data1DItem item;
150 
151  // check that it is not possible to errors to uninitialized axis
152  std::vector<double> expected_errors = {10.0, 20.0, 30.0};
153 
154  EXPECT_THROW(item.setErrors(expected_errors), std::runtime_error);
155 
156  item.setAxis<FixedBinAxisItem>(3, 0.0, 3.0);
157  item.setErrors(expected_errors);
158 
159  EXPECT_EQ(item.binErrors(), expected_errors);
160 }
void setErrors(const std::vector< double > &errors)
Sets errors on values in bins.
Definition: data1ditem.cpp:83

References ModelView::Data1DItem::binErrors(), ModelView::Data1DItem::setAxis(), and ModelView::Data1DItem::setErrors().

Here is the call graph for this function:

◆ TEST_F() [5/9]

TEST_F ( Data1DItemTest  ,
setFixedBinAxis   
)

Checking the method ::setFixedBinAxis.

Definition at line 49 of file data1ditem.test.cpp.

50 {
51  Data1DItem item;
52 
53  item.setAxis<FixedBinAxisItem>(5, 0.0, 5.0);
54 
55  // check type of the axis
56  EXPECT_TRUE(item.item<FixedBinAxisItem>(Data1DItem::T_AXIS) != nullptr);
57 
58  // check bin centers and values
59  std::vector<double> expected_centers = {0.5, 1.5, 2.5, 3.5, 4.5};
60  EXPECT_EQ(item.binCenters(), expected_centers);
61  std::vector<double> expected_values = std::vector<double>(expected_centers.size(), 0.0);
62  EXPECT_EQ(item.binValues(), expected_values);
63 
64  // setting another axis
65  // for the moment we have disabled possibility to re-create axes to faciltate undo/redo
66  // item.setAxis(FixedBinAxisItem::create(1, 1.0, 2.0));
67  // expected_centers = {1.5};
68  // EXPECT_EQ(item.binCenters(), expected_centers);
69  // expected_values = {0.0};
70  // EXPECT_EQ(item.binValues(), expected_values);
71 }
T * item(const std::string &tag) const
Returns first item under given tag casted to a specified type.
Definition: sessionitem.h:156

References ModelView::Data1DItem::binCenters(), ModelView::Data1DItem::binValues(), ModelView::SessionItem::item(), ModelView::Data1DItem::setAxis(), and ModelView::Data1DItem::T_AXIS.

Here is the call graph for this function:

◆ TEST_F() [6/9]

TEST_F ( Data1DItemTest  ,
setFixedBinAxisInModel   
)

Sets fixed bin axis via model context.

Definition at line 113 of file data1ditem.test.cpp.

114 {
115  SessionModel model;
116 
117  auto dataItem = model.insertItem<Data1DItem>();
118  model.insertItem<FixedBinAxisItem>(dataItem)->setParameters(5, 0.0, 5.0);
119 
120  // check type of the axis
121  EXPECT_TRUE(dataItem->item<FixedBinAxisItem>(Data1DItem::T_AXIS) != nullptr);
122 
123  // check bin centers and values
124  std::vector<double> expected_centers = {0.5, 1.5, 2.5, 3.5, 4.5};
125  EXPECT_EQ(dataItem->binCenters(), expected_centers);
126  std::vector<double> expected_values = std::vector<double>(expected_centers.size(), 0.0);
127  EXPECT_TRUE(dataItem->binValues().empty());
128 }

References ModelView::SessionModel::insertItem(), and ModelView::Data1DItem::T_AXIS.

Here is the call graph for this function:

◆ TEST_F() [7/9]

TEST_F ( Data1DItemTest  ,
setTemplatedFixedBinAxis   
)

Sets fixed bin axis via templated method.

Definition at line 75 of file data1ditem.test.cpp.

76 {
77  Data1DItem item;
78 
79  auto axis = item.setAxis<FixedBinAxisItem>(5, 0.0, 5.0);
80 
81  // check type of the axis
82  EXPECT_EQ(item.item<FixedBinAxisItem>(Data1DItem::T_AXIS), axis);
83 
84  // check bin centers and values
85  std::vector<double> expected_centers = {0.5, 1.5, 2.5, 3.5, 4.5};
86  EXPECT_EQ(item.binCenters(), expected_centers);
87  std::vector<double> expected_values = std::vector<double>(expected_centers.size(), 0.0);
88  EXPECT_EQ(item.binValues(), expected_values);
89 }

References ModelView::Data1DItem::binCenters(), ModelView::Data1DItem::binValues(), ModelView::SessionItem::item(), ModelView::Data1DItem::setAxis(), and ModelView::Data1DItem::T_AXIS.

Here is the call graph for this function:

◆ TEST_F() [8/9]

TEST_F ( Data1DItemTest  ,
setTemplatedFixedBinAxisInModelContext   
)

Sets fixed bin axis via templated method.

Definition at line 93 of file data1ditem.test.cpp.

94 {
95  SessionModel model;
96  auto dataItem = model.insertItem<Data1DItem>();
97 
98  auto axis = dataItem->setAxis<FixedBinAxisItem>(5, 0.0, 5.0);
99 
100  // check type of the axis
101  EXPECT_EQ(dataItem->item<FixedBinAxisItem>(Data1DItem::T_AXIS), axis);
102 
103  // check bin centers and values
104  std::vector<double> expected_centers = {0.5, 1.5, 2.5, 3.5, 4.5};
105  EXPECT_EQ(dataItem->binCenters(), expected_centers);
106  std::vector<double> expected_values = std::vector<double>(expected_centers.size(), 0.0);
107  EXPECT_EQ(dataItem->binValues(), expected_values);
108 }

References ModelView::SessionModel::insertItem(), ModelView::Data1DItem::setAxis(), and ModelView::Data1DItem::T_AXIS.

Here is the call graph for this function:

◆ TEST_F() [9/9]

TEST_F ( Data1DItemTest  ,
setValues   
)

Checking the method ::setValues.

Definition at line 132 of file data1ditem.test.cpp.

133 {
134  Data1DItem item;
135 
136  // check that it is not possible to set content to uninitialized axis
137  std::vector<double> expected_content = {1.0, 2.0, 3.0};
138  EXPECT_THROW(item.setValues(expected_content), std::runtime_error);
139 
140  item.setAxis<FixedBinAxisItem>(3, 0.0, 3.0);
141  item.setValues(expected_content);
142  EXPECT_EQ(item.binValues(), expected_content);
143 }
void setValues(const std::vector< double > &data)
Sets internal data buffer to given data.
Definition: data1ditem.cpp:66

References ModelView::Data1DItem::binValues(), ModelView::Data1DItem::setAxis(), and ModelView::Data1DItem::setValues().

Here is the call graph for this function: