Skip to content

Commit

Permalink
Added test of problem selection and enhanced the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kagalenko-m-b committed Jun 4, 2024
1 parent 0efb1ca commit 1c596cd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 31 deletions.
24 changes: 24 additions & 0 deletions Generated_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,27 @@ sub_add(::Val{:text}) = " Find the difference \\(c = a - b\\) and sum \\(d = a
sub_add(::Val{:solution_text}) = " Difference is equal to \\(c = %zw_sub%\\), sum is equal to \\(c = %zw_add%\\)\n"

```
When processing the macros, the left-hand sides of tilde `~` operators are collected
and then the tildes are replaced by the equality signs `=`. Otherwise the syntax
within the macro is the usual Julian syntax. The left-hand sides must always
represent a single variable; assignment to a tuple is unsupported.

The first method generates (usually randomized) data for the problem's statement.

The second method computes the solution. Arguments for this method are the symbols that
appear at the left-hand side of the tilde operator within the `@problem` macro,
but not the `@solution` macro. Their order as the arguments of the method call is the same
as their order of appearance at the left-hand side of the tilde. Those variables may be
assigned in the different order from what needed for the solution method, in which case
after assigning the needed values one may signal the inteded order in this fashion:

```julia

first_variable ~ first_variable
second_variable ~ second_variable
...
```
Other than telling the macro how to order the arguments of the second method, this is no-op.
To avoid ambiguity, it is not recommended to repeat any symbol at the left-hand side
of the tilde operator, and doing so produces a warning.

2 changes: 1 addition & 1 deletion src/MakeProblemSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Generate the latex source of the problems and solutions.
# Arguments
- `names::AbstractVector{String}`: Students' names
- `student_names::AbstractVector{String}`: Students' names
- `problems::AbstractVector{Function}`: Vector of functions defined using @problem macro
- `subsets::Union{Pair,Vector{<:Pair}}`: Subset specification or vector of specifications
- `rng_seed::Integer`: Random number generator's seed to make generated sets repeatable
Expand Down
66 changes: 36 additions & 30 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ function cleanup_string(str::AbstractString)
end

problem_1 = :(@problem sub_add begin
z ~ rand(7:9)
w ~ rand(1:5)
@solution begin
zw_sub ~ z - w
zw_add ~ z + w
end
@text raw"""
z ~ rand(7:9)
w ~ rand(1:5)
@solution begin
zw_sub ~ z - w
zw_add ~ z + w
end
@text raw"""
Find the difference \(c = a - b\) and sum \(d = a + b\)
of two values: \(a = %z%\) and \(b = %w%\)
"""
@text_solution raw"""
@text_solution raw"""
Difference is equal to \(c = %zw_sub%\), sum is equal to \(c = %zw_add%\)
"""
end)
end)

problem_2 = :(@problem sub begin
z ~ rand(7:9)
Expand All @@ -41,15 +41,15 @@ Find the difference \(c = a - b\) of two values: \(a = %zz%\) and \(b = %w%\)
end)

problem_3 = :(@problem add begin
z ~ rand(7:9)
w ~ rand(1:5)
@solution begin
zw_add ~ z + w
end
@text raw"""
z ~ rand(7:9)
w ~ rand(1:5)
@solution begin
zw_add ~ z + w
end
@text raw"""
Find the sum \(c = a + b\) of two values: \(a = %z%\) and \(b = %w%\)
"""
@text_solution raw"""
@text_solution raw"""
Sum is equal to \(c = %zww_add%\)
"""
end)
Expand All @@ -73,21 +73,21 @@ problem_set = :(@problemset test_problem_set begin
Base.remove_linenums!(pr)
@test length(pr.args) == 5
@test pr.args[1] == Base.remove_linenums!(:(function sub_add(; )
z = rand(7:9)
w = rand(1:5)
(zw_sub, zw_add) = sub_add(z, w)
return (z, w, zw_sub, zw_add)
end)
)

@test pr.args[3] == Base.remove_linenums!(:(function sub_add(z, w; )
begin
zw_sub = z - w
zw_add = z + w
end
return (zw_sub, zw_add)
z = rand(7:9)
w = rand(1:5)
(zw_sub, zw_add) = sub_add(z, w)
return (z, w, zw_sub, zw_add)
end)
)

@test pr.args[3] == Base.remove_linenums!(:(function sub_add(z, w; )
begin
zw_sub = z - w
zw_add = z + w
end
return (zw_sub, zw_add)
end)
)
#
data_1 = sub_add()
@test all(sub_add(data_1[1:2]...) .== data_1[3:end])
Expand Down Expand Up @@ -115,5 +115,11 @@ end
test_problem_set_add])
end


@testset "Problem selection" begin
@test_throws r"range" MakeProblemSet.select_problems(5,[1=>1:7])
idx = MakeProblemSet.select_problems(15,[1=>1:5, 2=>6:10, 3=>11:15])
@test count(1 .<= idx .<= 5) == 1
@test count(6 .<= idx .<= 10) == 2
@test count(11 .<= idx .<= 15) == 3
end

0 comments on commit 1c596cd

Please sign in to comment.