CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Clusterography_test.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
3 
6 
10 #include "casm/clex/PrimClex.hh"
11 #include "casm/app/AppIO.hh"
13 #include "Common.hh"
14 
15 using namespace CASM;
16 using namespace test;
17 
19  jsonParser nclust = jsonParser::array();
20  // check Nclusters for each orbit
21  for(int branch = 0; branch < tree.size(); ++branch) {
22  nclust.push_back(jsonParser::array());
23  for(int orbit = 0; orbit < tree[branch].size(); ++orbit) {
24  nclust[branch].push_back(tree[branch][orbit].size());
25  }
26  }
27  return nclust;
28 }
29 
30 BOOST_AUTO_TEST_SUITE(BasicStructureSiteTest)
31 
32 BOOST_AUTO_TEST_CASE(ClusterographyTest) {
33 
34  // read test file
35  fs::path test_cases_path("tests/unit/clusterography/test_cases.json");
36  jsonParser tests(test_cases_path);
37  double tol = TOL;
38 
39  for(auto test_it = tests.begin(); test_it != tests.end(); ++test_it) {
40 
41  // input and expected output data
42  jsonParser &j = *test_it;
43 
44  // if false: print calculated results if no test data; if true: suppress
45  bool quiet = false;
46  j.get_else(quiet, "quiet", false);
47 
48  BOOST_CHECK_MESSAGE(j.contains("title"), "test case 'title' is required");
49  BOOST_CHECK_MESSAGE(j.contains("prim"), "test case 'prim' is required");
50  BOOST_CHECK_MESSAGE(j.contains("bspecs"), "test case 'bspecs' is required");
51 
52  // generate prim
53  Structure prim(read_prim(j["prim"]));
54 
55  // generate cluster orbits
56  SiteOrbitree tree(prim.lattice(), tol);
57  tree = make_orbitree(prim, j["bspecs"], tol);
58 
59  jsonParser clust_json;
60  to_json(jsonHelper(tree, prim), clust_json);
61 
62  // run checks:
63  check("Nclusters", j, expected_Nclusters(tree), test_cases_path, quiet);
64  // ... add more here ...
65 
66  }
67 
68 }
69 
70 BOOST_AUTO_TEST_SUITE_END()
ClustJsonHelper< ValueType > jsonHelper(ValueType &_value, const Structure &_struc, double tol=TOL)
Definition: jsonClust.hh:62
iterator end()
Returns iterator to end of JSON object or JSON array.
Definition: jsonParser.cc:465
BOOST_AUTO_TEST_CASE(ClusterographyTest)
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:29
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
Definition: Common.hh:7
Main CASM namespace.
Definition: complete.cpp:8
const double TOL
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
Definition: jsonParser.cc:440
BasicStructure< Site > read_prim(fs::path filename)
Definition: AppIO.cc:11
double tol
bool get_else(T &t, const std::string &key, const T &default_value, Args...args) const
Definition: jsonParser.hh:749
bool check(std::string test, const jsonParser &expected, const jsonParser &calculated, fs::path test_cases_path, bool quiet, double tol=0.0)
Check expected JSON vs calculated JSON using BOOST_CHECK_EQUAL.
jsonParser expected_Nclusters(const SiteOrbitree &tree)
jsonParser & push_back(const T &value)
Puts new valued element at end of array of any type T for which 'jsonParser& to_json( const T &value...
Definition: jsonParser.hh:696
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:500
static jsonParser array()
Returns an empty json array.
Definition: jsonParser.hh:342
SiteOrbitree make_orbitree(Structure &prim, const jsonParser &json, double _tol)
Make orbitree. For now specifically global.
Definition: PrimClex.cc:1097
Index size(Index np) const
Number of orbits in OrbitBranch 'np'.