Skip to content

Commit

Permalink
fix iteration on AugmentedBasis and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed May 15, 2024
1 parent 2cb891f commit 74d8d1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/diracs_augmented.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct AugmentedBasis{T,I,A<:Augmented{T},B<:AbstractBasis{T,I}} <:
end

function AugmentedBasis(basis::DiracBasis{T,I}) where {T,I}
@assert one(object(basis)) in basis
return AugmentedBasis{T,I,Augmented{T},typeof(basis)}(basis)
end

Expand All @@ -67,10 +68,18 @@ function Base.length(ab::AugmentedBasis)
end

function Base.iterate(ab::AugmentedBasis)
return ((v, st) = iterate(object(ab)); (Augmented(v), st))
(v, st) = iterate(object(ab))
isone(v) && return iterate(ab, st)
return Augmented(v), st

Check warning on line 73 in src/diracs_augmented.jl

View check run for this annotation

Codecov / codecov/patch

src/diracs_augmented.jl#L73

Added line #L73 was not covered by tests
end

function Base.iterate(ab::AugmentedBasis, st)
return ((v, st) = iterate(object(ab), st); (Augmented(v), st))
(v, st) = let k = iterate(object(ab), st)
isnothing(k) && return nothing
k
end
isone(v) && return iterate(ab, st)
return Augmented(v), st
end

Base.in(g, ab::AugmentedBasis) = false
Expand Down
8 changes: 8 additions & 0 deletions test/perm_grp_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
ad = SA.AugmentedBasis(db)
@test SA.mstructure(ad) == SA.AugmentedMStructure(SA.mstructure(db))
@test ad[SA.Augmented(h)] isa SA.Augmented
@test sprint(show, ad[SA.Augmented(h)]) == "(-1·()+1·(1,2,4,5))"

@test !(h in ad)
@test SA.Augmented(h) in ad

IG = SA.StarAlgebra(G, ad)

Expand All @@ -47,6 +51,10 @@
@test coeffs(ax * ay) == SA.coeffs(x * y, basis(IG))
@test coeffs(ax * az) == SA.coeffs(x * z, basis(IG))
@test SA.aug(ax) == 0
@test star(ax) * star(ay) == star(ay) * star(ax)

@test length(ad) == length(db) - 1
@test Set(ad) == Set(SA.Augmented(g) for g in db if !isone(g))
end

@testset "Random elements" begin
Expand Down

0 comments on commit 74d8d1b

Please sign in to comment.