QMCPACK
test_project_data.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2017 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 
16 #include "OhmmsData/Libxml2Doc.h"
17 #include "ProjectData.h"
18 
19 
20 #include <stdio.h>
21 #include <string>
22 #include <sstream>
23 
24 
25 using std::string;
26 
27 namespace qmcplusplus
28 {
29 TEST_CASE("ProjectData", "[ohmmsapp]")
30 {
31  Communicate* c;
33 
34 
35  ProjectData proj1;
36  // If no name given, it gets set to time and date
37  // and the title is set equal to the name
38  REQUIRE(proj1.getTitle().size() > 0);
39 
40  ProjectData proj2("asample");
41  REQUIRE(proj2.getSeriesIndex() == 0);
42  proj2.advance();
43  REQUIRE(proj2.getSeriesIndex() == 1);
44  REQUIRE(proj2.getTitle() == std::string("asample"));
45 
46  proj2.setCommunicator(c);
47  std::stringstream o2;
48  proj2.get(o2);
49 }
50 
51 TEST_CASE("ProjectData::put no series", "[ohmmsapp]")
52 {
53  ProjectData proj;
54 
55  const char* xml_input = R"(<project id="test1"></project>)";
57  bool okay = doc.parseFromString(xml_input);
58  REQUIRE(okay);
59 
60  xmlNodePtr root = doc.getRoot();
61 
62  proj.put(root);
63  REQUIRE(proj.getSeriesIndex() == 0);
64  REQUIRE(proj.getTitle() == std::string("test1"));
65 }
66 
67 TEST_CASE("ProjectData::put with series", "[ohmmsapp]")
68 {
69  ProjectData proj;
70 
71  const char* xml_input = R"(<project id="test1" series="1"></project>)";
73  bool okay = doc.parseFromString(xml_input);
74  REQUIRE(okay);
75 
76  xmlNodePtr root = doc.getRoot();
77 
78  proj.put(root);
79  REQUIRE(proj.getSeriesIndex() == 1);
80  REQUIRE(proj.getTitle() == std::string("test1"));
81 
82  // host and date nodes get added for output to the .cont.xml file
83 }
84 
85 TEST_CASE("ProjectData::TestDriverVersion", "[ohmmsapp]")
86 {
87  using DV = ProjectData::DriverVersion;
88  SECTION("driver version batch")
89  {
90  ProjectData proj;
91 
92  const char* xml_input = R"(
93  <project id="test1" series="1">
94  <parameter name='driver_version'>
95  batch
96  </parameter>
97  </project>
98  )";
100  bool okay = doc.parseFromString(xml_input);
101  REQUIRE(okay);
102 
103  xmlNodePtr root = doc.getRoot();
104 
105  proj.put(root);
106  REQUIRE(proj.getSeriesIndex() == 1);
107  REQUIRE(proj.getDriverVersion() == DV::BATCH);
108  }
109  SECTION("driver version legacy")
110  {
111  ProjectData proj;
112  REQUIRE(proj.getDriverVersion() == DV::LEGACY);
113 
114  const char* xml_input = R"(
115  <project id="test1" series="1">
116  <parameter name='driver_version'>
117  legacy
118  </parameter>
119  </project>
120  )";
122  bool okay = doc.parseFromString(xml_input);
123  REQUIRE(okay);
124 
125  xmlNodePtr root = doc.getRoot();
126 
127  proj.put(root);
128  REQUIRE(proj.getSeriesIndex() == 1);
129  REQUIRE(proj.getDriverVersion() == DV::LEGACY);
130  }
131  SECTION("driver version bad value")
132  {
133  ProjectData proj;
134 
135  const char* xml_input = R"(
136  <project id=" test1 " series=" 1 ">
137  <parameter name = 'driver_version' >
138  linear
139  </parameter>
140  </project>)";
142  bool okay = doc.parseFromString(xml_input);
143  REQUIRE(okay);
144 
145  xmlNodePtr root = doc.getRoot();
146 
147  REQUIRE_THROWS(proj.put(root));
148  }
149 
150  // host and date nodes get added for output to the .cont.xml file
151 }
152 
153 TEST_CASE("ProjectData::TestIsComplex", "[ohmmsapp]")
154 {
155  ProjectData proj;
156 #ifdef QMC_COMPLEX
157  REQUIRE(proj.isComplex());
158 #else
159  REQUIRE(!proj.isComplex());
160 #endif
161 }
162 
163 } // namespace qmcplusplus
const std::string & getTitle() const noexcept
returns the title of the project <project id="det_qmc_short_sdbatch_vmcbatch_mwalkers" series="0"> tr...
class that handles xmlDoc
Definition: Libxml2Doc.h:76
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
class ProjectData
Definition: ProjectData.h:36
TEST_CASE("complex_helper", "[type_traits]")
bool isComplex() const noexcept
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
Wrapping information on parallelism.
Definition: Communicate.h:68
DriverVersion getDriverVersion() const noexcept
bool put(std::istream &is)
Definition: ProjectData.cpp:60
DriverVersion
Enum for global scope switch of design from legacy driver based to batch driver based.
Definition: ProjectData.h:43
REQUIRE(std::filesystem::exists(filename))
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
int getSeriesIndex() const noexcept