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

Implements class CLASS? More...

Include dependency graph for colormapviewportitem.test.cpp:

Go to the source code of this file.

Classes

class  ColorMapViewportItemTest
 Testing ColorMapViewportItem. More...
 

Functions

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

Function Documentation

◆ TEST_F() [1/5]

TEST_F ( ColorMapViewportItemTest  ,
addItem   
)

Add graph to viewport.

Definition at line 74 of file colormapviewportitem.test.cpp.

75 {
76  SessionModel model;
77 
78  auto viewport_item = model.insertItem<ColorMapViewportItem>();
79  auto colormap_item = model.insertItem<ColorMapItem>(viewport_item);
80  auto data_item = model.insertItem<Data2DItem>();
81 
82  data_item->setAxes(FixedBinAxisItem::create(2, 0.0, 2.0),
83  FixedBinAxisItem::create(3, 0.0, 3.0));
84  const std::vector<double> expected_content = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
85  data_item->setContent(expected_content);
86 
87  colormap_item->setDataItem(data_item);
88  EXPECT_EQ(viewport_item->items<ColorMapItem>(ColorMapViewportItem::T_ITEMS).size(), 1);
89 
90  // updating viewport to graph
91  viewport_item->setViewportToContent();
92 
93  // x-axis of viewport should be set Data2DItem
94  auto [xmin, xmax] = viewport_item->xAxis()->range();
95  EXPECT_DOUBLE_EQ(xmin, 0.0);
96  EXPECT_DOUBLE_EQ(xmax, 2.0);
97 
98  // y-axis of viewport should be set Data2DItem
99  auto [ymin, ymax] = viewport_item->yAxis()->range();
100  EXPECT_DOUBLE_EQ(ymin, 0.0);
101  EXPECT_DOUBLE_EQ(ymax, 3.0);
102 
103  // z-axis of viewport should be set to min/max content
104  auto [zmin, zmax] = viewport_item->zAxis()->range();
105  EXPECT_DOUBLE_EQ(zmin, 1.0);
106  EXPECT_DOUBLE_EQ(zmax, 6.0);
107 }
Two-dimensional color map representation of Data2DItem.
Definition: colormapitem.h:28
Container with viewport and collection of ColorMapItem's to plot.
Represents two-dimensional data (axes definition and 2d array of values).
Definition: data2ditem.h:29
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::FixedBinAxisItem::create(), ModelView::SessionModel::insertItem(), and ModelView::ViewportItem::T_ITEMS.

Here is the call graph for this function:

◆ TEST_F() [2/5]

TEST_F ( ColorMapViewportItemTest  ,
initialState   
)

Initial state.

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

38 {
39  ColorMapViewportItem viewport;
40  EXPECT_EQ(viewport.xAxis()->modelType(), Constants::ViewportAxisItemType);
41  EXPECT_EQ(viewport.yAxis()->modelType(), Constants::ViewportAxisItemType);
42  EXPECT_EQ(viewport.zAxis()->modelType(), Constants::ViewportAxisItemType);
43  EXPECT_EQ(viewport.items<ColorMapItem>(ColorMapViewportItem::T_ITEMS).size(), 0);
44 }
ViewportAxisItem * zAxis() const
std::vector< T * > items(const std::string &tag) const
Returns all items under given tag casted to specific type.
Definition: sessionitem.h:169
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::SessionItem::items(), ModelView::SessionItem::modelType(), ModelView::ViewportItem::T_ITEMS, ModelView::Constants::ViewportAxisItemType, ModelView::ViewportItem::xAxis(), ModelView::ViewportItem::yAxis(), and ModelView::ColorMapViewportItem::zAxis().

Here is the call graph for this function:

◆ TEST_F() [3/5]

TEST_F ( ColorMapViewportItemTest  ,
onAddItem   
)

Check signaling on set data item.

Definition at line 111 of file colormapviewportitem.test.cpp.

112 {
113  SessionModel model;
114  auto viewport_item = model.insertItem<ColorMapViewportItem>();
115 
116  MockWidgetForItem widget(viewport_item);
117 
118  const TagRow expected_tagrow{ViewportItem::T_ITEMS, 0};
119  EXPECT_CALL(widget, onDataChange(_, _)).Times(0);
120  EXPECT_CALL(widget, onPropertyChange(_, _)).Times(0);
121  EXPECT_CALL(widget, onChildPropertyChange(_, _)).Times(0);
122  EXPECT_CALL(widget, onItemInserted(viewport_item, expected_tagrow)).Times(1);
123  EXPECT_CALL(widget, onAboutToRemoveItem(_, _)).Times(0);
124 
125  // triggering action
126  model.insertItem<ColorMapItem>(viewport_item);
127 }
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 ( ColorMapViewportItemTest  ,
onSetDataItem   
)

Check signaling on set data item.

Definition at line 131 of file colormapviewportitem.test.cpp.

132 {
133  SessionModel model;
134  auto viewport_item = model.insertItem<ColorMapViewportItem>();
135 
136  // setting upda tata item
137  auto data_item = model.insertItem<Data2DItem>();
138 
139  data_item->setAxes(FixedBinAxisItem::create(2, 0.0, 2.0),
140  FixedBinAxisItem::create(3, 0.0, 3.0));
141  const std::vector<double> expected_content = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
142  data_item->setContent(expected_content);
143 
144  // inserting graph item
145  auto colormap_item = model.insertItem<ColorMapItem>(viewport_item);
146 
147  MockWidgetForItem widget(viewport_item);
148 
149  EXPECT_CALL(widget, onDataChange(_, _)).Times(0);
150  EXPECT_CALL(widget, onPropertyChange(_, _)).Times(0);
151  EXPECT_CALL(widget, onChildPropertyChange(colormap_item, ColorMapItem::P_LINK)).Times(1);
152  EXPECT_CALL(widget, onItemInserted(_, _)).Times(0);
153  EXPECT_CALL(widget, onAboutToRemoveItem(_, _)).Times(0);
154 
155  // triggering action
156  colormap_item->setDataItem(data_item);
157 }

References ModelView::FixedBinAxisItem::create(), ModelView::SessionModel::insertItem(), and ModelView::ColorMapItem::P_LINK.

Here is the call graph for this function:

◆ TEST_F() [5/5]

TEST_F ( ColorMapViewportItemTest  ,
uninitializedViewportUpdate   
)

Update on unitialized viewport.

Definition at line 48 of file colormapviewportitem.test.cpp.

49 {
50  SessionModel model;
51 
52  auto viewport_item = model.insertItem<ColorMapViewportItem>();
53 
54  viewport_item->setViewportToContent();
55 
56  // x-axis of viewport should be set Data2DItem
57  auto [xmin, xmax] = viewport_item->xAxis()->range();
58  EXPECT_DOUBLE_EQ(xmin, 0.0);
59  EXPECT_DOUBLE_EQ(xmax, 1.0);
60 
61  // y-axis of viewport should be set Data2DItem
62  auto [ymin, ymax] = viewport_item->yAxis()->range();
63  EXPECT_DOUBLE_EQ(ymin, 0.0);
64  EXPECT_DOUBLE_EQ(ymax, 1.0);
65 
66  // z-axis of viewport should be set to min/max content
67  auto [zmin, zmax] = viewport_item->zAxis()->range();
68  EXPECT_DOUBLE_EQ(zmin, 0.0);
69  EXPECT_DOUBLE_EQ(zmax, 1.0);
70 }
void setViewportToContent() override
Sets range of x,y window to show all data.

References ModelView::SessionModel::insertItem(), and ModelView::ColorMapViewportItem::setViewportToContent().

Here is the call graph for this function: