BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
progresshandler.test.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/tests/testmodel/progresshandler.test.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "google_test.h"
17 
18 using namespace ModelView;
19 
20 class ProgressHandlerTest : public ::testing::Test {
21 public:
23 };
24 
26 
28 {
29  ProgressHandler handler;
30  EXPECT_FALSE(handler.has_interrupt_request());
31 }
32 
33 TEST_F(ProgressHandlerTest, fullConstructor)
34 {
35  size_t max_ticks = 1000;
36  int progress{0};
37  auto on_progress_change = [&progress](int value) {
38  progress = value;
39  return false;
40  };
41 
42  ProgressHandler handler(on_progress_change, max_ticks);
43 
44  handler.setCompletedTicks(100);
45  EXPECT_FALSE(handler.has_interrupt_request());
46  EXPECT_EQ(progress, 10);
47 
48  handler.setCompletedTicks(900);
49  EXPECT_FALSE(handler.has_interrupt_request());
50  EXPECT_EQ(progress, 100); // reports value in percents
51 }
52 
53 TEST_F(ProgressHandlerTest, interruptRequest)
54 {
55  size_t max_ticks = 1000;
56  int progress{0};
57  auto on_progress_change = [&progress](int value) {
58  progress = value;
59  return true;
60  };
61 
62  ProgressHandler handler(on_progress_change, max_ticks);
63 
64  handler.setCompletedTicks(1000);
65  EXPECT_TRUE(handler.has_interrupt_request());
66  EXPECT_EQ(progress, 100); // reports value in percents
67 
68  // checking reset
69  handler.reset();
70  EXPECT_FALSE(handler.has_interrupt_request());
71  handler.setCompletedTicks(100);
72  EXPECT_EQ(progress, 10); // reports value in percents
73 }
Maintain information about progress of a computation.
void setCompletedTicks(size_t value)
Increment number of completed computation steps.
void reset()
Resets progress.
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
TEST_F(ProgressHandlerTest, initialState)