diff --git a/src/Containers/DenseAxisArray.jl b/src/Containers/DenseAxisArray.jl index 0e421cd36c6..4f124de0a50 100644 --- a/src/Containers/DenseAxisArray.jl +++ b/src/Containers/DenseAxisArray.jl @@ -12,7 +12,6 @@ struct _AxisLookup{D} data::D end -Base.:(==)(x::_AxisLookup{D}, y::_AxisLookup{D}) where {D} = x.data == y.data # Default fallbacks. Base.getindex(::_AxisLookup, key) = throw(KeyError(key)) diff --git a/test/Containers/test_DenseAxisArray.jl b/test/Containers/test_DenseAxisArray.jl index fd780720a35..5d4d1345621 100644 --- a/test/Containers/test_DenseAxisArray.jl +++ b/test/Containers/test_DenseAxisArray.jl @@ -874,4 +874,51 @@ function test_multi_arg_eachindex() return end +function test_LinearIndices() + Containers.@container(x[i in 2:3], i) + @test_throws( + ErrorException("DenseAxisArray does not support this operation."), + LinearIndices(x), + ) + return +end + +function test_CartesianIndices() + Containers.@container(x[i in 2:3], i) + @test CartesianIndices(x) == CartesianIndices((2,)) + return +end + +function test_show_nd() + Containers.@container( + x[a in 2:3, b in 2:3, c in 2:14, d in 2:14], + (a, b, c, d), + ) + s = sprint(io -> show(IOContext(io, :limit => true), x)) + limit_indices = [2, 3, 4, 12, 13, 14] + for c in 2:14, d in 2:14 + is_visible = (c in limit_indices && d in limit_indices) + @test occursin("[:, :, $c, $d]", s) == is_visible + for a in 2:3, b in 2:3 + @test occursin("($a, $b, $c, $d)", s) == is_visible + end + end + s = sprint(io -> show(IOContext(io, :limit => false), x)) + limit_indices = [2, 3, 4, 12, 13, 14] + for c in 2:14, d in 2:14 + @test occursin("[:, :, $c, $d]", s) + for a in 2:3, b in 2:3 + @test occursin("($a, $b, $c, $d)", s) + end + end + return +end + +function test_view_DenseAxisArray() + Containers.@container(x[a in 2:3], a) + @test_throws KeyError view(x, 3:4) + @test_throws KeyError view(x, 4) + return +end + end # module diff --git a/test/Containers/test_SparseAxisArray.jl b/test/Containers/test_SparseAxisArray.jl index 86a6b0d85df..296dc83dfba 100644 --- a/test/Containers/test_SparseAxisArray.jl +++ b/test/Containers/test_SparseAxisArray.jl @@ -381,4 +381,11 @@ function test_sparseaxisarray_order() return end +function test_show_empty_limit() + x = SparseAxisArray(Dict{Tuple{Int},Int}()) + @test sprint(io -> show(IOContext(io, :limit => false), x)) == + "$SparseAxisArray{$Int, 1, Tuple{$Int}} with 0 entries" + return +end + end # module diff --git a/test/Containers/test_macro.jl b/test/Containers/test_macro.jl index 9227e240fe0..cdb2d3fe613 100644 --- a/test/Containers/test_macro.jl +++ b/test/Containers/test_macro.jl @@ -266,4 +266,10 @@ function test_add_additional_args() return end +function test_trailing_semicolon() + Containers.@container(x[a in 2:3;], a) + @test x isa DenseAxisArray + return +end + end # module diff --git a/test/Containers/test_vectorized_product_iterator.jl b/test/Containers/test_vectorized_product_iterator.jl index 03b509fbbf3..d38a07850b3 100644 --- a/test/Containers/test_vectorized_product_iterator.jl +++ b/test/Containers/test_vectorized_product_iterator.jl @@ -19,6 +19,7 @@ function test_VectorizedProductIterator() @test isempty(collect(Containers.vectorized_product(2, I, 1:0))) @test collect(Containers.vectorized_product(2, I)) == [(2, 1) (2, 3) (2, 2) (2, 4)] + @test ndims(Containers.vectorized_product(2, I)) == 2 return end @@ -35,4 +36,13 @@ function test_infinite_size() return end +function test_container_two_arg() + a = Containers.container(Containers.vectorized_product(2:3, 1:2)) do i, j + return (i, j) + end + Containers.@container(b[i in 2:3, j in 1:2], (i, j)) + @test a == b + return +end + end # module diff --git a/test/test_constraint.jl b/test/test_constraint.jl index cb63bb99e29..0ae9d46fca5 100644 --- a/test/test_constraint.jl +++ b/test/test_constraint.jl @@ -2194,27 +2194,37 @@ function test_shadow_price_errors() @test_throws err shadow_price(c) c = @constraint(model, x == 1) @test_throws err shadow_price(c) - model = Model() - @variable(model, x >= 0) + @variable(model, 0 <= x <= 1) set_optimizer( model, - () -> MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()), + () -> MOI.Utilities.MockOptimizer( + MOI.Utilities.Model{Float64}(); + eval_variable_constraint_dual = false, + ), ) optimize!(model) mock = unsafe_backend(model) MOI.set(mock, MOI.TerminationStatus(), MOI.OPTIMAL) MOI.set(mock, MOI.PrimalStatus(), MOI.FEASIBLE_POINT) MOI.set(mock, MOI.DualStatus(), MOI.FEASIBLE_POINT) - F, S = MOI.VariableIndex, MOI.GreaterThan{Float64} - xi = only(MOI.get(mock, MOI.ListOfVariableIndices())) - MOI.set(mock, MOI.ConstraintDual(), MOI.ConstraintIndex{F,S}(xi.value), 1.0) + F = MOI.VariableIndex + S1, S2 = MOI.GreaterThan{Float64}, MOI.LessThan{Float64} + i = only(MOI.get(mock, MOI.ListOfVariableIndices())).value + MOI.set(mock, MOI.ConstraintDual(), MOI.ConstraintIndex{F,S1}(i), 1.0) + MOI.set(mock, MOI.ConstraintDual(), MOI.ConstraintIndex{F,S2}(i), -1.0) @test_throws( ErrorException( "The shadow price is not available because the objective sense $FEASIBILITY_SENSE is not minimization or maximization.", ), shadow_price(LowerBoundRef(x)), ) + @test_throws( + ErrorException( + "The shadow price is not available because the objective sense $FEASIBILITY_SENSE is not minimization or maximization.", + ), + shadow_price(UpperBoundRef(x)), + ) return end diff --git a/test/test_model.jl b/test/test_model.jl index 6db3a692ed0..2f6009acf3f 100644 --- a/test/test_model.jl +++ b/test/test_model.jl @@ -1389,4 +1389,27 @@ function test_deepcopy() return end +struct _ModelNoSolverName <: MOI.AbstractOptimizer end + +MOI.is_empty(::_ModelNoSolverName) = true + +function test_solver_name_not_implemented() + model = direct_model(_ModelNoSolverName()) + @test solver_name(model) == + "SolverName() attribute not implemented by the optimizer." + return +end + +struct _ModelSolverNameError <: MOI.AbstractOptimizer end + +MOI.is_empty(::_ModelSolverNameError) = true + +MOI.get(::_ModelSolverNameError, ::MOI.SolverName) = error("test") + +function test_solver_name_error() + model = direct_model(_ModelSolverNameError()) + @test_throws ErrorException("test") solver_name(model) + return +end + end # module TestModels