CASM  1.1.0
A Clusters Approach to Statistical Mechanics
complete_tests.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <iterator>
4 #include "completer_functions.hh"
7 
8 namespace CASM {
9  using namespace Completer;
11 
12  std::string recast(ARG_TYPE atype) {
13  switch(atype) {
14  case ARG_TYPE::VOID:
15  return "VOID";
16  case ARG_TYPE::PATH:
17  return "PATH";
18  case ARG_TYPE::COMMAND:
19  return "COMMAND";
20  case ARG_TYPE::SCELNAME:
21  return "SCELNAME";
22  case ARG_TYPE::QUERY:
23  return "QUERY";
24  case ARG_TYPE::OPERATOR:
25  return "OPERATOR";
26  default:
27  return "FUCKUP";
28  }
29  }
30 
31  /*
32  template <typename T>
33  std::ostream &operator<< (std::ostream &out, const std::vector<T> &v) {
34  if(!v.empty()) {
35  out << '[';
36  std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
37  out << "\b\b]";
38  }
39  return out;
40  }
41  */
42 
43  void subopt_test() {
44  Suboption sub0("--void", "-v", ARG_TYPE::VOID);
45 
46  std::cout << sub0.long_tag() << std::endl;
47  std::cout << sub0.short_tag() << std::endl;
48  std::cout << sub0.matches("--void") << sub0.matches("-v") << sub0.matches("void") << std::endl;
49  std::cout << recast(sub0.argument_type()) << std::endl;
50  }
51 
52  void opt_test() {
53  Suboption sub0("--void", "-v", ARG_TYPE::VOID);
54  Suboption sub1("--path", "-p", ARG_TYPE::PATH);
55  Suboption sub2("--command", "-c", ARG_TYPE::COMMAND);
56  Suboption sub3("--scel", "-s", ARG_TYPE::SCELNAME);
57  Suboption sub4("--query", "-q", ARG_TYPE::QUERY);
58  Suboption sub5("--operator", "-o", ARG_TYPE::OPERATOR);
59 
60  std::vector<Suboption> subopts;
61  subopts.push_back(sub0);
62  subopts.push_back(sub1);
63  subopts.push_back(sub2);
64  subopts.push_back(sub3);
65  subopts.push_back(sub4);
66  subopts.push_back(sub5);
67 
68  Option opt("fake", subopts);
69 
70  std::cout << opt.tag() << std::endl;
71  std::cout << opt.probe_suboptions() << std::endl;
72  std::cout << recast(opt.probe_argument_type("--query")) << std::endl;
73  std::cout << recast(opt.probe_argument_type("-o")) << std::endl;
74  std::cout << opt.matches("fake") << opt.matches("real") << std::endl;
75 
76  return;
77  }
78 
79  void opt_test2() {
80  int min_vol, max_vol;
81  std::vector<std::string> scellname_list, filter_expr;
82 
83  po::options_description desc("'casm enum' usage");
84  desc.add_options()
85  ("help,h", "Write help documentation")
86  ("min", po::value<int>(&min_vol), "Min volume")
87  ("max", po::value<int>(&max_vol), "Max volume")
88  ("filter,f", po::value<std::vector<std::string> >(&filter_expr)->multitoken(), "Filter configuration enumeration so that")
89  ("scellname,n", po::value<std::vector<std::string> >(&scellname_list)->multitoken(), "Enumerate configs for given supercells")
90  ("all,a", "Enumerate configurations for all supercells")
91  ("supercells,s", "Enumerate supercells")
92  ("configs,c", "Enumerate configurations");
93 
94  Option opt("testopt", desc);
95 
96 
97  std::cout << opt.tag() << std::endl;
98  std::cout << opt.probe_suboptions() << std::endl;
99  std::cout << recast(opt.probe_argument_type("--help")) << std::endl;
100  std::cout << recast(opt.probe_argument_type("-f")) << std::endl;
101  std::cout << opt.matches("testopt") << opt.matches("real") << std::endl;
102 
103  return;
104  }
105 
106  void po_test() {
107  int min_vol, max_vol;
108  std::vector<std::string> scellname_list, filter_expr;
109 
110  po::options_description desc("'casm enum' usage");
111  desc.add_options()
112  ("help,h", "Write help documentation")
113  ("min", po::value<int>(&min_vol), "Min volume")
114  ("max", po::value<int>(&max_vol), "Max volume")
115  ("filter,f", po::value<std::vector<std::string> >(&filter_expr)->multitoken(), "Filter configuration enumeration so that")
116  ("scellname,n", po::value<std::vector<std::string> >(&scellname_list)->multitoken(), "Enumerate configs for given supercells")
117  ("all,a", "Enumerate configurations for all supercells")
118  ("supercells,s", "Enumerate supercells")
119  ("configs,c", "Enumerate configurations");
120 
121  po::option_description testop("filter,x", po::value<int>(&min_vol)->default_value(5)->value_name("lol"), "Filter configuration enumeration so that");
122 
123  std::cout << "FORMAT:" << std::endl;
124  std::cout << testop.format_parameter() << std::endl;
125 
126  std::cout << testop.canonical_display_name(po::command_line_style::allow_dash_for_short) << std::endl;
127  std::cout << testop.canonical_display_name(po::command_line_style::allow_long) << std::endl;
128 
129  for(auto it = desc.options().begin(); it != desc.options().end(); ++it) {
130  std::cout << (*it)->canonical_display_name(po::command_line_style::allow_dash_for_short) << " ";
131  std::cout << (*it)->canonical_display_name(po::command_line_style::allow_long) << std::endl;
132  }
133 
134  return;
135  }
136 
137  Option generate_option(std::string postfix, char beginshort) {
138  int phony;
139 
140  po::options_description desc("phony target " + postfix);
141 
142  desc.add_options()
143  ((("aaaa" + postfix + ",") + std::string(1, char(beginshort + 1))).c_str(),
144  po::value<int>(&phony)->value_name(ArgHandler::supercell()),
145  ("aaaa" + postfix + " info").c_str())
146 
147  ((("bbbb" + postfix + ",") + std::string(1, char(beginshort + 2))).c_str(),
148  po::value<int>(&phony)->default_value(9)->value_name(ArgHandler::query()),
149  ("bbbb" + postfix + " info").c_str())
150 
151  ((("cccc" + postfix + ",") + std::string(1, char(beginshort + 3))).c_str(),
152  po::value<int>(&phony)->value_name(ArgHandler::operation()),
153  ("cccc" + postfix + " info").c_str())
154 
155  ((("dddd" + postfix + ",") + std::string(1, char(beginshort + 4))).c_str(),
156  po::value<int>(&phony),
157  ("dddd" + postfix + " info").c_str())
158 
159  ((("eeee" + postfix + ",") + std::string(1, char(beginshort + 5))).c_str(),
160  po::value<int>(&phony),
161  ("eeee" + postfix + " info").c_str());
162 
163  return Option("fake" + postfix, desc);
164  }
165 
166  void engine_test() {
167  Option gen0 = generate_option("zz", 'a');
168  Option gen1 = generate_option("yy", 'h');
169 
170  Engine testengine;
171  testengine.push_back(gen0);
172  testengine.push_back(gen1);
173  testengine.push_back(generate_option("xx", 'l'));
174 
175  std::cout << testengine.probe_options() << std::endl;
176  std::cout << testengine.probe_suboptions("fakezz") << std::endl;
177  std::cout << testengine.probe_suboptions("fakeyy") << std::endl;
178  std::cout << testengine.probe_suboptions("fakexx") << std::endl;
179  std::cout << testengine.probe_suboptions("yy") << std::endl;
180  //std::cout << recast(testengine.probe_argument_type("fakexx", "--aaaaxx")) << std::endl;
181  //std::cout << recast(testengine.probe_argument_type("fakexx", "-n")) << std::endl;
182  //std::cout << recast(testengine.probe_argument_type("fakexx", "--ccccxx")) << std::endl;
183  //std::cout << recast(testengine.probe_argument_type("fakexx", "--ddddxx")) << std::endl;
184  return;
185  }
186 
187  void argtype_test() {
188  int min_vol;
189  std::string test = "asdf";
190  po::option_description testop
191  ("filter,x",
192  po::value<int>(&min_vol)->default_value(5)->value_name(ArgHandler::path()),
193  "Filter configuration enumeration so that");
194 
195  ARG_TYPE determined_type = ArgHandler::determine_type(testop);
196  std::cout << "DETERMINED: " << recast(determined_type) << std::endl;
197  return;
198  }
199 
200  void property_test() {
201  //I think this is s a DataFormatterDictionary<Configuration>
202  DataFormatterDictionary<Configuration> dict = make_dictionary<Configuration>();
203 
204  for(auto it = dict.begin(); it != dict.cend(); ++it) {
205  if(it->type() == DatumFormatterClass::Property)
206  std::cout << it->name() << " ";
207  }
208 
209  std::cout << std::endl;
210 
211  return;
212  }
213 
214 }
215 using namespace CASM;
216 
217 int main(int argc, char *argv[]) {
218 
219  //subopt_test();
220 
221  //std::cout << std::endl;
222 
223  //opt_test();
224 
225  //std::cout << std::endl;
226 
227  //po_test();
228 
229  //std::cout << std::endl;
230 
231  //opt_test2();
232 
233  //std::cout << std::endl;
234 
235  //argtype_test();
236 
237  //std::cout << std::endl;
238 
239  //engine_test();
240 
241  //std::cout <<std::endl;
242 
243  property_test();
244 
245 
246  return 0;
247 }
static std::string path()
Get value_type string for path completion.
Definition: Handlers.cc:56
static ARG_TYPE determine_type(const po::option_description &boost_option)
Definition: Handlers.cc:28
static std::string operation()
Get value_type string for operation completion.
Definition: Handlers.cc:64
static std::string query()
Get value_type string for query completion.
Definition: Handlers.cc:62
static std::string supercell()
Get value_type string for supercell completion.
Definition: Handlers.cc:60
std::vector< std::string > probe_options() const
Get a list of all available options.
Definition: Complete.cc:162
std::vector< std::string > probe_suboptions(const std::string &option_tag) const
For a particular option, get the available suboptions.
Definition: Complete.cc:178
void push_back(const Option &new_option)
Append a new option to the engine.
Definition: Complete.cc:310
ARG_TYPE probe_argument_type(const std::string &suboption_tag) const
Definition: Complete.cc:137
std::string tag() const
Return the identifying name of *this (e.g. "super", "monte", etc)
Definition: Complete.cc:113
bool matches(const std::string &test_tag) const
Check if the given string corresponds to the tag of *this.
Definition: Complete.cc:148
std::vector< std::string > probe_suboptions() const
Return what the suboptions (–long format) for *this are.
Definition: Complete.cc:120
std::string short_tag() const
Return short name as char.
Definition: Complete.cc:78
ARG_TYPE argument_type() const
Return the expected types of arguments that follow *this.
Definition: Complete.cc:94
bool matches(const std::string &test_tag) const
Definition: Complete.cc:80
std::string long_tag() const
Return long name in string format.
Definition: Complete.cc:76
Parsing dictionary for constructing a DataFormatter<DataObject> object.
const_iterator cend() const
Definition: unique_map.hh:223
iterator begin()
Definition: unique_map.hh:213
int main(int argc, char *argv[])
ArgHandler::ARG_TYPE ARG_TYPE
Definition: Complete.cc:11
Main CASM namespace.
Definition: APICommand.hh:8
void po_test()
void property_test()
Option generate_option(std::string postfix, char beginshort)
void opt_test()
void subopt_test()
void engine_test()
void argtype_test()
void opt_test2()
std::string recast(ARG_TYPE atype)
ClexDescription & desc
Definition: settings.cc:138