Repository navigation
Update tooling to handle Fortran matrices as input and output - #351
Merged
Merged
Conversation
|
Hello 👋 Thanks for your PR. This repo does not currently have dedicated maintainers. Our cross-track maintainers team will attempt to review and merge your PR, but it will likely take longer for your PR to be reviewed. If you enjoy contributing to Exercism and have a track-record of doing so successfully, you might like to become an Exercism maintainer for this track. Please feel free to ask any questions, or chat to us about anything to do with this PR or the reviewing process on the Exercism forum. (cc @exercism/cross-track-maintainers) |
IsaacG
approved these changes
Oct 26, 2026
This was referenced Oct 26, 2026
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.
Splitting draft #350, this PR replaces the first part.
Some new exercises will pass matrices as input argument and result. This seems desirable, as manipulating matrices and higher-dimensional arrays is probably >95% of what Fortran is used for.
Some extra tooling was needed:
bin/generate_tests.pyto convert from JSON nested lists.testlib/TesterMain.f90to generalize equality testing.The test runner Dockerfile contains this line:
Once this PR is merged, how do we get the docker image rebuilt and deployed with this new TesterMain? Exercises which are matrix-based (
flower-field,game-of-life, etc) will not run on docker in its current form.Claude comments are below the line, for documentation purposes.
Notes for reviewers: matrix support in the test generator and
testlibThis PR prepares the tooling for exercises whose input or output is a 2-D array. The first such exercise will be
flower-field, which comes in a separate PR after this one is merged. Nothing in this PR is used by an existing exercise yet. Regenerating every exercise's tests with the new generator produces no changes.1.
bin/generate_tests.py:fortran_matrixfilterThis filter came in with #343 and has not been used by any exercise yet. Writing the flower-field template showed three problems:
str(x), so string data produced invalid Fortran like[*, , 1]. A newfortran_literal()helper now writes strings as"x"(an embedded"is doubled), bools as.true./.false., and anything else withstr()as before.reshape([], [0, 0])is invalid because an empty array constructor has no type. The filter now takes an optionaltype_specargument. For example,fortran_matrix("character(len=1)")givesreshape([character(len=1) ::], [0, 0], order=[2, 1]). If the data is empty and notype_specwas given, it raisesValueErrorinstead of writing Fortran that won't compile.-Werror=line-truncation). An expression longer thanmax_width(default 80) is now split with&continuations, one matrix row per line, indented byindent(default 6). Short matrices stay on one line.Rows can be lists of scalars or strings. A string row gives one element per character, which matches how canonical data stores grids (
[" * ", "***"]).Example output, from flower-field's "large garden" case:
Things to check:
generate()runsbool_to_stronexpectedbefore the template's filters see it. A boolean matrix inexpectedwould therefore reachfortran_matrixas the strings".true."and be quoted. No planned exercise hits this. A future boolean-matrix exercise could fix it then.2.
testlib/TesterMain.f90: rank-2 characterassert_equalassert_equal_str_mat(estrmat, istrmat, test_description)added to theassert_equalinterface.Matrices are not the same shape!and reports both shapes (e.g.Expected < 2,2 > but got < 1,4 >), the same wayassert_equal_int_arrhandles a size mismatch.sm_to_sformats a failure as one quoted string per row:Expected < "1*","2 " > but got < "1*"," " >. Unlikesa_to_s, it keeps trailing blanks, because blank cells can be significant. Output is truncated with…like the other helpers.Follow-up needed in the test runner. The
exercism/fortran-test-runnerDockerfile fetchesTesterMain.f90from this repo'smainat build time, and the Docker layer cache keeps the old copy. After this PR merges, the runner'sbust_cacheneeds incrementing to force a rebuild, as in fortran-test-runner#55. The flower-field PR should wait until the rebuilt image is deployed.Verification
bin/generate_tests.py --no-pullover all exercises: no test files changed.bin/check-cmake-files-up-to-date: passes.assert_equaltested directly with 0×0, 1×0 and 2×2 matrices, a content mismatch and two shape mismatches. It builds cleanly under the track's flags (-std=f2008 -W -Wall -Wextra -pedantic).TesterMain.f90mounted.