Skip to content

Add templates 12 - #1166

Merged
colinleach merged 4 commits into
exercism:mainfrom
colinleach:add-templaters-12
Oct 25, 2026
Merged

colinleach merged 4 commits into
exercism:mainfrom
colinleach:add-templaters-12

Conversation

@colinleach

Copy link
Copy Markdown
Contributor

They are getting a bit more complicated by this stage, with some serious Julia-only testing to think about. I'm happy to keep the ::Integer restriction in difference-of-squares. rational-numbers has always been near-impossibly difficult, so I've moved the most challenging bits behind an opt-in flag. I think this may need an instructions-append.md, so I'll mark this draft for now.


Adds Jinja2 test templates for difference-of-squares, complex-numbers, rational-numbers, custom-set, circular-buffer and robot-simulator

Each runtests.jl is regenerated from canonical data, and every exercise passes against its example solution, including the opt-in bonus tests. Every templated exercise still passes generate_tests.py --check. No shared macros changed in this PR.

The canonical-only rule applies, with two kinds of exception, both worth a look:

  • difference-of-squares keeps the ::Integer type assertions.
  • Opt-in bonus tests are kept behind their flags. circular-buffer and complex-numbers already had them. rational-numbers now has one too.

The bonus blocks are Julia code, not cases, so they are written into the template as a fixed block after the canonical cases rather than in .meta/additional_tests.json. The test file checks the flag with @isdefined(...). Each example solution sets its flag, so CI runs the bonus tests.

Hand-written tests that weren't canonical, and weren't behind a flag, have been removed.

Things to look at:

  • difference-of-squares:
    • Every assertion keeps the type check, e.g. @test square_of_sum(5)::Integer == 225, so solutions that use / instead of ÷ still fail.
    • 13 assertions became 9. The canonical inputs are 1, 5 and 100 for each function. Removed: the three 10 cases and difference(0).
  • complex-numbers:
    • Canonical expressions become Julia: "pi" → π, "e" → ℯ, "ln(2)/2" → log(2)/2.
    • Division and exp compare with ≈. exp keeps atol = 1e-15. The two exact divisions that used == now also use ≈.
    • "Imaginary unit" is the canonical ComplexNumber(0, 1) * ComplexNumber(0, 1) instead of ComplexNumber(0, 1)^2.
    • Bonus A (operations between real and complex numbers) is canonical, so it is generated, behind enable_realcomplex_tests as before.
    • Bonus B (jm syntax sugar) is not canonical. It is copied unchanged into the template, behind enable_syntaxsugar_tests.
    • Removed: @test ComplexNumber <: Number.
  • rational-numbers:
    • New enable_bonus_tests flag. The old file's Julia-specific tests are now opt-in, in a "Bonus: Julia number interfaces" testset. These are:
      • RationalNumber <: Real
      • RationalNumber(0, 0) throws ArgumentError
      • conversion and promotion, with the comment pointing to the manual
      • zero / one
      • adding a RationalNumber and an integer, in both orders
      • the "Ordering" loop based on Julia Base's tests (MIT, credited as before)
    • The stub has an "uncomment to enable" comment for the flag, as complex-numbers does. .meta/example.jl ends with enable_bonus_tests = true.
    • Without the flag, students only need the canonical operations between two RationalNumbers. Adding an integer moved into the bonus, because it depends on promotion.
    • The canonical cases include two the old file didn't have: abs(RationalNumber(-1, -2)) and RationalNumber(-3, 5)^-2.
    • Reduction cases keep the numerator(r) / denominator(r) checks.
    • The real-to-rational power 8^RationalNumber(4, 3) is compared with ≈ 16.0, the canonical value. Before, it was compared with ≈ 15.999999999999998.
  • circular-buffer:
    • Each canonical operation becomes a statement in order:
      • write: @test push!(cb, x) === cb
      • overwrite: push!(cb, x; overwrite=true)
      • read: @test popfirst!(cb) == x
      • clear: @test empty!(cb) === cb
      • Operations that should fail are @test_throws BoundsError.
    • The bonus block (<: AbstractVector and the DataStructures.jl test set) is copied unchanged into the template, behind enable_bonus_tests. It matches the "Bonus tasks" section of instructions.append.md.
    • Removed, because they weren't behind the flag: the "overwrite=true and overwrite=false" and "type parameter" testsets.
  • custom-set:
    • The canonical intersection, difference and union cases each test both the plain function and its in-place version (intersect / intersect!, complement / complement!, union / union!), as before. These used to be in separate "in-place" and "not in-place" testsets.
    • Empty results are checked with isempty(...).
    • Removed: CustomSet <: Base.AbstractSet, and the length, iteration and copy tests.
  • robot-simulator:
    • Every canonical case builds Robot((x, y), DIRECTION), runs move!(r, "...") for move cases, then checks position(r) == Point(x, y) and heading(r) == DIRECTION.
    • The rotation and advance cases are now one testset each, run through move! with "R", "L" or "A". 31 assertions became 36.
    • Removed: "mutating functions should return robot", and the direct calls to turn_right!, turn_left! and advance!. Solutions still need these functions to implement move!, but no test calls them directly.

@github-actions

Copy link
Copy Markdown
Contributor

This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.

If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

@colinleach colinleach mentioned this pull request Oct 25, 2026
82 tasks done
@colinleach

Copy link
Copy Markdown
Contributor Author

I've added a brief instructions append to rational numbers, and a fairly minimal set of function stubs in the solution file. I still don't get an entirely warm fuzzy feeling about it, but it's probably OK for something with difficulty 8.

@colinleach
colinleach marked this pull request as ready for review October 25, 2026 20:25
@colinleach
colinleach requested a review from depial October 25, 2026 20:25
@colinleach

Copy link
Copy Markdown
Contributor Author

I spotted belatedly that robot-simulator has no function stubs. That is fixed in #1167 (and much else besides).

@depial depial left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the one comment, but I think the rest is okay.

Comment thread exercises/practice/rational-numbers/rational-numbers.jl Outdated
@colinleach colinleach added the ready-to-translate The English in this PR is final; queue its translations label Oct 25, 2026
exercism-i18n Bot added a commit to exercism/i18n that referenced this pull request Oct 25, 2026
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@exercism-i18n

exercism-i18n Bot commented Oct 25, 2026

Copy link
Copy Markdown

This PR has been translated 🚀

@colinleach
colinleach merged commit 882e37a into exercism:main Oct 25, 2026
12 of 13 checks passed
@colinleach
colinleach deleted the add-templaters-12 branch October 28, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-translate The English in this PR is final; queue its translations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants