diff --git a/Project.toml b/Project.toml index 9d2a73c..62cabc2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ProblemReductions" uuid = "899c297d-f7d2-4ebf-8815-a35996def416" authors = ["GiggleLiu and contributors"] -version = "0.3.3" +version = "0.3.4" [deps] BitBasis = "50ba71b6-fa0f-514d-ae9a-0916efc90dcf" diff --git a/src/models/models.jl b/src/models/models.jl index b39e352..df05165 100644 --- a/src/models/models.jl +++ b/src/models/models.jl @@ -311,7 +311,8 @@ The unit weight vector of length `n`. struct UnitWeight <: AbstractVector{Int} n::Int end -Base.getindex(::UnitWeight, i) = 1 +Base.getindex(::UnitWeight, i::Integer) = 1 +Base.getindex(::UnitWeight, inds::AbstractVector) = UnitWeight(length(inds)) Base.size(w::UnitWeight) = (w.n,) """ diff --git a/test/models/models.jl b/test/models/models.jl index 13bb99f..37e80b9 100644 --- a/test/models/models.jl +++ b/test/models/models.jl @@ -6,6 +6,14 @@ using Test, ProblemReductions @test ProblemReductions.combinations(3, 2) == [[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2]] end +@testset "UnitWeight" begin + w = UnitWeight(3) + @test w[1] == 1 + @test w[2] == 1 + @test w[3] == 1 + @test w[1:2] === UnitWeight(2) +end + @testset "Circuit" begin include("Circuit.jl") end