Convert cxx_grid_example to a googletest test-case#254
Merged
brittonsmith merged 6 commits intoMar 25, 2025
Merged
Conversation
The cxx_grid_example was never really meant to be an example. In reality it was a crude way of writing some test-code that could not be directly implemented in pytest. The new test_ghost_zone file could use a little refactoring
The idea is to factor out reusable testing-logic into this library. At
present, we have factored out logic to:
- set the value of `chemistry_data_file::grackle_data_file`. This is
actually really important logic (it deals with figuring out the path
to the data directory) and would justify the existence of
the library on its own
- drawing a random uniformly distributed value on the unit interval in
portable, reproducible manner
- in reality, we don't actually need this function right now. The
test_ghost_zone logic is just looking for arbitrary values for
the sake of "finger-printing" (we are just trying to confirm that
the randomized arbitrary values are unchanged). I only realized
this after I wrote up a long comment justifying its existence.
Since this will inevitably be useful in the future, we're going
to hold onto the logic.
This was referenced Feb 28, 2025
brittonsmith
approved these changes
Mar 25, 2025
brittonsmith
left a comment
Contributor
There was a problem hiding this comment.
I reviewed this in PR #258.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR converts the
cxx_grid_example.C"code example" into a test run as part of the googletest suiteSome background:
cxx_grid_example.Cfile back when I fixed the logic in some of thecalculate_<quan>functions in order to respect thegrid_startandgrid_endmembers of thegrackle_field_datatype.grid_startandgrid_end. However, this test could not be part of the pytest testing framework, since the python bindings hard-code the values ofgrid_startandgrid_end.In any case, I think it obviously makes a lot of sense to shift this test to the googletest framework. This is easiest to review commit-by-commit:
primordial_chemistryvalue and converted the test so it was parameterized by theprimordial_chemistryvalue (in other words, we now run 4 separate test cases)grackle_field_datastruct to reduce memory leaks on test-failureThis was all a little more involved than I expected (I thought it would take under an hour), so I decided to cut my losses at this point. There are a few more tweaks I think would be good for the future:
grid_rank,grid_start,grid_end, andgrid_dimension(see issue Determine desired behavior for variousgrid_(rank|dimension|start|end)values #253)Footnotes
The logic for doing this is a little hacky. Currently, PR Modern Version Of: Transcribe contents of interpolators_g.F from Fortran to C #251 crudely implements similar logic its own tests. The idea here is to provide an abstraction for this hacky logic that can be reused across multiple tests. If PRs Auto File Management Part 1: Introducing a Datafile Management Tool #235, Auto File Management Part 2: Allow Grackle to search for automatically managed data files #237, and Auto File Management Part 3: Install data-management tool as command line program #246 get merged, then we can refactor the abstraction ↩
in reality, we don't actually need this function right now. The test_ghost_zone logic is just looking for arbitrary values for the sake of "finger-printing" (we are just trying to confirm that the randomized arbitrary values are unchanged -- the values shouldn't actually affect the output values). I only realized this after I wrote up a long comment justifying its existence. Since this will inevitably be useful in the future, we're going to hold onto the logic.
[^3] like
grid_start[i] >= grid_dimension[i],grid_end[i] >= grid_dimension[i],grid_start[i] > grid_end[i],grid_start[i] < 0,grid_end[i] < 0,grid_dimension[i] < 0, ↩