BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
tagrow.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/tagrow.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"
16 #include "mvvm/model/tagrow.h"
17 
18 using namespace ModelView;
19 
20 //! Testing AxisItems.
21 
22 class TagRowTest : public ::testing::Test {
23 public:
25 
26  TagRow test_method(const TagRow& input) { return input; }
27 };
28 
29 TagRowTest::~TagRowTest() = default;
30 
31 //! Initial state.
32 
33 TEST_F(TagRowTest, initialState)
34 {
35  TagRow tagrow;
36  EXPECT_EQ(tagrow.tag, "");
37  EXPECT_EQ(tagrow.row, -1);
38 }
39 
40 //! Brace initializer.
41 
42 TEST_F(TagRowTest, braceInitializer)
43 {
44  TagRow tagrow{"abc", 42};
45  EXPECT_EQ(tagrow.tag, "abc");
46  EXPECT_EQ(tagrow.row, 42);
47 
48  tagrow = {};
49  EXPECT_EQ(tagrow.tag, "");
50  EXPECT_EQ(tagrow.row, -1);
51 
52  tagrow = {"cde", 43};
53  EXPECT_EQ(tagrow.tag, "cde");
54  EXPECT_EQ(tagrow.row, 43);
55 
56  TagRow tagrow2 = {"cde"};
57  EXPECT_EQ(tagrow2.tag, "cde");
58  EXPECT_EQ(tagrow2.row, -1);
59 }
60 
61 //! Equality operators.
62 
63 TEST_F(TagRowTest, equalityOperators)
64 {
65  TagRow tag1;
66  TagRow tag2;
67  EXPECT_TRUE(tag1 == tag2);
68  EXPECT_FALSE(tag1 != tag2);
69 
70  TagRow tag3 = {"abc", 42};
71  TagRow tag4 = {"abc", 42};
72  EXPECT_TRUE(tag3 == tag4);
73  EXPECT_FALSE(tag3 != tag4);
74 
75  TagRow tag5 = {"abc", 42};
76  TagRow tag6 = {"abc", 43};
77  EXPECT_FALSE(tag5 == tag6);
78  EXPECT_TRUE(tag5 != tag6);
79 
80  TagRow tag7 = {"a", 42};
81  TagRow tag8 = {"b", 42};
82  EXPECT_FALSE(tag7 == tag8);
83  EXPECT_TRUE(tag7 != tag8);
84 }
85 
86 //! Assignment operators.
87 
88 TEST_F(TagRowTest, assignmentOperator)
89 {
90  TagRow tag1;
91  TagRow tag2{"abc", 42};
92 
93  tag1 = tag2;
94  EXPECT_EQ(tag1.row, 42);
95  EXPECT_EQ(tag1.tag, "abc");
96 }
97 
98 //! Factory methods.
99 
100 TEST_F(TagRowTest, factoryMethods)
101 {
102  auto tagrow = TagRow::append();
103  EXPECT_EQ(tagrow.tag, "");
104  EXPECT_EQ(tagrow.row, -1);
105 
106  const std::string expected_name("tag");
107  tagrow = TagRow::append(expected_name);
108  EXPECT_EQ(tagrow.tag, expected_name);
109  EXPECT_EQ(tagrow.row, -1);
110 
111  tagrow = TagRow::prepend(expected_name);
112  EXPECT_EQ(tagrow.tag, expected_name);
113  EXPECT_EQ(tagrow.row, 0);
114 }
115 
116 //! Implicit type convertion
117 
118 TEST_F(TagRowTest, implicitConvertion)
119 {
120  auto tagrow = test_method("abc");
121  EXPECT_EQ(tagrow.tag, "abc");
122  EXPECT_EQ(tagrow.row, -1);
123 }
124 
125 //! Find next tagrow.
126 
128 {
129  TagRow tagrow{"tag", 0};
130  EXPECT_EQ(tagrow.next().tag, "tag");
131  EXPECT_EQ(tagrow.next().row, 1);
132 }
133 
134 //! Find previous tagrow.
135 
137 {
138  TagRow tagrow{"tag", 1};
139  EXPECT_EQ(tagrow.prev().tag, "tag");
140  EXPECT_EQ(tagrow.prev().row, 0);
141 }
Aggregate to hold (tag, row) information for SessionModel.
Definition: tagrow.h:25
static TagRow append(const std::string &tag_name={})
Returns TagRow corresponding to the append to tag_name.
Definition: tagrow.cpp:36
static TagRow prepend(const std::string &tag_name={})
Returns TagRow corresponding to prepending to tag_name.
Definition: tagrow.cpp:44
std::string tag
Definition: tagrow.h:27
Testing AxisItems.
Definition: tagrow.test.cpp:22
TagRow test_method(const TagRow &input)
Definition: tagrow.test.cpp:26
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
TEST_F(TagRowTest, initialState)
Initial state.
Definition: tagrow.test.cpp:33