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

Implements class CLASS? More...

Include dependency graph for graphviewportitem.test.cpp:

Go to the source code of this file.

Classes

class  GraphViewportItemTest
 Testing AxesItems. More...
 

Functions

 TEST_F (GraphViewportItemTest, addItem)
 Add graph to viewport. More...
 
 TEST_F (GraphViewportItemTest, initialState)
 Initial state. More...
 
 TEST_F (GraphViewportItemTest, onAddItem)
 Check signaling on set data item. More...
 
 TEST_F (GraphViewportItemTest, onSetDataItem)
 Check signaling on set data item. More...
 
 TEST_F (GraphViewportItemTest, setViewportToContentWithMargins)
 Add graph to viewport. 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 graphviewportitem.test.cpp.

Function Documentation

◆ TEST_F() [1/5]

TEST_F ( GraphViewportItemTest  ,
addItem   
)

Add graph to viewport.

Definition at line 47 of file graphviewportitem.test.cpp.

48 {
49  SessionModel model;
50 
51  auto viewport_item = model.insertItem<GraphViewportItem>();
52  auto graph_item = model.insertItem<GraphItem>(viewport_item);
53  auto data_item = model.insertItem<Data1DItem>();
54 
55  const std::vector<double> expected_values = {1.0, 2.0, 3.0};
56  const std::vector<double> expected_centers = {0.5, 1.5, 2.5};
57  data_item->setAxis<FixedBinAxisItem>(3, 0.0, 3.0);
58  data_item->setValues(expected_values);
59 
60  graph_item->setDataItem(data_item);
61  EXPECT_EQ(viewport_item->graphItems().size(), 1);
62 
63  // updating viewport to graph
64  viewport_item->setViewportToContent();
65 
66  // x-axis of viewport should be set to FixedBinAxis of DataItem
67  auto xaxis = viewport_item->xAxis();
68  EXPECT_DOUBLE_EQ(xaxis->property<double>(ViewportAxisItem::P_MIN), expected_centers[0]);
69  EXPECT_DOUBLE_EQ(xaxis->property<double>(ViewportAxisItem::P_MAX), expected_centers[2]);
70 
71  // y-axis of viewport should be set to min/max of expected_content
72  auto yaxis = viewport_item->yAxis();
73  auto [expected_amin, expected_amax] =
74  std::minmax_element(std::begin(expected_values), std::end(expected_values));
75  EXPECT_DOUBLE_EQ(yaxis->property<double>(ViewportAxisItem::P_MIN), *expected_amin);
76  EXPECT_DOUBLE_EQ(yaxis->property<double>(ViewportAxisItem::P_MAX), *expected_amax);
77 }
Represents one-dimensional data (axis and values).
Definition: data1ditem.h:30
Item to represent fixed bin axis.
Definition: axisitems.h:75
One-dimensional graph representation of Data1DItem.
Definition: graphitem.h:29
2D viewport specialized for showing multiple GraphItem's.
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

References ModelView::SessionModel::insertItem(), ModelView::BasicAxisItem::P_MAX, and ModelView::BasicAxisItem::P_MIN.

Here is the call graph for this function:

◆ TEST_F() [2/5]

TEST_F ( GraphViewportItemTest  ,
initialState   
)

Initial state.

Definition at line 37 of file graphviewportitem.test.cpp.

38 {
39  GraphViewportItem item;
40  EXPECT_EQ(item.xAxis()->modelType(), Constants::ViewportAxisItemType);
41  EXPECT_EQ(item.yAxis()->modelType(), Constants::ViewportAxisItemType);
42  EXPECT_EQ(item.graphItems().size(), 0);
43 }
std::vector< GraphItem * > graphItems() const
Returns the selected graph items.
model_type modelType() const
Returns item's model type.
Definition: sessionitem.cpp:80
ViewportAxisItem * xAxis() const
ViewportAxisItem * yAxis() const
const model_type ViewportAxisItemType
Definition: mvvm_types.h:62

References ModelView::GraphViewportItem::graphItems(), ModelView::SessionItem::modelType(), ModelView::Constants::ViewportAxisItemType, ModelView::ViewportItem::xAxis(), and ModelView::ViewportItem::yAxis().

Here is the call graph for this function:

◆ TEST_F() [3/5]

TEST_F ( GraphViewportItemTest  ,
onAddItem   
)

Check signaling on set data item.

Definition at line 81 of file graphviewportitem.test.cpp.

82 {
83  SessionModel model;
84  auto viewport_item = model.insertItem<GraphViewportItem>();
85 
86  MockWidgetForItem widget(viewport_item);
87 
88  const TagRow expected_tagrow{ViewportItem::T_ITEMS, 0};
89  EXPECT_CALL(widget, onDataChange(_, _)).Times(0);
90  EXPECT_CALL(widget, onPropertyChange(_, _)).Times(0);
91  EXPECT_CALL(widget, onChildPropertyChange(_, _)).Times(0);
92  EXPECT_CALL(widget, onItemInserted(viewport_item, expected_tagrow)).Times(1);
93  EXPECT_CALL(widget, onAboutToRemoveItem(_, _)).Times(0);
94 
95  // triggering action
96  model.insertItem<GraphItem>(viewport_item);
97 }
Mock widget to test ItemMapper functionality.
Definition: mockwidgets.h:36
Aggregate to hold (tag, row) information for SessionModel.
Definition: tagrow.h:25

References ModelView::SessionModel::insertItem(), and ModelView::ViewportItem::T_ITEMS.

Here is the call graph for this function:

◆ TEST_F() [4/5]

TEST_F ( GraphViewportItemTest  ,
onSetDataItem   
)

Check signaling on set data item.

Definition at line 101 of file graphviewportitem.test.cpp.

102 {
103  SessionModel model;
104  auto viewport_item = model.insertItem<GraphViewportItem>();
105 
106  // setting upda tata item
107  auto data_item = model.insertItem<Data1DItem>();
108  const std::vector<double> expected_values = {1.0, 2.0, 3.0};
109  const std::vector<double> expected_centers = {0.5, 1.5, 2.5};
110  data_item->setAxis<FixedBinAxisItem>(3, 0.0, 3.0);
111  data_item->setValues(expected_values);
112 
113  // inserting graph item
114  auto graph_item = model.insertItem<GraphItem>(viewport_item);
115 
116  MockWidgetForItem widget(viewport_item);
117 
118  EXPECT_CALL(widget, onDataChange(_, _)).Times(0);
119  EXPECT_CALL(widget, onPropertyChange(_, _)).Times(0);
120  EXPECT_CALL(widget, onChildPropertyChange(graph_item, GraphItem::P_LINK)).Times(1);
121  EXPECT_CALL(widget, onItemInserted(_, _)).Times(0);
122  EXPECT_CALL(widget, onAboutToRemoveItem(_, _)).Times(0);
123 
124  // triggering action
125  graph_item->setDataItem(data_item);
126 }

References ModelView::SessionModel::insertItem(), and ModelView::GraphItem::P_LINK.

Here is the call graph for this function:

◆ TEST_F() [5/5]

TEST_F ( GraphViewportItemTest  ,
setViewportToContentWithMargins   
)

Add graph to viewport.

Definition at line 130 of file graphviewportitem.test.cpp.

131 {
132  SessionModel model;
133 
134  auto viewport_item = model.insertItem<GraphViewportItem>();
135  auto graph_item = model.insertItem<GraphItem>(viewport_item);
136  auto data_item = model.insertItem<Data1DItem>();
137 
138  const std::vector<double> expected_values = {1.0, 2.0, 3.0};
139  const std::vector<double> expected_centers = {0.5, 1.5, 2.5};
140  data_item->setAxis<FixedBinAxisItem>(3, 0.0, 3.0);
141  data_item->setValues(expected_values);
142 
143  graph_item->setDataItem(data_item);
144  EXPECT_EQ(viewport_item->graphItems().size(), 1);
145 
146  // updating viewport to graph
147  const double bottom{0.1}, top{0.1};
148  viewport_item->setViewportToContent(0.0, top, 0.0, bottom);
149 
150  // x-axis of viewport should be set to FixedBinAxis of DataItem
151  auto xaxis = viewport_item->xAxis();
152  EXPECT_DOUBLE_EQ(xaxis->property<double>(ViewportAxisItem::P_MIN), expected_centers[0]);
153  EXPECT_DOUBLE_EQ(xaxis->property<double>(ViewportAxisItem::P_MAX), expected_centers[2]);
154 
155  // y-axis of viewport should be set to min/max of expected_content
156  auto yaxis = viewport_item->yAxis();
157  auto [expected_amin, expected_amax] =
158  std::minmax_element(std::begin(expected_values), std::end(expected_values));
159 
160  double expected_ymin = *expected_amin - (*expected_amax - *expected_amin) * bottom;
161  double expected_ymax = *expected_amax + (*expected_amax - *expected_amin) * top;
162  EXPECT_DOUBLE_EQ(yaxis->property<double>(ViewportAxisItem::P_MIN), expected_ymin);
163  EXPECT_DOUBLE_EQ(yaxis->property<double>(ViewportAxisItem::P_MAX), expected_ymax);
164 }

References ModelView::SessionModel::insertItem(), ModelView::BasicAxisItem::P_MAX, and ModelView::BasicAxisItem::P_MIN.

Here is the call graph for this function: