Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianna committed Dec 1, 2020
1 parent 8fe826b commit 1537192
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/interface/DDFilteredView.h
Expand Up @@ -166,7 +166,7 @@ namespace cms {
T get(const std::string&);

//! extract attribute value for current Node
// keep the maespace for comparison
// keep the namespace for comparison
// assume there are no regular expressions
template <typename T>
std::vector<T> getValuesNS(const std::string& key) {
Expand Down
Expand Up @@ -986,8 +986,10 @@ void Converter<Parameter>::operator()(xml_h element) const {
string specParName = specPar.attr<string>(_U(name));
string name = e.nameStr();
string value = e.attr<string>(DD_CMU(value));
bool eval = e.hasAttr(_U(eval)) ? e.attr<bool>(_U(eval))
: (specParSect.hasAttr(_U(eval)) ? specParSect.attr<bool>(_U(eval)) : false);
bool eval = specParSect.hasAttr(_U(eval)) ? specParSect.attr<bool>(_U(eval)) : false;
eval = specPar.hasAttr(_U(eval)) ? specPar.attr<bool>(_U(eval)) : eval;
eval = e.hasAttr(_U(eval)) ? e.attr<bool>(_U(eval)) : eval;

string type = eval ? "number" : "string";

#ifdef EDM_ML_DEBUG
Expand Down
8 changes: 3 additions & 5 deletions DetectorDescription/DDCMS/src/DDFilteredView.cc
Expand Up @@ -841,11 +841,9 @@ double DDFilteredView::getNextValue(const std::string& key) const {
double result(0.0);

if (currentSpecPar_ != nullptr) {
if (currentSpecPar_->hasValue(key)) {
auto const& nitem = currentSpecPar_->numpars.find(key);
if (nitem != end(currentSpecPar_->numpars)) {
result = nitem->second[0];
}
auto const& nitem = currentSpecPar_->numpars.find(key);
if (nitem != end(currentSpecPar_->numpars)) {
result = nitem->second[0];
}
}

Expand Down
28 changes: 14 additions & 14 deletions DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc
Expand Up @@ -48,19 +48,19 @@ void testDDFilteredView::setUp() {
"0.4002930E-03/cm", "0.4009888E-03/cm", "0.3954170E-03/cm", "0.3893599E-03/cm", "0.3839422E-03/cm"};
refdLongFL_ = {
227.993, 237.122, 241.701, 256.48, 266.754, 275.988, 276.982, 284.989, 286.307, 290.478, 290.5, 292, 295.5};
refsLongFL_ = {"227.9925651*cm",
"237.1215213*cm",
"241.7005445*cm",
"256.47981*cm",
"266.7540042*cm",
"275.987715*cm",
"276.9823529*cm",
"284.9889299*cm",
"286.3065327*cm",
"290.4779412*cm",
"290.5*cm",
"292.0*cm",
"295.5*cm"};
refsLongFL_ = {"227.9925651",
"237.1215213",
"241.7005445",
"256.47981",
"266.7540042",
"275.987715",
"276.9823529",
"284.9889299",
"286.3065327",
"290.4779412",
"290.5",
"292.0",
"295.5"};
}

void testDDFilteredView::checkFilteredView() {
Expand Down Expand Up @@ -114,7 +114,7 @@ void testDDFilteredView::checkFilteredView() {
std::vector<std::string> sLongFL = fview.get<std::vector<std::string>>("hf", "LongFL");
for (auto const& i : sLongFL) {
std::cout << "LongFL " << i << " == " << refsLongFL_[count] << "\n";
CPPUNIT_ASSERT(i.compare(refsLongFL_[count]) == 0);
CPPUNIT_ASSERT(abs(std::stod(i) - std::stod(refsLongFL_[count])) < 10e-6);
count++;
}

Expand Down
5 changes: 3 additions & 2 deletions DetectorDescription/DDCMS/test/DDFilteredView.find.cppunit.cc
Expand Up @@ -68,9 +68,10 @@ void testDDFilteredViewFind::checkFilteredView() {
fview.findSpecPar("TrackerRadLength", "TrackerXi");

double radLength = fview.getNextValue("TrackerRadLength");
std::cout << radLength << "\n";
double xi = fview.getNextValue("TrackerXi");
CPPUNIT_ASSERT(radLength == refRadLength_);
CPPUNIT_ASSERT(xi == refXi_);
CPPUNIT_ASSERT(abs(radLength - refRadLength_) < 10e-6);
CPPUNIT_ASSERT(abs(xi - refXi_) < 10e-6);

std::cout << "TrackerRadLength = " << radLength << "\nTrackerXi = " << xi << "\n";

Expand Down
4 changes: 2 additions & 2 deletions DetectorDescription/DDCMS/test/DDFilteredView.get.cppunit.cc
Expand Up @@ -69,8 +69,8 @@ void testDDFilteredViewGet::checkFilteredView() {

double radLength = fview.getNextValue("TrackerRadLength");
double xi = fview.getNextValue("TrackerXi");
CPPUNIT_ASSERT(radLength == refRadLength_);
CPPUNIT_ASSERT(xi == refXi_);
CPPUNIT_ASSERT(abs(radLength - refRadLength_) < 10e-6);
CPPUNIT_ASSERT(abs(xi - refXi_) < 10e-6);

std::cout << "TrackerRadLength = " << radLength << "\nTrackerXi = " << xi << "\n";
auto vals = fview.getValuesNS<std::string>("TrackerRadLength");
Expand Down
4 changes: 2 additions & 2 deletions DetectorDescription/DDCMS/test/DDFilteredView.goto.cppunit.cc
Expand Up @@ -65,8 +65,8 @@ void testDDFilteredViewGoTo::checkFilteredView() {

double radLength = fview.get<double>("TrackerRadLength");
double xi = fview.getNextValue("TrackerXi");
CPPUNIT_ASSERT(radLength == refRadLength_);
CPPUNIT_ASSERT(xi == refXi_);
CPPUNIT_ASSERT(abs(radLength - refRadLength_) < 10e-6);
CPPUNIT_ASSERT(abs(xi - refXi_) < 10e-6);

std::cout << "TrackerRadLength = " << radLength << "\nTrackerXi = " << xi << "\n";

Expand Down

0 comments on commit 1537192

Please sign in to comment.