Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Pathfinder json test whitespace agnostic #1197

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}