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

Implements class CLASS? More...

Include dependency graph for containerutils.test.cpp:

Go to the source code of this file.

Classes

class  ContainerUtilsTest
 Tests of container utils. More...
 

Functions

 TEST_F (ContainerUtilsTest, Contains)
 
 TEST_F (ContainerUtilsTest, IndexOfItem)
 
 TEST_F (ContainerUtilsTest, isUniquePtr)
 
 TEST_F (ContainerUtilsTest, Real)
 
 TEST_F (ContainerUtilsTest, UniqueWithOrder)
 

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 containerutils.test.cpp.

Function Documentation

◆ TEST_F() [1/5]

TEST_F ( ContainerUtilsTest  ,
Contains   
)

Definition at line 78 of file containerutils.test.cpp.

79 {
80  std::vector<int> data = {1, 42, 1, 6, 43, 6};
81  EXPECT_TRUE(Utils::Contains(data, 42));
82  EXPECT_FALSE(Utils::Contains(data, 99));
83 }
bool Contains(const A &container, const B &element)
Returns true if container contains a given element.

References ModelView::Utils::Contains().

Here is the call graph for this function:

◆ TEST_F() [2/5]

TEST_F ( ContainerUtilsTest  ,
IndexOfItem   
)

Definition at line 37 of file containerutils.test.cpp.

38 {
39  // searching in vector of integers
40  std::vector<int> vv{1, 7, 5};
41  EXPECT_EQ(Utils::IndexOfItem(vv, 1), 0);
42  EXPECT_EQ(Utils::IndexOfItem(vv, 10), -1);
43  EXPECT_EQ(Utils::IndexOfItem(vv, 5), 2);
44  EXPECT_EQ(Utils::IndexOfItem(vv.begin(), vv.end(), 7), 1);
45 
46  // searching in vector of SessionItem's
47  std::vector<SessionItem*> items{new SessionItem, new SessionItem, new SessionItem};
48  SessionItem other;
49  EXPECT_EQ(Utils::IndexOfItem(items, items[0]), 0);
50  EXPECT_EQ(Utils::IndexOfItem(items, items[1]), 1);
51  EXPECT_EQ(Utils::IndexOfItem(items, items[2]), 2);
52  EXPECT_EQ(Utils::IndexOfItem(items, &other), -1);
53  for (auto x : items)
54  delete x;
55 
56  // searching in vector of unique_ptr
57  std::vector<std::unique_ptr<SessionItem>> unique_items;
58  unique_items.emplace_back(std::make_unique<SessionItem>());
59  unique_items.emplace_back(std::make_unique<SessionItem>());
60  EXPECT_EQ(Utils::IndexOfItem(unique_items, unique_items[0].get()), 0);
61  EXPECT_EQ(Utils::IndexOfItem(unique_items, unique_items[1].get()), 1);
62  EXPECT_EQ(Utils::IndexOfItem(unique_items, &other), -1);
63 }
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
int IndexOfItem(It begin, It end, const T &item)
Returns index corresponding to the first occurance of the item in the container.

References ModelView::Utils::IndexOfItem().

Here is the call graph for this function:

◆ TEST_F() [3/5]

TEST_F ( ContainerUtilsTest  ,
isUniquePtr   
)

Definition at line 31 of file containerutils.test.cpp.

32 {
33  EXPECT_FALSE(Utils::is_unique_ptr<int>::value);
34  EXPECT_TRUE(Utils::is_unique_ptr<std::unique_ptr<int>>::value);
35 }

◆ TEST_F() [4/5]

TEST_F ( ContainerUtilsTest  ,
Real   
)

Definition at line 65 of file containerutils.test.cpp.

66 {
67  std::vector<std::complex<double>> data = {{1.0, 10.0}, {2.0, 20.0}};
68  EXPECT_EQ(Utils::Real(data), (std::vector<double>{1.0, 2.0}));
69  EXPECT_EQ(Utils::Imag(data), (std::vector<double>{10.0, 20.0}));
70 }
std::vector< double > Real(const C &container)
Returns vector with real part of complex numbers.
std::vector< double > Imag(const C &container)
Returns vector with imag part of complex numbers.

References ModelView::Utils::Imag(), and ModelView::Utils::Real().

Here is the call graph for this function:

◆ TEST_F() [5/5]

TEST_F ( ContainerUtilsTest  ,
UniqueWithOrder   
)

Definition at line 72 of file containerutils.test.cpp.

73 {
74  std::vector<int> data = {1, 42, 1, 6, 43, 6};
75  EXPECT_EQ(Utils::UniqueWithOrder(data), (std::vector<int>{1, 42, 6, 43}));
76 }
C UniqueWithOrder(const C &container)
Returns copy of container with all duplicated elements filtered our. The order is preserved.

References ModelView::Utils::UniqueWithOrder().

Here is the call graph for this function: