Ejemplo n.º 1
0
TEST(gm,issue109_csv_header_consistent_with_samples) {
  std::vector<std::string> model_path;
  model_path.push_back("src");
  model_path.push_back("test");
  model_path.push_back("test-models");
  model_path.push_back("compiled");
  model_path.push_back("issue109");

  std::string path = convert_model_path(model_path);
  std::string samples = path + ".csv";

  std::string command
    = path
    + " sample num_warmup=0 num_samples=1"
    + " output file=" + samples;

  run_command_output out = run_command(command);
  EXPECT_EQ(int(stan::gm::error_codes::OK), out.err_code);
  EXPECT_FALSE(out.hasError);

  std::ifstream ifstream;
  ifstream.open(samples.c_str());
  stan::mcmc::chains<> chains(stan::io::stan_csv_reader::parse(ifstream));
  ifstream.close();
  
  EXPECT_EQ(1, chains.num_samples());
  EXPECT_FLOAT_EQ(1, chains.samples("z[1,1]")(0));
  EXPECT_FLOAT_EQ(2, chains.samples("z[1,2]")(0));
  EXPECT_FLOAT_EQ(3, chains.samples("z[2,1]")(0));
  EXPECT_FLOAT_EQ(4, chains.samples("z[2,2]")(0));
  EXPECT_FLOAT_EQ(1, chains.samples("z_mat[1,1]")(0));
  EXPECT_FLOAT_EQ(2, chains.samples("z_mat[1,2]")(0));
  EXPECT_FLOAT_EQ(3, chains.samples("z_mat[2,1]")(0));
  EXPECT_FLOAT_EQ(4, chains.samples("z_mat[2,2]")(0));
}
TEST(gm,issue109_csv_header_consistent_with_samples) {
  char path_separator = get_path_separator();
  std::vector<std::string> model_path;
  model_path.push_back("src");
  model_path.push_back("test");
  model_path.push_back("gm");
  model_path.push_back("model_specs");
  model_path.push_back("compiled");
  model_path.push_back("issue109");

  std::string path = convert_model_path(model_path);
  std::string samples = path + ".csv";

  std::string command
    = path
    + " --iter=1"
    + " --warmup=0"
    + " --samples=" + samples;
  
  run_command(command);
  std::ifstream ifstream;
  ifstream.open(samples.c_str());
  stan::mcmc::chains<> chains(stan::io::stan_csv_reader::parse(ifstream));
  ifstream.close();
  
  EXPECT_EQ(1, chains.num_samples());
  EXPECT_FLOAT_EQ(1, chains.samples("z[1,1]")(0));
  EXPECT_FLOAT_EQ(2, chains.samples("z[1,2]")(0));
  EXPECT_FLOAT_EQ(3, chains.samples("z[2,1]")(0));
  EXPECT_FLOAT_EQ(4, chains.samples("z[2,2]")(0));
}
Ejemplo n.º 3
0
TEST(gm,issue91_segfault_printing_uninitialized) {
  std::vector<std::string> model_path;
  model_path.push_back("src");
  model_path.push_back("test");
  model_path.push_back("test-models");
  model_path.push_back("compiled");
  model_path.push_back("issue91");

  std::string command 
    = convert_model_path(model_path)
    + " sample num_warmup=0 num_samples=0"
    + " output file=" + convert_model_path(model_path) + ".csv";
  
  run_command_output out = run_command(command);
  EXPECT_EQ(int(stan::gm::error_codes::OK), out.err_code);
  EXPECT_FALSE(out.hasError);
}
TEST(gm,issue91_segfault_printing_uninitialized) {
  char path_separator = get_path_separator();
  std::vector<std::string> model_path;
  model_path.push_back("src");
  model_path.push_back("test");
  model_path.push_back("gm");
  model_path.push_back("model_specs");
  model_path.push_back("compiled");
  model_path.push_back("issue91");

  std::string command 
    = convert_model_path(model_path)
    + " --iter=0" 
    + " --samples=" + convert_model_path(model_path) + ".csv";
  
  run_command(command);

  SUCCEED()
    << "running this model should not seg fault";
}
Ejemplo n.º 5
0
  static void SetUpTestCase() {
    std::vector<std::string> model_path;
    model_path.push_back("..");
    model_path.push_back("src");
    model_path.push_back("test");
    model_path.push_back("gm");
    model_path.push_back("arguments");
    model_path.push_back("test_model");

    command += "cd test ";
    command += multiple_command_separator();
    command += " ";
    command += convert_model_path(model_path);
  }
Ejemplo n.º 6
0
TEST(StanGmArgumentsConfiguration, TestRandomWithoutMethod) {
  
  // Prepare model
  std::vector<std::string> model_path;
  model_path.push_back("src");
  model_path.push_back("test");
  model_path.push_back("gm");
  model_path.push_back("arguments");
  model_path.push_back("test_model");
  
  // Prepare arguments
  std::stringstream s;
  
  std::vector<stan::gm::argument*> valid_arguments;
  valid_arguments.push_back(new stan::gm::arg_random());
  
  stan::gm::argument_probe probe(valid_arguments);
  probe.probe_args(s);
  
  // Check argument consistency
  bool expected_success = false;
  
  std::string l1;
  std::stringstream expected_output;
  std::stringstream output;
  
  while (s.good()) {
    
    std::getline(s, l1);
    if (!s.good()) continue;
    
    if      (l1 == "good") expected_success = true;
    else if (l1 == "bad") expected_success = false;
    else if (l1 != "") expected_output << l1 << std::endl;
    else {
      
      int n_output = 0;
      
      std::string l2;
      std::string argument("");
      
      while (expected_output.good()) {
        std::getline(expected_output, l2);
        if (!expected_output.good()) continue;
        clean_line(l2);
        argument += " " + l2;
        ++n_output;
      }
      
      if (argument.length() == 0) continue;
      
      remove_duplicates(argument);
      
      std::string command = convert_model_path(model_path) + argument;
      run_command_output out = run_command(command);
      
      expected_output.clear();
      expected_output.seekg(std::ios_base::beg);
      
      if (expected_success == false) {
        
        unsigned int c1 = out.output.find("is not");
        out.output.erase(0, c1);
        unsigned int c2 = out.output.find(" \"");
        unsigned int c3 = out.output.find("Failed to parse");
        out.output.replace(c2, c3 - c2, "\n");
        
        expected_output.str(std::string());
        expected_output << "is not a valid value for" << std::endl;
        expected_output << "Failed to parse arguments, terminating Stan" << std::endl;
        n_output = 2;
        
      }
      else {
        expected_output.str(std::string());
        expected_output << "A method must be specified!" << std::endl;
        expected_output << "Failed to parse arguments, terminating Stan" << std::endl;
        n_output = 2;
      }
      
      output.str(out.output);
      
      for (int i = 0; i < n_output; ++i) {
        
        std::string expected_line;
        std::getline(expected_output, expected_line);
        
        std::string actual_line;
        std::getline(output, actual_line);
        
        EXPECT_EQ(expected_line, actual_line);
        
      }
      
      expected_output.clear();
      expected_output.seekg(std::ios_base::beg);
      expected_output.str(std::string());
      
    }
    
  }
  
  for (size_t i = 0; i < valid_arguments.size(); ++i)
    delete valid_arguments.at(i);
  
}