Skip to content

Commit

Permalink
add tests for MaximalChainsIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-roehrich committed Apr 15, 2024
1 parent 9e19fd0 commit ef8ca15
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions experimental/Posets/src/Poset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ function Base.iterate(iter::MaximalChainsIterator, chain::Vector{Int}=[1, 1])
return nothing
end

j = findnext(!=(0), cov[last(chain), :], s)
j = findnext(!=(0), iter.poset.cov[last(chain), :], s)
if !isnothing(j)
break
end
end

while !isnothing(j)
push!(c, j)
j = findnext(!=(0), cov[last(chain), :], j)
push!(chain, j)
j = findnext(!=(0), iter.poset.cov[last(chain), :], j)
end

if iter.inplace
Expand Down
18 changes: 18 additions & 0 deletions experimental/Posets/test/Poset-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,22 @@
test_poset(a2_adj_cov, a2_adj_rel)
test_poset(b2_adj_cov, b2_adj_rel)
end

@testset "iterate(::MaximalChainsIterator, ::Vector{Int})" begin
ps = poset(a2_adj_cov)
@test collect(maximal_chains(ps)) ==
[[1, 2, 4, 6], [1, 2, 5, 6], [1, 3, 4, 6], [1, 3, 5, 6]]

ps = poset(b2_adj_cov)
@test collect(maximal_chains(ps)) == [
[1, 2, 4, 6, 8],
[1, 2, 4, 7, 8],
[1, 2, 5, 6, 8],
[1, 2, 5, 7, 8],
[1, 3, 4, 6, 8],
[1, 3, 4, 7, 8],
[1, 3, 5, 6, 8],
[1, 3, 5, 7, 8],
]
end
end

0 comments on commit ef8ca15

Please sign in to comment.