Skip to content

Commit

Permalink
fix 25 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiggleLiu committed Jun 23, 2022
1 parent a1e07e6 commit 0c0285f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/iterate_control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ julia> for each in itercontrol(7, [1, 3, 4, 7], (1, 0, 1, 0))
# NOTE: positions should be vector (MVector is the best), since it need to be sorted
# do not use Tuple, or other immutables, it increases the sorting time.
function itercontrol(nbits::Int, positions::AbstractVector, bit_configs)
@assert all(x->iszero(x) || isone(x), bit_configs) "Bit configurations should be 0 or 1"
base = bmask(Int, positions[i] for (i, u) in enumerate(bit_configs) if u != 0)
masks, factors = group_shift!(nbits, positions)
S = length(masks)
Expand Down Expand Up @@ -111,6 +112,7 @@ function group_shift!(nbits::Int, positions::AbstractVector{Int})
k_prv = 0
i = 0
for k in positions
@assert k > k_prv "Conflict at location: $k"
if k != k_prv + 1
push!(factors, 1<<(k_prv-i))
gap = k - k_prv-1
Expand Down
5 changes: 5 additions & 0 deletions test/iterate_control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ end
@test [ic...] == [ic[k] for k in 1:4]
end
end

@testset "regression test" begin
@test_throws AssertionError itercontrol(8, [8, 8], [1, 1])
@test_throws AssertionError itercontrol(8, [8], [-1])
end

0 comments on commit 0c0285f

Please sign in to comment.