Repository navigation
Add templates 12 - #1166
Add templates 12#1166
Conversation
|
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. For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping |
|
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. |
|
I spotted belatedly that |
depial
left a comment
There was a problem hiding this comment.
Just the one comment, but I think the rest is okay.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
This PR has been translated 🚀 |
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
::Integerrestriction indifference-of-squares.rational-numbershas always been near-impossibly difficult, so I've moved the most challenging bits behind an opt-in flag. I think this may need aninstructions-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.jlis regenerated from canonical data, and every exercise passes against its example solution, including the opt-in bonus tests. Every templated exercise still passesgenerate_tests.py --check. No shared macros changed in this PR.The canonical-only rule applies, with two kinds of exception, both worth a look:
::Integertype assertions.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:
@test square_of_sum(5)::Integer == 225, so solutions that use/instead of÷still fail.10cases anddifference(0)."pi"→π,"e"→ℯ,"ln(2)/2"→log(2)/2.expcompare with≈.expkeepsatol = 1e-15. The two exact divisions that used==now also use≈.ComplexNumber(0, 1) * ComplexNumber(0, 1)instead ofComplexNumber(0, 1)^2.enable_realcomplex_testsas before.jmsyntax sugar) is not canonical. It is copied unchanged into the template, behindenable_syntaxsugar_tests.@test ComplexNumber <: Number.enable_bonus_testsflag. The old file's Julia-specific tests are now opt-in, in a "Bonus: Julia number interfaces" testset. These are:RationalNumber <: RealRationalNumber(0, 0)throwsArgumentErrorzero/oneRationalNumberand an integer, in both orders.meta/example.jlends withenable_bonus_tests = true.RationalNumbers. Adding an integer moved into the bonus, because it depends on promotion.abs(RationalNumber(-1, -2))andRationalNumber(-3, 5)^-2.numerator(r)/denominator(r)checks.8^RationalNumber(4, 3)is compared with≈ 16.0, the canonical value. Before, it was compared with≈ 15.999999999999998.@test push!(cb, x) === cbpush!(cb, x; overwrite=true)@test popfirst!(cb) == x@test empty!(cb) === cb@test_throws BoundsError.<: AbstractVectorand the DataStructures.jl test set) is copied unchanged into the template, behindenable_bonus_tests. It matches the "Bonus tasks" section ofinstructions.append.md.intersect/intersect!,complement/complement!,union/union!), as before. These used to be in separate "in-place" and "not in-place" testsets.isempty(...).CustomSet <: Base.AbstractSet, and thelength, iteration andcopytests.Robot((x, y), DIRECTION), runsmove!(r, "...")formovecases, then checksposition(r) == Point(x, y)andheading(r) == DIRECTION.move!with"R","L"or"A". 31 assertions became 36.turn_right!,turn_left!andadvance!. Solutions still need these functions to implementmove!, but no test calls them directly.