Repository navigation
[Flower Field] New practice exercise - #350
colinleach wants to merge 1 commit into
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) |
|
Is this a dupe of #352 ? |
No, it's the draft precursor which is now split into #351 (tooling) and #352 (draft of the exercise). I will close this #350. Fixing the test runner is most urgent right now. I'll come back to the exercises once we can run anything. Also, the |
This is the first exercise that passes 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.This exercise will not yet run in Docker, because the extended
testlib/TesterMain.f90needs to be copied to the test runner.I will open a PR on that repo.The test runner Dockerfile contains this line:
Presumably, we need to update the file on this repo, then rebuild the Docker image. Advice on how to proceed would be welcome.
I'll start by splitting out the tooling changes to a separate PR, to be merged first.
This got complicated, so I drafted in Claude to help me. The LLM notes are below the line, providing much more detail for documentation purposes.
Notes for reviewers: [Flower Field] New practice exercise
This PR adds the
flower-fieldpractice exercise. It is the first exercise to use a 2-D character array as both input and output, so it also changes some shared code: the test generator andtestlib. Those changes are the ones that most need review.1.
bin/generate_tests.py:fortran_matrixfilterThis filter came in with #343 and had not been used by any exercise until now. Using it 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, used asfortran_matrix("character(len=1)"), which 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 (
[" * ", "***"]).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. This doesn't affect flower-field. It would affect a future boolean-matrix exercise, which 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 blanks are significant cells here. Output is truncated with…like the other helpers.gfortran -Wall -std=f2018. It also builds under the track's-std=f2008 -W -Wall -Wextra -pedantic.Deployment order matters: this PR needs a companion test-runner PR. The
exercism/fortran-test-runnerimage bundles its own copy at/opt/test-runner/testlib/TesterMain.f90, and that copy does not have the new routine. With the current image, every flower-field test fails to compile withThere is no specific subroutine for the generic assert_equal(see Verification).fortran-test-runnerneeds a PR that brings in thisTesterMain.f90, merged and deployed before or together with this one. Otherwise every flower-field submission will error on the site.Separately, when there is no local
testlib, the exerciseCMakeLists.txtdownloadsTesterMain.f90frommainon GitHub, so local student builds also depend on this PR being merged.3. The exercise itself
annotate(garden)takescharacter(len=1), dimension(:,:)and returns acharacter(len=1)array of the same shape. Representing the garden as a 2-D character array (rather than an array of strings) seemed the most natural fit for Fortran. Happy to discuss the alternative..meta/example.f90: counts flowers in each cell's 3×3 neighbourhood (clipped at the edges) withcount()on an array section.flower_field.f90): declares the full signature and returns the input unchanged, so it compiles.no rows(0×0) andno columns(1×0).Verification
0 of 13 tests failed(per-exercise CMake build, with the track's gfortran flags).bin/check-cmake-files-up-to-date: passes.bin/verify-exercises-in-docker flower-fieldwith the currentexercism/fortran-test-runner:latestimage (digestsha256:e96e5c54…): fails. Every test fails to compile withThere is no specific subroutine for the generic assert_equal, because the image uses its own bundledTesterMain.f90.testlib/TesterMain.f90mounted over/opt/test-runner/testlib/TesterMain.f90: passes, 13/13 tests. The only blocker is therefore the runner's copy ofTesterMain. If CI runs the Docker verification, this PR will fail that check until the runner is updated.CMakeLists.txtbuild of all exercises.