Skip to content

Commit

Permalink
coverage fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsipher committed Feb 1, 2024
1 parent 07bc162 commit ca2ae98
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ macro disjunction(args...)
error_fn("Unrecognized syntax, please see docs for accepted `@disjunction` syntax.")
end

# make sure param is something reasonable
if !(c isa Union{Nothing, Symbol, Expr})
error_fn("Expected `$c` to be a disjunction name.")
end
# make sure param is something reasonable (I don't think this is needed)
# if !(c isa Union{Nothing, Symbol, Expr})
# error_fn("Expected `$c` to be a disjunction name.")
# end

# process the container input
name, idxvars, inds = Containers.parse_ref_sets(
Expand Down
4 changes: 4 additions & 0 deletions test/constraints/disjunction.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function test_macro_helpers()
@test DP._esc_non_constant(1) == 1
@test_throws ErrorException DP._error_if_cannot_register(error, Model(), 42)
end

function test_disjunction_add_fail()
Expand All @@ -9,6 +10,8 @@ function test_disjunction_add_fail()
@constraint(model, x == 5, Disjunct(y[1]))

@test_macro_throws ErrorException @disjunction(model) #not enough arguments
@test_macro_throws ErrorException @disjunction(42, y) #a model was not given
@test_macro_throws ErrorException @disjunction(model, "bob"[i = 1:1], y[1:1]) #bad name
@test_macro_throws UndefVarError @disjunction(model, y) #unassociated indicator
@test_macro_throws UndefVarError @disjunction(GDPModel(), y) #wrong model
@test_throws ErrorException disjunction(Model(), y) #not a GDPModel
Expand All @@ -24,6 +27,7 @@ function test_disjunction_add_fail()

@constraint(model, x == 10, Disjunct(y[2]))
@disjunction(model, disj, y)
@test model[:disj] isa DisjunctionRef
@test_macro_throws UndefVarError @disjunction(model, disj, y) #duplicate name
@test_throws ErrorException DP._error_if_cannot_register(error, model, :disj) #duplicate name

Expand Down
5 changes: 5 additions & 0 deletions test/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,25 @@ function test_logic_constraint_printing()
@variable(model, Y[1:2], Logical)
@constraint(model, c1, ¬(Y[1] && Y[2]) == (Y[1] || Y[2]) := true)
c2 = @constraint(model, ¬(Y[1] && Y[2]) == (Y[1] || Y[2]) := true)
c3 = @constraint(model, Y[1] Y[2] := true)

# Test plain printing
if Sys.iswindows()
show_test(MIME("text/plain"), c1, "c1 : !(Y[1] and Y[2]) <--> (Y[1] or Y[2]) = True")
show_test(MIME("text/plain"), c2, "!(Y[1] and Y[2]) <--> (Y[1] or Y[2]) = True")
show_test(MIME("text/plain"), c3, "-->(Y[1], Y[2]) = True")
else
show_test(MIME("text/plain"), c1, "c1 : ¬(Y[1] ∧ Y[2]) ⟺ (Y[1] ∨ Y[2]) = True")
show_test(MIME("text/plain"), c2, "¬(Y[1] ∧ Y[2]) ⟺ (Y[1] ∨ Y[2]) = True")
show_test(MIME("text/plain"), c3, "⟹(Y[1], Y[2]) = True")
end

# Test LaTeX printing
str = "\$\$ {\\textsf{\\neg}\\left({{Y_{1}} \\wedge {Y_{2}}}\\right)} \\iff {\\left({Y_{1}} \\vee {Y_{2}}\\right)} = \\text{True} \$\$"
show_test(MIME("text/latex"), c1, str)
show_test(MIME("text/latex"), c2, str)
str = "\$\$ \\textsf{\\implies}\\left({Y_{1}}, {Y_{2}}\\right) = \\text{True} \$\$"
show_test(MIME("text/latex"), c3, str) == str

# Test cardinality constraints
for (Set, s) in ((Exactly, "exactly"), (AtMost, "atmost"), (AtLeast, "atleast"))
Expand Down

0 comments on commit ca2ae98

Please sign in to comment.