Commit 9a050dfa authored by kraus's avatar kraus
Browse files

fix the unit test 'SolveFactoryTest' which failed due to the added out of...

fix the unit test 'SolveFactoryTest' which failed due to the added out of bounds check; additionally fixed the test 'VariableRFCavityFringeFieldTest.TestConstructor'
parent 87d5c8ac
......@@ -150,6 +150,19 @@ SquarePolynomialVector* SolveFactory::PolynomialSolve(
"Values and derivatives over or under constrained"
);
}
for (int i = 1; i < nCoeffs && i < n_poly_coeffs_; ++i) {
if (values[i].size() < values[0].size()) {
throw GeneralClassicException("SolveFactory::PolynomialSolve",
"The vector of values is too short");
}
}
for (int i = 0; i < nDerivs; ++ i) {
if (deriv_values[i].size() < values[0].size()) {
throw GeneralClassicException("SolveFactory::PolynomialSolve",
"The vector of derivative values is too short");
}
}
int valueDim = 0;
if (values.size() != 0) {
valueDim = values[0].size();
......
......@@ -36,7 +36,7 @@
#include "AbsBeamline/EndFieldModel/Tanh.h"
#include "AbsBeamline/VariableRFCavityFringeField.h"
class VariableRFCavityFringeFieldTest : public ::testing::Test {
class VariableRFCavityFringeFieldTest : public ::testing::Test {
public:
VariableRFCavityFringeFieldTest() {
cav1 = VariableRFCavityFringeField("bob");
......@@ -77,8 +77,8 @@ TEST_F(VariableRFCavityFringeFieldTest, TestConstructor) {
std::cerr << "Test Ctor" << std::endl;
VariableRFCavityFringeField cav("bob");
EXPECT_FLOAT_EQ(cav.getCavityCentre(), 0.);
endfieldmodel::EndFieldModel* null = NULL;
EXPECT_EQ(&(*(cav.getEndField())), null);
EXPECT_FALSE(cav.getEndField());
std::cerr << "Test Ctor 2" << std::endl;
}
......@@ -151,10 +151,10 @@ void testFieldLookup(VariableRFCavityFringeField& cav, Vector_t R, double t, Vec
cav.apply(R, centroid, t, Etest, Btest);
for (size_t i = 0; i < 3; ++i) {
EXPECT_FLOAT_EQ(E[i], Etest[i]) << "\nR:" << R << " t: " << t
<< "\nE expected: " << E << " " << " E meas: " << Etest
<< "\nE expected: " << E << " " << " E meas: " << Etest
<< "\nB expected: " << B << " " << " B meas: " << Btest << std::endl;
EXPECT_FLOAT_EQ(B[i], Btest[i]) << "\nR:" << R
<< "\nE expected: " << E << " " << " E meas: " << Etest
EXPECT_FLOAT_EQ(B[i], Btest[i]) << "\nR:" << R
<< "\nE expected: " << E << " " << " E meas: " << Etest
<< "\nB expected: " << B << " " << " B meas: " << Btest << std::endl;
}
}
......@@ -238,7 +238,7 @@ Vector_t testMaxwell3(VariableRFCavityFringeField& cav, Vector_t pos, double t,
Vector_t result = dBdt*1e-1 + curlE;
if (verbose) {
std::cerr << "maxwell3 at R: " << pos << " t: " << t << " with dx: "
std::cerr << "maxwell3 at R: " << pos << " t: " << t << " with dx: "
<< deltaPos << " dt: " << deltaT << std::endl;
std::cerr << " dEdx " << dEdx << std::endl;
std::cerr << " dEdy " << dEdy << std::endl;
......@@ -263,12 +263,12 @@ std::vector<double> testMaxwell1and2(VariableRFCavityFringeField& cav, Vector_t
partial(cav, pos, t, deltaPos, 0, dEdx, dBdx);
partial(cav, pos, t, deltaPos, 1, dEdy, dBdy);
partial(cav, pos, t, deltaPos, 2, dEdz, dBdz);
double divE = dEdx[0] + dEdy[1] + dEdz[2];
double divB = dBdx[0] + dBdy[1] + dBdz[2];
if (verbose) {
std::cerr << "maxwell1+2 at R: " << pos << " t: " << t << " with dx: "
std::cerr << "maxwell1+2 at R: " << pos << " t: " << t << " with dx: "
<< deltaPos << std::endl;
std::cerr << " dEidi "
<< dEdx[0] << " " << dEdy[1] << " " << dEdz[2] << std::endl;
......@@ -343,4 +343,4 @@ TEST_F(VariableRFCavityFringeFieldTest, TestOrder) {
cav2.setMaxOrder(i);
cav2.apply(R, centroid, t, E, B);
}
}
}
\ No newline at end of file
......@@ -38,7 +38,7 @@ using namespace interpolation;
class SolveFactoryTestFixture : public ::testing::Test {
protected:
};
TEST(SolveFactoryTest, TestSolveNoDerivs) {
......@@ -105,7 +105,7 @@ TEST(SolveFactoryTest, TestSolveDerivs) {
}
}
// fill by hand the
// fill by hand the
std::vector< std::vector<double> > deriv_pos( {
{2, 0}, {2, 1}, {2, 2}, {1, 2}, {0, 2}
});
......@@ -113,7 +113,7 @@ TEST(SolveFactoryTest, TestSolveDerivs) {
{0,1}, {0,1}, {1,1}, {1,0}, {1,0}
});
std::vector<std::vector<double> > deriv_values(deriv_pos.size(),
std::vector<double>(2));
std::vector<double>(3));
for (size_t i = 0; i < deriv_pos.size(); ++i) {
SquarePolynomialVector refDeriv = ref.Deriv(&deriv_indices[i][0]);
refDeriv.F(&deriv_pos[i][0], &deriv_values[i][0]);
......@@ -135,4 +135,4 @@ TEST(SolveFactoryTest, TestSolveDerivs) {
for (size_t i = 0; i < 3; ++i)
for (size_t j = 0; j < 3; ++j)
EXPECT_NEAR(testCoeffs(i+1, j+1), refCoeffs(i+1, j+1), 1e-6);
}
}
\ No newline at end of file
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