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

Implements class CLASS? More...

Include dependency graph for data2dplotcontroller.test.cpp:

Go to the source code of this file.

Classes

class  Data2DPlotControllerTest
 Testing Data1DPlotController. More...
 

Functions

 TEST_F (Data2DPlotControllerTest, dataItemInInitialState)
 Testing controller when Data2DItem is not initialized properly. More...
 
 TEST_F (Data2DPlotControllerTest, dataPoints)
 Testing data points. More...
 
 TEST_F (Data2DPlotControllerTest, dataRange)
 Testing data range. More...
 
 TEST_F (Data2DPlotControllerTest, initialState)
 Initial state. More...
 
 TEST_F (Data2DPlotControllerTest, setAxesAfter)
 Testing controller when Data2DItem got it's axes after controller was set. More...
 
 TEST_F (Data2DPlotControllerTest, twoDataItems)
 Testing two colormap scenario. 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 data2dplotcontroller.test.cpp.

Function Documentation

◆ TEST_F() [1/6]

TEST_F ( Data2DPlotControllerTest  ,
dataItemInInitialState   
)

Testing controller when Data2DItem is not initialized properly.

Definition at line 56 of file data2dplotcontroller.test.cpp.

57 {
58  // creating custom plot and empty graph on it
59  auto custom_plot = std::make_unique<QCustomPlot>();
60  auto color_map = new QCPColorMap(custom_plot->xAxis, custom_plot->yAxis);
61 
62  // creating data item with single point
63  SessionModel model;
64  auto data_item = model.insertItem<Data2DItem>();
65 
66  // creating controller and point it to Data2DItem
67  Data2DPlotController controller(color_map);
68  EXPECT_NO_THROW(controller.setItem(data_item));
69 
70  // Since data item doesn't contain axes defined, should be no points on colormap.
71  EXPECT_EQ(color_map->data()->keySize(), 0);
72  EXPECT_EQ(color_map->data()->valueSize(), 0);
73 }
Represents two-dimensional data (axes definition and 2d array of values).
Definition: data2ditem.h:29
Establish communication between QCPColorMap and Data2DItem.
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().

Here is the call graph for this function:

◆ TEST_F() [2/6]

TEST_F ( Data2DPlotControllerTest  ,
dataPoints   
)

Testing data points.

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

106 {
107  // creating custom plot and empty graph on it
108  auto custom_plot = std::make_unique<QCustomPlot>();
109  auto color_map = new QCPColorMap(custom_plot->xAxis, custom_plot->yAxis);
110 
111  // creating data item with single point
112  SessionModel model;
113  auto data_item = model.insertItem<Data2DItem>();
114  const int nx = 3, ny = 2;
115  data_item->setAxes(FixedBinAxisItem::create(nx, 0.0, 3.0),
116  FixedBinAxisItem::create(ny, 0.0, 2.0));
117 
118  // creating controller and point it to Data2DItem
119  Data2DPlotController controller(color_map);
120  controller.setItem(data_item);
121 
122  EXPECT_EQ(color_map->data()->keySize(), nx);
123  EXPECT_EQ(color_map->data()->valueSize(), ny);
124  EXPECT_EQ(color_map->data()->cell(0, 0), 0.0);
125  EXPECT_EQ(color_map->data()->cell(nx - 1, ny - 1), 0.0);
126 
127  // setting data points
128  std::vector<double> expected = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
129  data_item->setContent(expected);
130  EXPECT_EQ(color_map->data()->cell(0, 0), 1.0);
131  EXPECT_EQ(color_map->data()->cell(nx - 1, ny - 1), 6.0);
132 
133  // Setting item to nullptr. Current convention is that QCPColorMap loses its data.
134  controller.setItem(nullptr);
135  EXPECT_EQ(color_map->data()->keySize(), 0);
136  EXPECT_EQ(color_map->data()->valueSize(), 0);
137 }
void setAxes(std::unique_ptr< BinnedAxisItem > x_axis, std::unique_ptr< BinnedAxisItem > y_axis)
Sets axes and put data points to zero.
Definition: data2ditem.cpp:41

References ModelView::FixedBinAxisItem::create(), ModelView::SessionModel::insertItem(), ModelView::Data2DItem::setAxes(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function:

◆ TEST_F() [3/6]

TEST_F ( Data2DPlotControllerTest  ,
dataRange   
)

Testing data range.

Definition at line 182 of file data2dplotcontroller.test.cpp.

183 {
184  // creating custom plot and empty graph on it
185  auto custom_plot = std::make_unique<QCustomPlot>();
186  auto color_map = new QCPColorMap(custom_plot->xAxis, custom_plot->yAxis);
187 
188  // creating data item with single point
189  SessionModel model;
190  auto data_item = model.insertItem<Data2DItem>();
191  const int nx = 3, ny = 2;
192  data_item->setAxes(FixedBinAxisItem::create(nx, 0.0, 3.0),
193  FixedBinAxisItem::create(ny, 0.0, 2.0));
194  std::vector<double> expected = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
195  data_item->setContent(expected);
196 
197  // creating controller and point it to Data2DItem
198  Data2DPlotController controller(color_map);
199  controller.setItem(data_item);
200 
201  QSignalSpy spy(color_map, &QCPColorMap::dataRangeChanged);
202 
203  auto range = color_map->dataRange();
204  EXPECT_EQ(spy.count(), 0);
205  EXPECT_EQ(range.lower, 1.0);
206  EXPECT_EQ(range.upper, 6.0);
207 }

References ModelView::FixedBinAxisItem::create(), ModelView::SessionModel::insertItem(), ModelView::Data2DItem::setAxes(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function:

◆ TEST_F() [4/6]

TEST_F ( Data2DPlotControllerTest  ,
initialState   
)

Initial state.

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

39 {
40  // Constructor accept valid QCPColorMap
41  EXPECT_THROW(Data2DPlotController(nullptr), std::runtime_error);
42 
43  auto custom_plot = std::make_unique<QCustomPlot>();
44  auto color_map = new QCPColorMap(custom_plot->xAxis, custom_plot->yAxis);
45  color_map->data()->clear(); // to remove default values defined in QCPColorMap
46 
47  Data2DPlotController controller(color_map);
48  EXPECT_EQ(controller.currentItem(), nullptr);
49 
50  EXPECT_EQ(color_map->data()->keySize(), 0);
51  EXPECT_EQ(color_map->data()->valueSize(), 0);
52 }

References ModelView::ItemListener< T >::currentItem().

Here is the call graph for this function:

◆ TEST_F() [5/6]

TEST_F ( Data2DPlotControllerTest  ,
setAxesAfter   
)

Testing controller when Data2DItem got it's axes after controller was set.

Definition at line 77 of file data2dplotcontroller.test.cpp.

78 {
79  // creating custom plot and empty graph on it
80  auto custom_plot = std::make_unique<QCustomPlot>();
81  auto color_map = new QCPColorMap(custom_plot->xAxis, custom_plot->yAxis);
82 
83  // creating data item with single point
84  SessionModel model;
85  auto data_item = model.insertItem<Data2DItem>();
86 
87  // creating controller and point it to Data2DItem
88  Data2DPlotController controller(color_map);
89  EXPECT_NO_THROW(controller.setItem(data_item));
90 
91  // setting axes after
92  const int nx = 3, ny = 2;
93  data_item->setAxes(FixedBinAxisItem::create(nx, 0.0, 3.0),
94  FixedBinAxisItem::create(ny, 0.0, 2.0));
95 
96  // color map should get shape of axes
97  EXPECT_EQ(color_map->data()->keySize(), nx);
98  EXPECT_EQ(color_map->data()->valueSize(), ny);
99  EXPECT_EQ(color_map->data()->cell(0, 0), 0.0);
100  EXPECT_EQ(color_map->data()->cell(nx - 1, ny - 1), 0.0);
101 }

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

Here is the call graph for this function:

◆ TEST_F() [6/6]

TEST_F ( Data2DPlotControllerTest  ,
twoDataItems   
)

Testing two colormap scenario.

Definition at line 141 of file data2dplotcontroller.test.cpp.

142 {
143  // creating custom plot and empty graph on it
144  auto custom_plot = std::make_unique<QCustomPlot>();
145  auto color_map = new QCPColorMap(custom_plot->xAxis, custom_plot->yAxis);
146 
147  // creating data item with single point
148  SessionModel model;
149  auto data_item1 = model.insertItem<Data2DItem>();
150  const int nx1 = 3, ny1 = 2;
151  std::vector<double> expected1 = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
152  data_item1->setAxes(FixedBinAxisItem::create(nx1, 0.0, 3.0),
153  FixedBinAxisItem::create(ny1, 0.0, 2.0));
154  data_item1->setContent(expected1);
155  auto data_item2 = model.insertItem<Data2DItem>();
156  const int nx2 = 2, ny2 = 1;
157  std::vector<double> expected2 = {10.0, 20.0};
158  data_item2->setAxes(FixedBinAxisItem::create(nx2, 0.0, 3.0),
159  FixedBinAxisItem::create(ny2, 0.0, 2.0));
160  data_item2->setContent(expected2);
161 
162  // creating controller and point it to first Data2DItem
163  Data2DPlotController controller(color_map);
164  controller.setItem(data_item1);
165 
166  EXPECT_EQ(color_map->data()->keySize(), nx1);
167  EXPECT_EQ(color_map->data()->valueSize(), ny1);
168  EXPECT_EQ(color_map->data()->cell(0, 0), 1.0);
169  EXPECT_EQ(color_map->data()->cell(nx1 - 1, ny1 - 1), 6.0);
170 
171  // pointing controller to the second Data2DItem
172  controller.setItem(data_item2);
173 
174  EXPECT_EQ(color_map->data()->keySize(), nx2);
175  EXPECT_EQ(color_map->data()->valueSize(), ny2);
176  EXPECT_EQ(color_map->data()->cell(0, 0), 10.0);
177  EXPECT_EQ(color_map->data()->cell(nx2 - 1, ny2 - 1), 20.0);
178 }

References ModelView::FixedBinAxisItem::create(), ModelView::SessionModel::insertItem(), ModelView::Data2DItem::setAxes(), and ModelView::ItemListenerBase::setItem().

Here is the call graph for this function: