BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
taginfo.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/taginfo.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/taginfo.h"
17 
18 using namespace ModelView;
19 
20 //! Tests of TagInfo class.
21 
22 class TagInfoTest : public ::testing::Test {
23 public:
25 };
26 
27 TagInfoTest::~TagInfoTest() = default;
28 
29 TEST_F(TagInfoTest, initialState)
30 {
31  TagInfo tag;
32  EXPECT_EQ(tag.name(), std::string());
33  EXPECT_EQ(tag.min(), 0);
34  EXPECT_EQ(tag.max(), -1);
35  EXPECT_FALSE(tag.isSinglePropertyTag());
36  EXPECT_TRUE(tag.isValidChild(""));
37  EXPECT_TRUE(tag.isValidChild("abc"));
38 }
39 
40 //! Testing default tag intended for storing unlimited amount of items of any type.
41 
42 TEST_F(TagInfoTest, defaultTag)
43 {
44  // initial state
45  TagInfo tag = TagInfo::universalTag("name");
46  EXPECT_EQ(tag.name(), std::string("name"));
47  EXPECT_EQ(tag.min(), 0);
48  EXPECT_EQ(tag.max(), -1);
49  EXPECT_FALSE(tag.isSinglePropertyTag());
50  EXPECT_TRUE(tag.isValidChild(""));
51  EXPECT_TRUE(tag.isValidChild("abc"));
52 }
53 
54 //! Testing property tag intended for storing single PropertyItem.
55 
56 TEST_F(TagInfoTest, propertyTag)
57 {
58  // initial state
59  TagInfo tag = TagInfo::propertyTag("name", "model_type");
60 
61  EXPECT_EQ(tag.name(), std::string("name"));
62  EXPECT_EQ(tag.min(), 1);
63  EXPECT_EQ(tag.max(), 1);
64  EXPECT_TRUE(tag.isSinglePropertyTag());
65  EXPECT_TRUE(tag.isValidChild("model_type"));
66  EXPECT_FALSE(tag.isValidChild("abc"));
67 }
68 
69 //! Testing equality operators.
70 
71 TEST_F(TagInfoTest, equalityOperator)
72 {
73  // default constructor
74  TagInfo tag1, tag2;
75  EXPECT_TRUE(tag1 == tag2);
76  EXPECT_FALSE(tag1 != tag2);
77 
78  // same property tag
79  TagInfo tag3 = TagInfo::propertyTag("name", "model_type");
80  TagInfo tag4 = TagInfo::propertyTag("name", "model_type");
81  EXPECT_TRUE(tag3 == tag4);
82  EXPECT_FALSE(tag3 != tag4);
83 
84  // same universal tag
85  TagInfo tag5 = TagInfo::universalTag("name");
86  TagInfo tag6 = TagInfo::universalTag("name");
87  EXPECT_TRUE(tag5 == tag6);
88  EXPECT_FALSE(tag5 != tag6);
89 
90  // different tag
91  TagInfo tag7("tag7", 0, 1, std::vector<std::string>());
92  TagInfo tag8("tag8", 0, 1, std::vector<std::string>());
93  EXPECT_FALSE(tag7 == tag8);
94  EXPECT_TRUE(tag7 != tag8);
95 }
Holds info about single tag for SessionItem.
Definition: taginfo.h:28
std::string name() const
Definition: taginfo.cpp:45
int max() const
Definition: taginfo.cpp:55
bool isValidChild(const std::string &modelType) const
Returns true if given modelType matches the list of possible model types.
Definition: taginfo.cpp:67
int min() const
Definition: taginfo.cpp:50
bool isSinglePropertyTag() const
Returns true if this tag is used to store single properties.
Definition: taginfo.cpp:75
static TagInfo universalTag(std::string name, std::vector< std::string > modelTypes={})
Constructs universal tag intended for unlimited amount of various items.
Definition: taginfo.cpp:34
static TagInfo propertyTag(std::string name, std::string model_type)
Constructs tag intended for single property.
Definition: taginfo.cpp:40
Tests of TagInfo class.
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
TEST_F(TagInfoTest, initialState)