@@ -10,34 +10,67 @@ using cmdstan::test::run_command_output;
1010class CmdStan : public testing ::Test {
1111 public:
1212 void SetUp () {
13- multi_normal_model = {" src" , " test" , " test-models" , " multi_normal_model" };
14- arg_output = {" test" , " output" };
15- output_csv = {" test" , " output.csv" };
16- output_json = {" test" , " output_config.json" };
13+ multi_normal_model = convert_model_path (
14+ std::vector{" src" , " test" , " test-models" , " multi_normal_model" });
15+ arg_output = convert_model_path (std::vector{" test" , " output" });
16+
17+ output_csv = convert_model_path (std::vector{" test" , " output.csv" });
18+ output_json = convert_model_path (std::vector{" test" , " output_config.json" });
19+
20+ output_csv_multi
21+ = convert_model_path (std::vector{" test" , " output_multi.csv" });
22+ output_json_multi
23+ = convert_model_path (std::vector{" test" , " output_multi_config.json" });
1724 }
1825
1926 void TearDown () {
20- std::remove (convert_model_path (output_csv).c_str ());
21- std::remove (convert_model_path (output_json).c_str ());
27+ std::remove (output_csv.c_str ());
28+ std::remove (output_json.c_str ());
29+ std::remove (output_csv_multi.c_str ());
30+ std::remove (output_json_multi.c_str ());
2231 }
2332
24- std::vector<std::string> multi_normal_model;
25- std::vector<std::string> arg_output;
26- std::vector<std::string> output_csv;
27- std::vector<std::string> output_json;
33+ std::string multi_normal_model;
34+ std::string arg_output;
35+ std::string output_csv;
36+ std::string output_json;
37+
38+ std::string output_csv_multi;
39+ std::string output_json_multi;
2840};
2941
3042TEST_F (CmdStan, config_json_output_valid) {
3143 std::stringstream ss;
32- ss << convert_model_path (multi_normal_model)
33- << " sample output file=" << convert_model_path (arg_output)
44+ ss << multi_normal_model << " sample output file=" << arg_output
3445 << " save_cmdstan_config=1" ;
3546 run_command_output out = run_command (ss.str ());
3647 ASSERT_FALSE (out.hasError ) << out.output ;
37- ASSERT_TRUE (file_exists (convert_model_path (output_csv)));
38- ASSERT_TRUE (file_exists (convert_model_path (output_json)));
48+ ASSERT_TRUE (file_exists (output_csv));
49+ ASSERT_TRUE (file_exists (output_json));
50+
51+ std::fstream json_in (output_json);
52+ std::stringstream result_json_sstream;
53+ result_json_sstream << json_in.rdbuf ();
54+ json_in.close ();
55+ std::string json = result_json_sstream.str ();
56+
57+ ASSERT_FALSE (json.empty ());
58+ ASSERT_TRUE (is_valid_JSON (json));
59+ }
60+
61+ TEST_F (CmdStan, config_json_output_valid_multi) {
62+ std::stringstream ss;
63+ ss << multi_normal_model
64+ << " sample num_chains=2 output file=" << output_csv_multi << " ,"
65+ << output_csv << " save_cmdstan_config=true" ;
66+ run_command_output out = run_command (ss.str ());
67+ ASSERT_FALSE (out.hasError ) << out.output ;
68+ ASSERT_TRUE (file_exists (output_csv_multi));
69+ ASSERT_TRUE (file_exists (output_csv));
70+ ASSERT_TRUE (file_exists (output_json_multi));
71+ ASSERT_FALSE (file_exists (output_json));
3972
40- std::fstream json_in (convert_model_path (output_json) );
73+ std::fstream json_in (output_json_multi );
4174 std::stringstream result_json_sstream;
4275 result_json_sstream << json_in.rdbuf ();
4376 json_in.close ();
@@ -49,10 +82,9 @@ TEST_F(CmdStan, config_json_output_valid) {
4982
5083TEST_F (CmdStan, config_json_output_not_requested) {
5184 std::stringstream ss;
52- ss << convert_model_path (multi_normal_model)
53- << " sample output file=" << convert_model_path (arg_output);
85+ ss << multi_normal_model << " sample output file=" << arg_output;
5486 run_command_output out = run_command (ss.str ());
5587 ASSERT_FALSE (out.hasError );
56- ASSERT_TRUE (file_exists (convert_model_path ( output_csv) ));
57- ASSERT_FALSE (file_exists (convert_model_path ( output_json) ));
88+ ASSERT_TRUE (file_exists (output_csv));
89+ ASSERT_FALSE (file_exists (output_json));
5890}
0 commit comments