Skip to content

Commit

Permalink
Improve coverage and fix macro bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsipher committed Oct 28, 2023
1 parent 3885ccc commit dd50ae7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ for (RefType, loc) in ((:DisjunctConstraintRef, :disjunct_constraints),
return cref1.model === cref2.model && cref1.index == cref2.index
end
Base.copy(cref::$RefType) = cref
@doc """
Base.getindex(map::GenericReferenceMap, cref::$($RefType))
...
"""
function Base.getindex(map::ReferenceMap, cref::$RefType)
$RefType(map.model, index(cref))
end
# @doc """
# Base.getindex(map::GenericReferenceMap, cref::$($RefType))

# ...
# """
# function Base.getindex(map::ReferenceMap, cref::$RefType)
# $RefType(map.model, index(cref))
# end
end
end

Expand Down
12 changes: 5 additions & 7 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function _extract_kwargs(args)
arg_list = collect(args)
if !isempty(args) && isexpr(args[1], :parameters)
p = popfirst!(arg_list)
append!(arg_list, p.args)
append!(arg_list, (Expr(:(=), a.args...) for a in p.args))
end
extra_kwargs = filter(x -> isexpr(x, :(=)) && x.args[1] != :container &&
x.args[1] != :base_name, arg_list)
Expand Down Expand Up @@ -153,19 +153,17 @@ The recognized keyword arguments in `kw_args` are the following:
of the axes `axes`.
- `container`: Specify the container type.
"""
macro disjunction(model, args...)
# prepare the model
esc_model = esc(model)

macro disjunction(args...)
# define error message function
_error(str...) = _macro_error(:disjunction, (model, args...),
_error(str...) = _macro_error(:disjunction, (args...),
__source__, str...)

# parse the arguments
pos_args, extra_kwargs, container_type, base_name = _extract_kwargs(args)

# initial processing of positional arguments
length(pos_args) >= 1 || _error("Not enough arguments, please see docs for accepted `@disjunction` syntax..")
length(pos_args) >= 2 || _error("Not enough arguments, please see docs for accepted `@disjunction` syntax..")
esc_model = esc(popfirst!(pos_args))
y = first(pos_args)
extra = pos_args[2:end]
if isexpr(args[1], :block)
Expand Down
2 changes: 1 addition & 1 deletion test/constraints/disjunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function test_disjunction_add_array()
@variable(model, x)
@variable(model, y[1:2, 1:3, 1:4], Logical)
@constraint(model, con[i=1:2, j=1:3, k=1:4], x==i+j+k, Disjunct(y[i,j,k]))
@disjunction(model, disj[i=1:2, j=1:3], y[i,j,:])
@disjunction(model, disj[i=1:2, j=1:3], y[i,j,:]; container = Array)

@test disj isa Matrix{DisjunctionRef}
@test length(disj) == 6
Expand Down
2 changes: 2 additions & 0 deletions test/constraints/proposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function test_proposition_add_fail()
@test_throws ErrorException @constraint(m, logical_or(y...) == 2)
@test_throws ErrorException @constraint(m, logical_or(y...) <= 1)
@test_throws ErrorException @constraint(m, sum(y) := true)
@test_throws ErrorException @constraint(m, y[1]^2 := true)
@test_throws ErrorException @constraint(m, sum(y) == true)
@test_throws ErrorException @constraint(m, prod(y) := true)
@test_throws ErrorException @constraint(m, sin(y[1]) := true)
@test_throws ErrorException @constraint(m, logical_or(y...) == true)
Expand Down

0 comments on commit dd50ae7

Please sign in to comment.