Skip to content

Commit e40f340

Browse files
committed
add tests
1 parent fae47b1 commit e40f340

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/macros.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function _name_call(base_name, idxvars)
4646
return ex
4747
end
4848

49-
# Process macro arugments
49+
# Process macro arguments
5050
function _extract_kwargs(args)
5151
arg_list = collect(args)
5252
if !isempty(args) && isexpr(args[1], :parameters)
@@ -89,15 +89,6 @@ function _add_positional_args(call, args)
8989
return
9090
end
9191

92-
# Determine if an expression contains any index variable symbols
93-
function _has_idxvars(expr, idxvars)
94-
expr in idxvars && return true
95-
if expr isa Expr
96-
return any(_has_idxvars(a, idxvars) for a in expr.args)
97-
end
98-
return false
99-
end
100-
10192
# Ensure a model argument is valid
10293
# Inspired from https://github.com/jump-dev/JuMP.jl/blob/d9cd5fb16c2d0a7e1c06aa9941923492fc9a28b5/src/macros.jl#L38-L44
10394
function _valid_model(_error::Function, model, name)

test/disjunction.jl renamed to test/constraints/disjunction.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
function test_macro_helpers()
2+
@test DP._esc_non_constant(1) == 1
3+
@test DP._get_name(:x) == :x
4+
@test DP._get_name("x") == "x"
5+
@test DP._get_name(Expr(:string,"x")) == Expr(:string,"x")
6+
@test DP._name_call("",[]) == ""
7+
@test DP._name_call("name",[]) == "name"
8+
end
9+
110
function test_disjunction_add_fail()
211
model = GDPModel()
312
@variable(model, x)
@@ -21,6 +30,7 @@ function test_disjunction_add_fail()
2130
@constraint(model, x == 10, DisjunctConstraint(y[2]))
2231
@disjunction(model, disj, y)
2332
@test_macro_throws UndefVarError @disjunction(model, disj, y) #duplicate name
33+
@test_throws ErrorException DP._error_if_cannot_register(error, model, :disj) #duplicate name
2434

2535
@test_macro_throws ErrorException @disjunction(model, "bad"[i=1:2], y) #wrong expression for disjunction name
2636
@test_macro_throws ErrorException @disjunction(model, [model=1:2], y) #index name can't be same as model name
@@ -209,6 +219,9 @@ function test_disjunction_function_nested()
209219
end
210220

211221
@testset "Disjunction" begin
222+
@testset "Macro Helpers" begin
223+
test_macro_helpers()
224+
end
212225
@testset "Add Disjunction" begin
213226
test_disjunction_add_fail()
214227
test_disjunction_add_success()

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ include("constraints/indicator.jl")
3737
include("constraints/bigm.jl")
3838
include("constraints/hull.jl")
3939
include("constraints/fallback.jl")
40-
include("disjunction.jl")
40+
include("constraints/disjunction.jl")
4141
include("solve.jl")

0 commit comments

Comments
 (0)