Commit dad1d8d1 authored by snuverink_j's avatar snuverink_j
Browse files

Merge branch '524-distribution-unit-tests-failing' into 'master'

Resolve "Distribution Unit Tests failing"

Closes #524

See merge request !344
parents fed401f6 ca6f864e
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
#include <boost/regex.hpp> #include <boost/regex.hpp>
using std::string;
using namespace Expressions; using namespace Expressions;
...@@ -75,7 +74,7 @@ namespace Attributes { ...@@ -75,7 +74,7 @@ namespace Attributes {
const SRefAttr<bool> &value = ref->evaluate(); const SRefAttr<bool> &value = ref->evaluate();
return value.evaluate(); return value.evaluate();
} else { } else {
throw OpalException("Attributes::get()", "Attribute \"" + throw OpalException("Attributes::getBool()", "Attribute \"" +
attr.getName() + "\" is not logical."); attr.getName() + "\" is not logical.");
} }
} else { } else {
...@@ -85,10 +84,11 @@ namespace Attributes { ...@@ -85,10 +84,11 @@ namespace Attributes {
void setBool(Attribute &attr, bool val) { void setBool(Attribute &attr, bool val) {
SValue<SRefAttr<bool> > *ref;
if(dynamic_cast<const Bool *>(&attr.getHandler())) { if(dynamic_cast<const Bool *>(&attr.getHandler())) {
attr.set(new SValue<bool>(val)); attr.set(new SValue<bool>(val));
} else if(SValue<SRefAttr<bool> > *ref = } else if((attr.isBaseAllocated() == true) &&
dynamic_cast<SValue<SRefAttr<bool> >*>(&attr.getBase())) { (ref = dynamic_cast<SValue<SRefAttr<bool> >*>(&attr.getBase()))) {
const SRefAttr<bool> &value = ref->evaluate(); const SRefAttr<bool> &value = ref->evaluate();
value.set(val); value.set(val);
} else { } else {
...@@ -161,7 +161,7 @@ namespace Attributes { ...@@ -161,7 +161,7 @@ namespace Attributes {
if(dynamic_cast<const Place *>(&attr.getHandler())) { if(dynamic_cast<const Place *>(&attr.getHandler())) {
attr.set(new SValue<PlaceRep>(rep)); attr.set(new SValue<PlaceRep>(rep));
} else { } else {
throw OpalException("Attributes::getPlace()", "Attribute \"" + throw OpalException("Attributes::setPlace()", "Attribute \"" +
attr.getName() + "\" is not a place reference."); attr.getName() + "\" is not a place reference.");
} }
} }
...@@ -182,7 +182,7 @@ namespace Attributes { ...@@ -182,7 +182,7 @@ namespace Attributes {
dynamic_cast<SValue<RangeRep> *>(&attr.getBase())) { dynamic_cast<SValue<RangeRep> *>(&attr.getBase())) {
return range->evaluate(); return range->evaluate();
} else { } else {
throw OpalException("Attributes::get()", "Attribute \"" + throw OpalException("Attributes::getRange()", "Attribute \"" +
attr.getName() + "\" is not a range reference."); attr.getName() + "\" is not a range reference.");
} }
} else { } else {
...@@ -195,7 +195,7 @@ namespace Attributes { ...@@ -195,7 +195,7 @@ namespace Attributes {
if(dynamic_cast<const Range *>(&attr.getHandler())) { if(dynamic_cast<const Range *>(&attr.getHandler())) {
attr.set(new SValue<RangeRep>(rep)); attr.set(new SValue<RangeRep>(rep));
} else { } else {
throw OpalException("Attributes::get()", "Attribute \"" + throw OpalException("Attributes::setRange()", "Attribute \"" +
attr.getName() + "\" is not a range reference."); attr.getName() + "\" is not a range reference.");
} }
} }
...@@ -236,10 +236,11 @@ namespace Attributes { ...@@ -236,10 +236,11 @@ namespace Attributes {
void setReal(Attribute &attr, double val) { void setReal(Attribute &attr, double val) {
SValue<SRefAttr<double> > *ref;
if(dynamic_cast<const Real *>(&attr.getHandler())) { if(dynamic_cast<const Real *>(&attr.getHandler())) {
attr.set(new SValue<double>(val)); attr.set(new SValue<double>(val));
} else if(SValue<SRefAttr<double> > *ref = } else if((attr.isBaseAllocated() == true) &&
dynamic_cast<SValue<SRefAttr<double> >*>(&attr.getBase())) { (ref = dynamic_cast<SValue<SRefAttr<double> >*>(&attr.getBase()))) {
const SRefAttr<double> &value = ref->evaluate(); const SRefAttr<double> &value = ref->evaluate();
value.set(val); value.set(val);
} else { } else {
...@@ -357,10 +358,11 @@ namespace Attributes { ...@@ -357,10 +358,11 @@ namespace Attributes {
void setString(Attribute &attr, const std::string &val) { void setString(Attribute &attr, const std::string &val) {
SValue<SRefAttr<std::string> > *ref;
if(dynamic_cast<const String *>(&attr.getHandler())) { if(dynamic_cast<const String *>(&attr.getHandler())) {
attr.set(new SValue<std::string>(val)); attr.set(new SValue<std::string>(val));
} else if(SValue<SRefAttr<std::string> > *ref = } else if((attr.isBaseAllocated() == true) &&
dynamic_cast<SValue<SRefAttr<std::string> >*>(&attr.getBase())) { (ref = dynamic_cast<SValue<SRefAttr<std::string> >*>(&attr.getBase()))) {
const SRefAttr<std::string> &value = ref->evaluate(); const SRefAttr<std::string> &value = ref->evaluate();
value.set(val); value.set(val);
} else { } else {
...@@ -385,10 +387,11 @@ namespace Attributes { ...@@ -385,10 +387,11 @@ namespace Attributes {
void setUpperCaseString(Attribute &attr, const std::string &val) { void setUpperCaseString(Attribute &attr, const std::string &val) {
SValue<SRefAttr<std::string> > *ref;
if(dynamic_cast<const UpperCaseString *>(&attr.getHandler())) { if(dynamic_cast<const UpperCaseString *>(&attr.getHandler())) {
attr.set(new SValue<std::string>(Util::toUpper(val))); attr.set(new SValue<std::string>(Util::toUpper(val)));
} else if(SValue<SRefAttr<std::string> > *ref = } else if((attr.isBaseAllocated() == true) &&
dynamic_cast<SValue<SRefAttr<std::string> >*>(&attr.getBase())) { (ref = dynamic_cast<SValue<SRefAttr<std::string> >*>(&attr.getBase()))) {
const SRefAttr<std::string> &value = ref->evaluate(); const SRefAttr<std::string> &value = ref->evaluate();
value.set(Util::toUpper(val)); value.set(Util::toUpper(val));
} else { } else {
...@@ -495,7 +498,7 @@ namespace Attributes { ...@@ -495,7 +498,7 @@ namespace Attributes {
dynamic_cast<SValue<TableRowRep> *>(&attr.getBase())) { dynamic_cast<SValue<TableRowRep> *>(&attr.getBase())) {
return row->evaluate(); return row->evaluate();
} else { } else {
throw OpalException("Attributes::get()", "Attribute \"" + throw OpalException("Attributes::getTableRow()", "Attribute \"" +
attr.getName() + attr.getName() +
"\" is not a table row reference."); "\" is not a table row reference.");
} }
...@@ -509,7 +512,7 @@ namespace Attributes { ...@@ -509,7 +512,7 @@ namespace Attributes {
if(dynamic_cast<const TableRow *>(&attr.getHandler())) { if(dynamic_cast<const TableRow *>(&attr.getHandler())) {
attr.set(new SValue<TableRowRep>(rep)); attr.set(new SValue<TableRowRep>(rep));
} else { } else {
throw OpalException("Attributes::get()", "Attribute \"" + throw OpalException("Attributes::setTableRow()", "Attribute \"" +
attr.getName() + attr.getName() +
"\" is not a table row reference."); "\" is not a table row reference.");
} }
...@@ -543,7 +546,7 @@ namespace Attributes { ...@@ -543,7 +546,7 @@ namespace Attributes {
if(dynamic_cast<const TokenList *>(&attr.getHandler())) { if(dynamic_cast<const TokenList *>(&attr.getHandler())) {
attr.set(new SValue<std::list<Token> >(val)); attr.set(new SValue<std::list<Token> >(val));
} else { } else {
throw OpalException("Attributes::set()", "Attribute \"" + attr.getName() + throw OpalException("Attributes::setTokenList()", "Attribute \"" + attr.getName() +
"\" is not a token list."); "\" is not a token list.");
} }
} }
......
...@@ -34,7 +34,7 @@ TEST(BinomialTest, FullSigmaTest1) { ...@@ -34,7 +34,7 @@ TEST(BinomialTest, FullSigmaTest1) {
Distribution dist; Distribution dist;
Attributes::setString(dist.itsAttr[Attrib::Distribution::TYPE], "BINOMIAL"); Attributes::setUpperCaseString(dist.itsAttr[Attrib::Distribution::TYPE], "BINOMIAL");
Attributes::setReal(dist.itsAttr[Attrib::Distribution::MX], 999999999.9); Attributes::setReal(dist.itsAttr[Attrib::Distribution::MX], 999999999.9);
Attributes::setReal(dist.itsAttr[Attrib::Distribution::MY], 999999999.9); Attributes::setReal(dist.itsAttr[Attrib::Distribution::MY], 999999999.9);
Attributes::setReal(dist.itsAttr[Attrib::Distribution::MZ], 999999999.9); Attributes::setReal(dist.itsAttr[Attrib::Distribution::MZ], 999999999.9);
...@@ -114,7 +114,7 @@ TEST(BinomialTest, FullSigmaTest2) { ...@@ -114,7 +114,7 @@ TEST(BinomialTest, FullSigmaTest2) {
Distribution dist; Distribution dist;
Attributes::setString(dist.itsAttr[Attrib::Distribution::TYPE], "BINOMIAL"); Attributes::setUpperCaseString(dist.itsAttr[Attrib::Distribution::TYPE], "BINOMIAL");
Attributes::setReal(dist.itsAttr[Attrib::Distribution::MX], 1.0); Attributes::setReal(dist.itsAttr[Attrib::Distribution::MX], 1.0);
Attributes::setReal(dist.itsAttr[Attrib::Distribution::MY], 1.0); Attributes::setReal(dist.itsAttr[Attrib::Distribution::MY], 1.0);
Attributes::setReal(dist.itsAttr[Attrib::Distribution::MZ], 1.0); Attributes::setReal(dist.itsAttr[Attrib::Distribution::MZ], 1.0);
......
...@@ -15,7 +15,7 @@ TEST(GaussTest, FullSigmaTest1) { ...@@ -15,7 +15,7 @@ TEST(GaussTest, FullSigmaTest1) {
const double expectedR22 = 0.7998; const double expectedR22 = 0.7998;
const double expectedR33 = 2.498; const double expectedR33 = 2.498;
const double expectedR44 = 0.6212; const double expectedR44 = 0.6212;
const double expectedR55 = 1.537; const double expectedR55 = 1.537;
const double expectedR66 = 0.9457; const double expectedR66 = 0.9457;
const double expectedR21 = -0.40993; const double expectedR21 = -0.40993;
...@@ -34,7 +34,7 @@ TEST(GaussTest, FullSigmaTest1) { ...@@ -34,7 +34,7 @@ TEST(GaussTest, FullSigmaTest1) {
Distribution dist; Distribution dist;
Attributes::setString(dist.itsAttr[Attrib::Distribution::TYPE], "GAUSS"); Attributes::setUpperCaseString(dist.itsAttr[Attrib::Distribution::TYPE], "GAUSS");
Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAX], expectedR11 * 1e-3); Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAX], expectedR11 * 1e-3);
Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAPX], expectedR22); Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAPX], expectedR22);
Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAY], expectedR33 * 1e-3); Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAY], expectedR33 * 1e-3);
...@@ -112,7 +112,7 @@ TEST(GaussTest, FullSigmaTest2) { ...@@ -112,7 +112,7 @@ TEST(GaussTest, FullSigmaTest2) {
Distribution dist; Distribution dist;
Attributes::setString(dist.itsAttr[Attrib::Distribution::TYPE], "GAUSS"); Attributes::setUpperCaseString(dist.itsAttr[Attrib::Distribution::TYPE], "GAUSS");
Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAX], expectedR11 * 1e-3); Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAX], expectedR11 * 1e-3);
Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAPX], expectedR22); Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAPX], expectedR22);
Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAY], expectedR33 * 1e-3); Attributes::setReal(dist.itsAttr[Attrib::Distribution::SIGMAY], expectedR33 * 1e-3);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment