Skip to content

Commit

Permalink
Implement isone (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored Jan 28, 2025
1 parent 342ee47 commit 1fa65c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function Base.isequal(p::Polynomial{B}, q::Polynomial{B}) where {B}
return isequal(p.monomial, q.monomial)
end

Base.isone(p::Polynomial) = isone(p.monomial)

# Needed for `BoundsError`
Base.iterate(p::Polynomial) = p, nothing
Base.iterate(::Polynomial, ::Nothing) = nothing
Expand Down
3 changes: 3 additions & 0 deletions test/monomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ using DynamicPolynomials
@testset "StarAlgebras" begin
@polyvar x
a = MB.Polynomial{MB.Monomial}(x)
@test !isone(a)
b = a * a
@test b.coeffs == sparse_coefficients(x^2)
@test typeof(b.coeffs) == typeof(sparse_coefficients(x^2))
@test MB.Polynomial{MB.Monomial}(x^2) == MB.Polynomial{MB.Monomial}(x^2)
@test MB.Polynomial{MB.Monomial}(x^3) != MB.Polynomial{MB.Monomial}(x^2)
o = MB.Polynomial{MB.Monomial}(constant_monomial(x^2))
@test isone(o)
end

@testset "Linear" begin
Expand Down

0 comments on commit 1fa65c8

Please sign in to comment.