Commit f77a2f26 authored by Kristin Berry's avatar Kristin Berry
Browse files

Update some of the tests that set a new state value to use a function in the...

Update some of the tests that set a new state value to use a function in the fixture, rather than repeating code
parent a21916bf
Loading
Loading
Loading
Loading
+18 −15
Original line number Diff line number Diff line
@@ -98,30 +98,33 @@ protected:
  };
};

class FrameIsdTest : public ::testing::Test {
class FrameStateTest : public ::testing::Test {
  protected:
    csm::Isd isd;
    void printIsd(csm::Isd &localIsd) {
      std::multimap<std::string,std::string> isdmap= localIsd.parameters();
      for (auto it = isdmap.begin(); it != isdmap.end();++it){
        std::cout << it->first << " : " << it->second << std::endl;
      }
    }
    UsgsAstroFrameSensorModel* createModel(csm::Isd &modifiedIsd) {
    
    UsgsAstroFrameSensorModel* createModifiedStateSensorModel(std::string key, double newValue) {
      UsgsAstroFramePlugin frameCameraPlugin;
      modifiedIsd.setFilename("data/simpleFramerISD.img");
      csm::Model *model = frameCameraPlugin.constructModelFromISD(
              modifiedIsd,"USGS_ASTRO_FRAME_SENSOR_MODEL");
      csm::Model *model = frameCameraPlugin.constructModelFromISD(isd,"USGS_ASTRO_FRAME_SENSOR_MODEL");
      UsgsAstroFrameSensorModel* sensorModel = dynamic_cast<UsgsAstroFrameSensorModel *>(model);
      if (sensorModel)
      if (sensorModel) {
        sensorModel->getModelState(); 
        std::string modelState = sensorModel->getModelState(); 
        auto state = json::parse(modelState);
        state[key] = newValue; 
        sensorModel->replaceModelState(state.dump()); 

        return sensorModel;
      else
      }
      else {
        return nullptr;
      }
    }

    virtual void SetUp() {
    void SetUp() override {
      isd.setFilename("data/simpleFramerISD.img");
    }
};



#endif
+24 −62
Original line number Diff line number Diff line
@@ -216,22 +216,11 @@ TEST_F(FrameSensorModel, setFocalPlane_AlternatingOnes) {
}



// Focal Length Tests:
TEST_F(FrameSensorModel, FL500_OffBody4) {
TEST_F(FrameStateTest, FL500_OffBody4) {
  std::string key = "m_focalLength";
  double newValue = 500.0;

  std::string modelState = sensorModel->getModelState(); 
  auto state = json::parse(modelState);
  state[key] = newValue; 
  sensorModel->replaceModelState(state.dump()); 

  sensorModel->setParameterValue(0, 1000.0); // X
  sensorModel->setParameterValue(1, 0.0); // Y 
  sensorModel->setParameterValue(2, 0.0); // Z

  modelState = sensorModel->getModelState(); 
  UsgsAstroFrameSensorModel* sensorModel = createModifiedStateSensorModel(key, newValue);

  ASSERT_NE(sensorModel, nullptr);
  csm::ImageCoord imagePt(15.0, 15.0);
@@ -245,14 +234,10 @@ TEST_F(FrameSensorModel, FL500_OffBody4) {
}


TEST_F(FrameSensorModel, FL500_OffBody3) {
TEST_F(FrameStateTest, FL500_OffBody3) {
  std::string key = "m_focalLength";
  double newValue = 500.0;

  std::string modelState = sensorModel->getModelState(); 
  auto state = json::parse(modelState);
  state[key] = newValue; 
  sensorModel->replaceModelState(state.dump()); 
  UsgsAstroFrameSensorModel* sensorModel = createModifiedStateSensorModel(key, newValue);
  
  ASSERT_NE(sensorModel, nullptr);
  csm::ImageCoord imagePt(0.0, 0.0);
@@ -266,14 +251,10 @@ TEST_F(FrameSensorModel, FL500_OffBody3) {
}


TEST_F(FrameSensorModel, FL500_Center) {
TEST_F(FrameStateTest, FL500_Center) {
  std::string key = "m_focalLength";
  double newValue = 500.0;

  std::string modelState = sensorModel->getModelState(); 
  auto state = json::parse(modelState);
  state[key] = newValue; 
  sensorModel->replaceModelState(state.dump()); 
  UsgsAstroFrameSensorModel* sensorModel = createModifiedStateSensorModel(key, newValue);

  ASSERT_NE(sensorModel, nullptr);
  csm::ImageCoord imagePt(7.5, 7.5);
@@ -287,14 +268,10 @@ TEST_F(FrameSensorModel, FL500_Center) {
}


TEST_F(FrameSensorModel, FL500_SlightlyOffCenter) {
TEST_F(FrameStateTest, FL500_SlightlyOffCenter) {
  std::string key = "m_focalLength";
  double newValue = 500.0;

  std::string modelState = sensorModel->getModelState(); 
  auto state = json::parse(modelState);
  state[key] = newValue; 
  sensorModel->replaceModelState(state.dump()); 
  UsgsAstroFrameSensorModel* sensorModel = createModifiedStateSensorModel(key, newValue);

  ASSERT_NE(sensorModel, nullptr);
  csm::ImageCoord imagePt(7.5, 6.5);
@@ -325,7 +302,6 @@ TEST_F(FrameSensorModel, X10_SlightlyOffCenter) {

TEST_F(FrameSensorModel, X1e9_SlightlyOffCenter) {
   double newValue = 1000000000.0;

   sensorModel->setParameterValue(0, newValue); // X

   ASSERT_NE(sensorModel, nullptr);
@@ -343,7 +319,6 @@ TEST_F(FrameSensorModel, X1e9_SlightlyOffCenter) {

// Angle rotations:
TEST_F(FrameSensorModel, Rotation_omegaPi_Center) {

   sensorModel->setParameterValue(3, 1.0); 
   sensorModel->setParameterValue(4, 1.0); 
   sensorModel->setParameterValue(5, 1.0); 
@@ -366,7 +341,6 @@ TEST_F(FrameSensorModel, Rotation_omegaPi_Center) {


TEST_F(FrameSensorModel, Rotation_NPole_Center) {

  sensorModel->setParameterValue(3, 0.0); 
  sensorModel->setParameterValue(4, -1.0); 
  sensorModel->setParameterValue(5, 0.0); 
@@ -407,14 +381,10 @@ TEST_F(FrameSensorModel, Rotation_SPole_Center) {


// Ellipsoid axis tests:
TEST_F(FrameSensorModel, SemiMajorAxis100x_Center) {
TEST_F(FrameStateTest, SemiMajorAxis100x_Center) {
  std::string key = "m_majorAxis";
  double newValue = 1000.0;

  std::string modelState = sensorModel->getModelState(); 
  auto state = json::parse(modelState);
  state[key] = newValue; 
  sensorModel->replaceModelState(state.dump()); 
  UsgsAstroFrameSensorModel* sensorModel = createModifiedStateSensorModel(key, newValue);

  ASSERT_NE(sensorModel, nullptr);
  csm::ImageCoord imagePt(7.5, 7.5);
@@ -428,14 +398,10 @@ TEST_F(FrameSensorModel, SemiMajorAxis100x_Center) {
}


TEST_F(FrameSensorModel, SemiMajorAxis10x_SlightlyOffCenter) {
TEST_F(FrameStateTest, SemiMajorAxis10x_SlightlyOffCenter) {
  std::string key = "m_majorAxis";
  double newValue = 100.0;

  std::string modelState = sensorModel->getModelState(); 
  auto state = json::parse(modelState);
  state[key] = newValue; 
  sensorModel->replaceModelState(state.dump()); 
  UsgsAstroFrameSensorModel* sensorModel = createModifiedStateSensorModel(key, newValue);

  ASSERT_NE(sensorModel, nullptr);
  csm::ImageCoord imagePt(7.5, 6.5);
@@ -453,14 +419,10 @@ TEST_F(FrameSensorModel, SemiMajorAxis10x_SlightlyOffCenter) {

// The following test is for the scenario where the semi_minor_axis is actually larger
// than the semi_major_axis:
TEST_F(FrameSensorModel, SemiMinorAxis10x_SlightlyOffCenter) {
TEST_F(FrameStateTest, SemiMinorAxis10x_SlightlyOffCenter) {
  std::string key = "m_minorAxis";
  double newValue = 100.0;

   std::string modelState = sensorModel->getModelState(); 
   auto state = json::parse(modelState);
   state[key] = newValue;
   sensorModel->replaceModelState(state.dump()); 
  UsgsAstroFrameSensorModel* sensorModel = createModifiedStateSensorModel(key, newValue);

  ASSERT_NE(sensorModel, nullptr);
  csm::ImageCoord imagePt(7.5, 6.5);