<commit_before>// OneDimPPMNuclideTests.cpp
#include <deque>
#include <map>
#include <gtest/gtest.h>

#include "OneDimPPMNuclideTests.h"
#include "NuclideModelTests.h"
#include "NuclideModel.h"
#include "CycException.h"
#include "Material.h"
#include "XMLQueryEngine.h"

using namespace std;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
void OneDimPPMNuclideTest::SetUp(){
  // set up geometry. this usually happens in the component init
  r_four_ = 4;
  r_five_ = 5;
  point_t origin_ = {0,0,0}; 
  len_five_ = 5;
  geom_ = GeometryPtr(new Geometry(r_four_, r_five_, origin_, len_five_));

  // other vars
  theta_ = 0.3; // percent porosity
  v_ = 1; // m/yr
  time_ = 0;
  Ci_ = 1;
  Co_ = 2;
  porosity_ = 0.1;
  D_ = 4;
  rho_ = 5;
  Kd_ = 6;

  // composition set up
  u235_=92235;
  am241_=95241;
  one_kg_=1.0;
  test_comp_= CompMapPtr(new CompMap(MASS));
  (*test_comp_)[u235_] = one_kg_;
  test_size_=10.0;

  // material creation
  test_mat_ = mat_rsrc_ptr(new Material(test_comp_));
  test_mat_->setQuantity(test_size_);

  // test_one_dim_ppm_nuclide model setup
  mat_table_ = MDB->table("clay");
  one_dim_ppm_ptr_ = OneDimPPMNuclidePtr(initNuclideModel());
  one_dim_ppm_ptr_->set_mat_table(mat_table_);
  nuc_model_ptr_ = boost::dynamic_pointer_cast<NuclideModel>(one_dim_ppm_ptr_);
  nuc_model_ptr_->set_mat_table(mat_table_);
  default_one_dim_ppm_ptr_ = OneDimPPMNuclidePtr(OneDimPPMNuclide::create());
  default_nuc_model_ptr_ = boost::dynamic_pointer_cast<NuclideModel>(default_one_dim_ppm_ptr_);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
void OneDimPPMNuclideTest::TearDown() {
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
NuclideModelPtr OneDimPPMNuclideModelConstructor (){
  return boost::dynamic_pointer_cast<NuclideModel>(OneDimPPMNuclide::create());
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
OneDimPPMNuclidePtr OneDimPPMNuclideTest::initNuclideModel(){
  stringstream ss("");
  ss << "<start>"
     << "  <advective_velocity>" << v_ << "</advective_velocity>"
     << "  <initial_concentration>" << Ci_ << "</initial_concentration>"
     << "  <source_concentration>" << Co_ << "</source_concentration>"
     << "  <porosity>" << porosity_ << "</porosity>"
     << "  <bulk_density>" << rho_ << "</bulk_density>"
     << "</start>";

  XMLParser parser(ss);
  XMLQueryEngine* engine = new XMLQueryEngine(parser);
  OneDimPPMNuclidePtr one_dim_ppm_ptr = OneDimPPMNuclidePtr(OneDimPPMNuclide::create());
  one_dim_ppm_ptr->initModuleMembers(engine);
  delete engine;
  return one_dim_ppm_ptr;  
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, initial_state) {
  EXPECT_EQ(v_, one_dim_ppm_ptr_->v());
  EXPECT_EQ(Ci_, one_dim_ppm_ptr_->Ci());
  EXPECT_EQ(Co_, one_dim_ppm_ptr_->Co());
  EXPECT_EQ(rho_, one_dim_ppm_ptr_->rho());
  EXPECT_EQ(porosity_, one_dim_ppm_ptr_->porosity());
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, defaultConstructor) {
  ASSERT_EQ("ONEDIMPPM_NUCLIDE", nuc_model_ptr_->name());
  ASSERT_EQ(ONEDIMPPM_NUCLIDE, nuc_model_ptr_->type());
  ASSERT_FLOAT_EQ(0, one_dim_ppm_ptr_->geom()->length());
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, initFunctionNoXML) { 
  //EXPECT_NO_THROW(one_dim_ppm_ptr_->init(porosity_));
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, copy) {
  //ASSERT_NO_THROW(one_dim_ppm_ptr_->init(porosity_));
  OneDimPPMNuclidePtr test_copy = OneDimPPMNuclidePtr(OneDimPPMNuclide::create());
  OneDimPPMNuclidePtr one_dim_ppm_shared_ptr = OneDimPPMNuclidePtr(one_dim_ppm_ptr_);
  NuclideModelPtr nuc_model_shared_ptr = NuclideModelPtr(nuc_model_ptr_);
  EXPECT_NO_THROW(test_copy->copy(*one_dim_ppm_shared_ptr));
  EXPECT_NO_THROW(test_copy->copy(*nuc_model_shared_ptr));
  EXPECT_FLOAT_EQ(porosity_, test_copy->porosity());
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, absorb){
  // if you absorb a material, the conc_map should reflect that
  // you shouldn't absorb more material than you can handle. how much is that?
  for(int i=0; i<4; i++){
    ASSERT_EQ(i,time_);
    EXPECT_NO_THROW(nuc_model_ptr_->absorb(test_mat_));
    //EXPECT_NO_THROW(one_dim_ppm_ptr_->update_vec_hist(time_));
    //EXPECT_FLOAT_EQ((1+time_)*test_mat_->quantity(), one_dim_ppm_ptr_->contained_mass(time_));
    time_++;
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, extract){ 
  // it should be able to extract all of the material it absorbed
  double frac = 0.2;
  
  // if you extract a material, the conc_map should reflect that
  // you shouldn't extract more material than you have how much is that?

  ASSERT_EQ(0,time_);
  ASSERT_NO_THROW(nuc_model_ptr_->absorb(test_mat_));
  EXPECT_NO_THROW(one_dim_ppm_ptr_->transportNuclides(time_));
  //EXPECT_FLOAT_EQ(test_mat_->quantity(), one_dim_ppm_ptr_->contained_mass(time_));
  //EXPECT_FLOAT_EQ(test_size_, one_dim_ppm_ptr_->contained_mass(time_));

  for(int i=1; i<4; i++){
    time_++;
    ASSERT_EQ(i,time_);
    EXPECT_NO_THROW(nuc_model_ptr_->extract(test_comp_, frac*test_size_));
    EXPECT_NO_THROW(one_dim_ppm_ptr_->transportNuclides(time_));
    //EXPECT_FLOAT_EQ((1 - frac*time_)*test_size_, one_dim_ppm_ptr_->contained_mass(time_));
  }

}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, set_porosity){ 
  // the deg rate must be between 0 and 1, inclusive
  porosity_=0;
  //ASSERT_NO_THROW(one_dim_ppm_ptr_->set_porosity(porosity_));
  //EXPECT_FLOAT_EQ(one_dim_ppm_ptr_->porosity(), porosity_);
  porosity_=1;
  //ASSERT_NO_THROW(one_dim_ppm_ptr_->set_porosity(porosity_));
  //EXPECT_FLOAT_EQ(one_dim_ppm_ptr_->porosity(), porosity_);
  // it should accept floats<commit_msg>reinstating some tests<commit_after>// OneDimPPMNuclideTests.cpp
#include <deque>
#include <map>
#include <gtest/gtest.h>

#include "OneDimPPMNuclideTests.h"
#include "NuclideModelTests.h"
#include "NuclideModel.h"
#include "CycException.h"
#include "Material.h"
#include "XMLQueryEngine.h"

using namespace std;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
void OneDimPPMNuclideTest::SetUp(){
  // set up geometry. this usually happens in the component init
  r_four_ = 4;
  r_five_ = 5;
  point_t origin_ = {0,0,0}; 
  len_five_ = 5;
  geom_ = GeometryPtr(new Geometry(r_four_, r_five_, origin_, len_five_));

  // other vars
  theta_ = 0.3; // percent porosity
  v_ = 1; // m/yr
  time_ = 0;
  Ci_ = 1;
  Co_ = 2;
  porosity_ = 0.1;
  D_ = 4;
  rho_ = 5;
  Kd_ = 6;

  // composition set up
  u235_=92235;
  am241_=95241;
  one_kg_=1.0;
  test_comp_= CompMapPtr(new CompMap(MASS));
  (*test_comp_)[u235_] = one_kg_;
  test_size_=10.0;

  // material creation
  test_mat_ = mat_rsrc_ptr(new Material(test_comp_));
  test_mat_->setQuantity(test_size_);

  // test_one_dim_ppm_nuclide model setup
  mat_table_ = MDB->table("clay");
  one_dim_ppm_ptr_ = OneDimPPMNuclidePtr(initNuclideModel());
  one_dim_ppm_ptr_->set_mat_table(mat_table_);
  nuc_model_ptr_ = boost::dynamic_pointer_cast<NuclideModel>(one_dim_ppm_ptr_);
  nuc_model_ptr_->set_mat_table(mat_table_);
  default_one_dim_ppm_ptr_ = OneDimPPMNuclidePtr(OneDimPPMNuclide::create());
  default_nuc_model_ptr_ = boost::dynamic_pointer_cast<NuclideModel>(default_one_dim_ppm_ptr_);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
void OneDimPPMNuclideTest::TearDown() {
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
NuclideModelPtr OneDimPPMNuclideModelConstructor (){
  return boost::dynamic_pointer_cast<NuclideModel>(OneDimPPMNuclide::create());
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
OneDimPPMNuclidePtr OneDimPPMNuclideTest::initNuclideModel(){
  stringstream ss("");
  ss << "<start>"
     << "  <advective_velocity>" << v_ << "</advective_velocity>"
     << "  <initial_concentration>" << Ci_ << "</initial_concentration>"
     << "  <source_concentration>" << Co_ << "</source_concentration>"
     << "  <porosity>" << porosity_ << "</porosity>"
     << "  <bulk_density>" << rho_ << "</bulk_density>"
     << "</start>";

  XMLParser parser(ss);
  XMLQueryEngine* engine = new XMLQueryEngine(parser);
  OneDimPPMNuclidePtr one_dim_ppm_ptr = OneDimPPMNuclidePtr(OneDimPPMNuclide::create());
  one_dim_ppm_ptr->initModuleMembers(engine);
  delete engine;
  return one_dim_ppm_ptr;  
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, initial_state) {
  EXPECT_EQ(v_, one_dim_ppm_ptr_->v());
  EXPECT_EQ(Ci_, one_dim_ppm_ptr_->Ci());
  EXPECT_EQ(Co_, one_dim_ppm_ptr_->Co());
  EXPECT_EQ(rho_, one_dim_ppm_ptr_->rho());
  EXPECT_EQ(porosity_, one_dim_ppm_ptr_->porosity());
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, defaultConstructor) {
  ASSERT_EQ("ONEDIMPPM_NUCLIDE", nuc_model_ptr_->name());
  ASSERT_EQ(ONEDIMPPM_NUCLIDE, nuc_model_ptr_->type());
  ASSERT_FLOAT_EQ(0, one_dim_ppm_ptr_->geom()->length());
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, copy) {
  OneDimPPMNuclidePtr test_copy = OneDimPPMNuclidePtr(OneDimPPMNuclide::create());
  OneDimPPMNuclidePtr one_dim_ppm_shared_ptr = OneDimPPMNuclidePtr(one_dim_ppm_ptr_);
  NuclideModelPtr nuc_model_shared_ptr = NuclideModelPtr(nuc_model_ptr_);
  EXPECT_NO_THROW(test_copy->copy(*one_dim_ppm_shared_ptr));
  EXPECT_NO_THROW(test_copy->copy(*nuc_model_shared_ptr));
  EXPECT_FLOAT_EQ(porosity_, test_copy->porosity());
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, absorb){
  // if you absorb a material, the conc_map should reflect that
  // you shouldn't absorb more material than you can handle. how much is that?
  for(int i=0; i<4; i++){
    ASSERT_EQ(i,time_);
    EXPECT_NO_THROW(nuc_model_ptr_->absorb(test_mat_));
    EXPECT_NO_THROW(one_dim_ppm_ptr_->update_vec_hist(time_));
    EXPECT_FLOAT_EQ((1+time_)*test_mat_->quantity(), one_dim_ppm_ptr_->contained_mass(time_));
    time_++;
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, extract){ 
  // it should be able to extract all of the material it absorbed
  double frac = 0.2;
  
  // if you extract a material, the conc_map should reflect that
  // you shouldn't extract more material than you have how much is that?

  ASSERT_EQ(0,time_);
  ASSERT_NO_THROW(nuc_model_ptr_->absorb(test_mat_));
  EXPECT_NO_THROW(one_dim_ppm_ptr_->transportNuclides(time_));
  EXPECT_FLOAT_EQ(test_mat_->quantity(), one_dim_ppm_ptr_->contained_mass(time_));
  EXPECT_FLOAT_EQ(test_size_, one_dim_ppm_ptr_->contained_mass(time_));

  for(int i=1; i<4; i++){
    time_++;
    ASSERT_EQ(i,time_);
    EXPECT_NO_THROW(nuc_model_ptr_->extract(test_comp_, frac*test_size_));
    EXPECT_NO_THROW(one_dim_ppm_ptr_->transportNuclides(time_));
    //EXPECT_FLOAT_EQ((1 - frac*time_)*test_size_, one_dim_ppm_ptr_->contained_mass(time_));
  }

}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
TEST_F(OneDimPPMNuclideTest, set_porosity){ 
  // the deg rate must be between 0 and 1, inclusive
  porosity_=0;
  //ASSERT_NO_THROW(one_dim_ppm_ptr_->set_porosity(porosity_));
  //EXPECT_FLOAT_EQ(one_dim_ppm_ptr_->porosity(), porosity_);
  porosity_=1;
  //ASSERT_NO_THROW(one_dim_ppm_ptr_->set_porosity(porosity_));
  //EXPECT_FLOAT_EQ(one_dim_ppm_ptr_->porosity(), porosity_);
  // it should accept floats
{'fraction_non_alphanumeric': 0.1847835085685901, 'fraction_numerical': 0.009106714131964566, 'mean_word_length': 2.6975818794000612, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 126, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '655959', 'n_tokens_mistral': 5136, 'n_tokens_neox': 4806, 'n_words': 605}