Skip to content

Commit

Permalink
Merge pull request #1197 from stan-dev/fix/pathfinder-json-test-white…
Browse files Browse the repository at this point in the history
…space

Make Pathfinder json test whitespace agnostic
  • Loading branch information
WardBrian authored Sep 6, 2023
2 parents 5bcf7c2 + da72861 commit 7f910eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
14 changes: 3 additions & 11 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ endif
@echo ' the nightly version.'
@echo ' STAN_CPP_OPTIMS: Turns on additonal compiler flags for performance.'
@echo ' STAN_NO_RANGE_CHECKS: Removes the range checks from the model for performance.'
@echo ' STAN_THREADS: Enable multi-threaded execution of the Stan model.'
@echo ''
@echo ''
@echo ' Example - bernoulli model: examples/bernoulli/bernoulli.stan'
Expand Down Expand Up @@ -295,9 +296,9 @@ endif
##
# Clean up.
##
.PHONY: clean clean-deps clean-manual clean-all clean-program
.PHONY: clean clean-deps clean-all

clean: clean-manual
clean:
$(RM) -r test
$(RM) $(wildcard $(patsubst %.stan,%.d,$(TEST_MODELS)))
$(RM) $(wildcard $(patsubst %.stan,%.hpp,$(TEST_MODELS)))
Expand All @@ -317,15 +318,6 @@ clean-all: clean clean-deps clean-libraries
$(RM) examples/bernoulli/bernoulli$(EXE) examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.d examples/bernoulli/bernoulli.hpp
$(RM) -r $(wildcard $(BOOST)/stage/lib $(BOOST)/bin.v2 $(BOOST)/tools/build/src/engine/bootstrap/ $(BOOST)/tools/build/src/engine/bin.* $(BOOST)/project-config.jam* $(BOOST)/b2 $(BOOST)/bjam $(BOOST)/bootstrap.log)

clean-program:
ifndef STANPROG
$(error STANPROG not set)
endif
$(RM) "$(wildcard $(patsubst %.stan,%.d,$(basename ${STANPROG}).stan))"
$(RM) "$(wildcard $(patsubst %.stan,%.hpp,$(basename ${STANPROG}).stan))"
$(RM) "$(wildcard $(patsubst %.stan,%.o,$(basename ${STANPROG}).stan))"
$(RM) "$(wildcard $(patsubst %.stan,%$(EXE),$(basename ${STANPROG}).stan))"

##
# Submodule related tasks
##
Expand Down
13 changes: 10 additions & 3 deletions src/test/interface/pathfinder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ TEST_F(CmdStan, pathfinder_single) {
EXPECT_EQ(1, count_matches("save_single_paths = 0 (Default)", output));
}

bool is_whitespace(char c) { return c == ' ' || c == '\n'; }

TEST_F(CmdStan, pathfinder_save_single_default_num_paths) {
std::stringstream ss;
ss << convert_model_path(multi_normal_model)
Expand Down Expand Up @@ -142,7 +144,10 @@ TEST_F(CmdStan, pathfinder_save_single_default_num_paths) {

rapidjson::Document document;
ASSERT_FALSE(document.Parse<0>(single_json.c_str()).HasParseError());
EXPECT_EQ(1, count_matches("\"1\" : {\"iter\" : 1,", single_json));
single_json.erase(
std::remove_if(single_json.begin(), single_json.end(), is_whitespace),
single_json.end());
EXPECT_EQ(1, count_matches("\"1\":{\"iter\":1,", single_json));
}

TEST_F(CmdStan, pathfinder_save_single_num_paths_1) {
Expand Down Expand Up @@ -233,6 +238,8 @@ TEST_F(CmdStan, pathfinder_lbfgs_iterations) {
ASSERT_FALSE(output.empty());
rapidjson::Document document;
ASSERT_FALSE(document.Parse<0>(output.c_str()).HasParseError());
EXPECT_EQ(1, count_matches("\"3\" : {\"iter\" : 3,", output));
EXPECT_EQ(0, count_matches("\"4\" : {\"iter\" : 4,", output));
output.erase(std::remove_if(output.begin(), output.end(), is_whitespace),
output.end());
EXPECT_EQ(1, count_matches("\"3\":{\"iter\":3,", output));
EXPECT_EQ(0, count_matches("\"4\":{\"iter\":4,", output));
}

0 comments on commit 7f910eb

Please sign in to comment.