CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Enumerator_test.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
3 
5 #include "casm/clex/ScelEnum.hh"
6 //#include "casm/clex/ScelEnum_impl.hh"
7 
9 
10 #include "Common.hh"
11 #include "FCCTernaryProj.hh"
12 
13 using namespace CASM;
14 
15 BOOST_AUTO_TEST_SUITE(EnumeratorTest)
16 
18 
19  test::ZrOProj proj;
20  proj.check_init();
21 
22  PrimClex primclex(proj.dir, null_log());
23 
24  Eigen::Vector3d a, b, c;
25  std::tie(a, b, c) = primclex.get_prim().lattice().vectors();
26 
27  std::vector<std::string> m_names;
28 
29  // -- test an input enumerator --------------------
30  {
31  ScelEnumProps enum_props(1, 5);
32  ScelEnumByProps e(primclex, enum_props);
33 
34  BOOST_CHECK_EQUAL(e.name(), "ScelEnumByProps");
35 
36  auto it = e.begin();
37  auto end = e.end();
38 
39  Index count = 0;
40  for(; it != end; ++it, ++count) {
41  m_names.push_back(it->get_name());
42  //std::cout << it->get_name() << std::endl;
43  }
44  BOOST_CHECK_EQUAL(count, 20);
45  BOOST_CHECK(it == end);
46  BOOST_CHECK(!e.valid());
47  }
48 
49  // -- test a random access enumerator --------------------
50  ScelEnumByNameT<false> e(primclex, m_names.begin(), m_names.end());
51  {
52  auto it = e.begin();
53  BOOST_CHECK_EQUAL(it.step(), 0);
54  ++it;
55  BOOST_CHECK_EQUAL(it.step(), 1);
56 
57  auto it_B = e.begin();
58  BOOST_CHECK_EQUAL(it_B.step(), 0);
59  ++it_B;
60  BOOST_CHECK_EQUAL(it_B.step(), 1);
61 
62  BOOST_CHECK_EQUAL(it.step(), 1);
63 
64  it += 5;
65  BOOST_CHECK_EQUAL(it.step(), 6);
66 
67  it -= 1;
68  BOOST_CHECK_EQUAL(it.step(), 5);
69  }
70 
71  {
72  BOOST_CHECK(e.end() == e.end());
73  }
74 
75  {
76  auto it = e.begin();
77  it += 20;
78  BOOST_CHECK(it == e.end());
79  }
80 
81  {
82  auto it = e.begin();
83  auto it_B = e.begin();
84  BOOST_CHECK(it == it_B);
85 
86  ++it;
87  BOOST_CHECK(it != it_B);
88 
89  ++it_B;
90  BOOST_CHECK(it == it_B);
91 
92  BOOST_CHECK_EQUAL(std::distance(it, it_B), 0);
93 
94  it_B += 2;
95  BOOST_CHECK_EQUAL(std::distance(it, it_B), 2);
96  BOOST_CHECK_EQUAL(std::distance(it_B, it), -2);
97  }
98 
99  {
100  BOOST_CHECK_EQUAL(std::distance(e.begin(), e.begin()), 0);
101  BOOST_CHECK_EQUAL(std::distance(e.end(), e.end()), 0);
102  BOOST_CHECK_EQUAL(std::distance(e.begin(), e.end()), e.size());
103  BOOST_CHECK_EQUAL(std::distance(e.begin(), e.end()), e.size());
104  }
105 
106  {
107  BOOST_CHECK_EQUAL(std::distance(e.rbegin(), e.rbegin()), 0);
108  BOOST_CHECK_EQUAL(std::distance(e.rend(), e.rend()), 0);
109  BOOST_CHECK_EQUAL(std::distance(e.rbegin(), e.rend()), e.size());
110  BOOST_CHECK_EQUAL(std::distance(e.rbegin(), e.rend()), e.size());
111  }
112 
113 }
114 
115 BOOST_AUTO_TEST_SUITE_END()
fs::path dir
Definition: Proj.hh:34
Data structure for holding supercell enumeration properties.
PrimClex * primclex
Definition: settings.cc:101
Main CASM namespace.
Definition: complete.cpp:8
const Lattice & lattice() const
Log & null_log()
Definition: Log.hh:211
EigenIndex Index
For long integer indexing:
BOOST_AUTO_TEST_CASE(Test1)
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
Enumerate over Supercell.
Definition: ScelEnum.hh:36
std::tuple< LatVec, LatVec, LatVec > vectors()
Definition: Lattice.hh:65
virtual void check_init()
Check project initialization.
const Structure & get_prim() const
const Access to primitive Structure
Definition: PrimClex.cc:260