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

Implements class CLASS? More...

Include dependency graph for data1dplotcontroller.test.cpp:

Go to the source code of this file.

Classes

class  Data1DPlotControllerTest
 Testing Data1DPlotController. More...
 

Functions

 TEST_F (Data1DPlotControllerTest, axisAfter)
 Testing controller when Data1DItem get it's axis after controller setup. More...
 
 TEST_F (Data1DPlotControllerTest, dataItemInInitialState)
 Testing controller when Data1DItem is not initialized properly. More...
 
 TEST_F (Data1DPlotControllerTest, dataPoints)
 Testing graph points update. More...
 
 TEST_F (Data1DPlotControllerTest, errorBars)
 Testing graph errors update. More...
 
 TEST_F (Data1DPlotControllerTest, initialState)
 Initial state. More...
 
 TEST_F (Data1DPlotControllerTest, twoDataItems)
 Testing two graph 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 data1dplotcontroller.test.cpp.

Function Documentation

◆ TEST_F() [1/6]

TEST_F ( Data1DPlotControllerTest  ,
axisAfter   
)

Testing controller when Data1DItem get it's axis after controller setup.

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

78 {
79  // creating custom plot and empty graph on it
80  auto custom_plot = std::make_unique<QCustomPlot>();
81  auto graph = custom_plot->addGraph();
82 
83  // creating data item with single point
84  SessionModel model;
85  auto data_item = model.insertItem<Data1DItem>();
86 
87  // creating controller and point it to Data1DItem
88  Data1DPlotController controller(graph);
89  controller.setItem(data_item);
90 
91  // setting correct axis
92  data_item->setAxis<FixedBinAxisItem>(1, 1.0, 2.0);
93  EXPECT_EQ(data_item->binCenters(), TestUtils::binCenters(graph));
94  EXPECT_EQ(data_item->binValues(), TestUtils::binValues(graph));
95  EXPECT_EQ(std::vector<double>(), TestUtils::binErrors(graph));
96 }
Represents one-dimensional data (axis and values).
Definition: data1ditem.h:30
Establishes communication between QCPGraph and Data1DItem.
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
std::vector< double > binValues(const QCPGraph *graph)
Returns vector representing y-values on QCPgraph.
std::vector< double > binErrors(const QCPGraph *graph)
Returns vector representing bin errors of QCPGraph.
std::vector< double > binCenters(const QCPGraph *graph)
Returns vector representing bin centers on QCPgraph.

References TestUtils::binCenters(), TestUtils::binErrors(), TestUtils::binValues(), and ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [2/6]

TEST_F ( Data1DPlotControllerTest  ,
dataItemInInitialState   
)

Testing controller when Data1DItem is not initialized properly.

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

57 {
58  // creating custom plot and empty graph on it
59  auto custom_plot = std::make_unique<QCustomPlot>();
60  auto graph = custom_plot->addGraph();
61 
62  // creating data item with single point
63  SessionModel model;
64  auto data_item = model.insertItem<Data1DItem>();
65 
66  // creating controller and point it to Data1DItem
67  Data1DPlotController controller(graph);
68  controller.setItem(data_item);
69 
70  EXPECT_EQ(std::vector<double>(), TestUtils::binCenters(graph));
71  EXPECT_EQ(std::vector<double>(), TestUtils::binValues(graph));
72  EXPECT_EQ(std::vector<double>(), TestUtils::binErrors(graph));
73 }

References TestUtils::binCenters(), TestUtils::binErrors(), TestUtils::binValues(), and ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [3/6]

TEST_F ( Data1DPlotControllerTest  ,
dataPoints   
)

Testing graph points update.

Definition at line 100 of file data1dplotcontroller.test.cpp.

101 {
102  // creating custom plot and empty graph on it
103  auto custom_plot = std::make_unique<QCustomPlot>();
104  auto graph = custom_plot->addGraph();
105 
106  // creating data item with single point
107  SessionModel model;
108  auto data_item = model.insertItem<Data1DItem>();
109  data_item->setAxis<FixedBinAxisItem>(1, 1.0, 2.0);
110 
111  // creating controller and point it to Data1DItem
112  Data1DPlotController controller(graph);
113  controller.setItem(data_item);
114 
115  // checking that QCPGraph now has data points as in Data1DItem
116  EXPECT_EQ(data_item->binCenters(), TestUtils::binCenters(graph));
117  EXPECT_EQ(data_item->binValues(), TestUtils::binValues(graph));
118  EXPECT_EQ(data_item->binErrors(), TestUtils::binErrors(graph));
119 
120  // Setting item to nullptr. Current convention is that graph stays intact, but points disappear.
121  controller.setItem(nullptr);
122  EXPECT_EQ(std::vector<double>(), TestUtils::binCenters(graph));
123  EXPECT_EQ(std::vector<double>(), TestUtils::binValues(graph));
124  EXPECT_EQ(std::vector<double>(), TestUtils::binErrors(graph));
125 }
T * setAxis(Args &&... args)
Inserts axis of given type.
Definition: data1ditem.h:56

References TestUtils::binCenters(), TestUtils::binErrors(), TestUtils::binValues(), ModelView::SessionModel::insertItem(), and ModelView::Data1DItem::setAxis().

Here is the call graph for this function:

◆ TEST_F() [4/6]

TEST_F ( Data1DPlotControllerTest  ,
errorBars   
)

Testing graph errors update.

Definition at line 129 of file data1dplotcontroller.test.cpp.

130 {
131  // creating custom plot and empty graph on it
132  auto custom_plot = std::make_unique<QCustomPlot>();
133  auto graph = custom_plot->addGraph();
134 
135  // creating data item with single point
136  SessionModel model;
137  auto data_item = model.insertItem<Data1DItem>();
138  data_item->setAxis<FixedBinAxisItem>(2, 1.0, 2.0);
139 
140  // creating controller and point it to Data1DItem
141  Data1DPlotController controller(graph);
142  controller.setItem(data_item);
143 
144  std::vector<double> expected_errors = {0.1, 0.2};
145  data_item->setErrors(expected_errors);
146  EXPECT_EQ(TestUtils::binErrors(graph), expected_errors);
147 
148  // setting new errors
149  expected_errors = {0.3, 0.4};
150  data_item->setErrors(expected_errors);
151  EXPECT_EQ(TestUtils::binErrors(graph), expected_errors);
152 }

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

Here is the call graph for this function:

◆ TEST_F() [5/6]

TEST_F ( Data1DPlotControllerTest  ,
initialState   
)

Initial state.

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

39 {
40  // Constructor accept valid QCPGraph
41  EXPECT_THROW(Data1DPlotController(nullptr), std::runtime_error);
42 
43  auto custom_plot = std::make_unique<QCustomPlot>();
44  auto graph = custom_plot->addGraph();
45 
46  Data1DPlotController controller(graph);
47  EXPECT_EQ(controller.currentItem(), nullptr);
48 
49  // no points have been added to graph
50  EXPECT_EQ(std::vector<double>(), TestUtils::binCenters(graph));
51  EXPECT_EQ(std::vector<double>(), TestUtils::binValues(graph));
52 }

References TestUtils::binCenters(), TestUtils::binValues(), and ModelView::ItemListener< T >::currentItem().

Here is the call graph for this function:

◆ TEST_F() [6/6]

TEST_F ( Data1DPlotControllerTest  ,
twoDataItems   
)

Testing two graph scenario.

Definition at line 156 of file data1dplotcontroller.test.cpp.

157 {
158  // creating custom plot and empty graph on it
159  auto custom_plot = std::make_unique<QCustomPlot>();
160  auto graph = custom_plot->addGraph();
161 
162  // creating two data items
163  SessionModel model;
164  auto data_item1 = model.insertItem<Data1DItem>();
165  data_item1->setAxis<FixedBinAxisItem>(1, 1.0, 2.0);
166  auto data_item2 = model.insertItem<Data1DItem>();
167  data_item2->setAxis<FixedBinAxisItem>(2, 0.0, 2.0);
168 
169  // creating controller and point it to first item
170  Data1DPlotController controller(graph);
171  controller.setItem(data_item1);
172 
173  // checking that QCPGraph now has data points as in first data item
174  EXPECT_EQ(data_item1->binCenters(), TestUtils::binCenters(graph));
175  EXPECT_EQ(data_item1->binValues(), TestUtils::binValues(graph));
176 
177  // pointing controller to the second item
178  controller.setItem(data_item2);
179  EXPECT_EQ(data_item2->binCenters(), TestUtils::binCenters(graph));
180  EXPECT_EQ(data_item2->binValues(), TestUtils::binValues(graph));
181 }
std::vector< double > binCenters() const override
Definition: axisitems.cpp:98

References ModelView::FixedBinAxisItem::binCenters(), TestUtils::binCenters(), TestUtils::binValues(), ModelView::SessionModel::insertItem(), and ModelView::Data1DItem::setAxis().

Here is the call graph for this function: