Skip to content

Commit 6875015

Browse files
committed
Add tests
1 parent 0567d8c commit 6875015

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/poly.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ polynomial(p::AbstractPolynomial) = p
6666
polynomial(p::APL{T}, ::Type{T}) where T = polynomial(terms(p))
6767
polynomial(p::APL{T}) where T = polynomial(p, T)
6868
polynomial(ts::AbstractVector, s::ListState=MessyState()) = sum(ts)
69-
polynomial(ts::AbstractVector{<:AbstractTerm}, s::ListState=MessyState()) = polynomial(coefficient.(ts), monomial.(ts), s)
69+
polynomial(ts::AbstractVector{<:AbstractTerm}, s::SortedUniqState) = polynomial(coefficient.(ts), monomial.(ts), s)
7070
polynomial(a::AbstractVector, x::AbstractVector, s::ListState=MessyState()) = polynomial([α * m for (α, m) in zip(a, x)], s)
7171
polynomial(f::Function, mv::AbstractVector{<:AbstractMonomialLike}) = polynomial([f(i) * mv[i] for i in 1:length(mv)])
7272
function polynomial(Q::AbstractMatrix, mv::AbstractVector)
@@ -100,7 +100,7 @@ function uniqterms(ts::AbstractVector{T}) where T <: AbstractTerm
100100
result
101101
end
102102
polynomial(ts::AbstractVector{<:AbstractTerm}, s::SortedState) = polynomial(uniqterms(ts), SortedUniqState())
103-
polynomial(ts::AbstractVector{<:AbstractTerm}, s::UnsortedState) = polynomial(sort(ts, lt=(>)), sortstate(s))
103+
polynomial(ts::AbstractVector{<:AbstractTerm}, s::UnsortedState=MessyState()) = polynomial(sort(ts, lt=(>)), sortstate(s))
104104

105105
"""
106106
terms(p::AbstractPolynomialLike)

test/poly.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
Mod.@polyvar x
3232

3333
@test terms(polynomial([1, x^2, x, 2x^2])) == [3x^2, x, 1]
34+
@test terms(polynomial([x, 3x^4, 2], MP.UniqState())) == [3x^4, x, 2]
3435
@test terms(polynomial([x^3, 2x^3, x^2, -2x^2, x^2, x, 2, -2], MP.SortedState())) == [3x^3, x]
3536

3637
@test polynomial(1 + x) == 1 + x
@@ -87,6 +88,9 @@
8788
@test removemonomials(4x^2*y + x*y + 2x, [x*y]) == 4x^2*y + 2x
8889

8990
@test_throws InexactError push!([1], x+1)
91+
92+
@test polynomial([1 2; 3 4], [x^2, y]) == x^4 + 5x^2*y + 4y^2
93+
@test polynomial([1 2; 3 4], [x^2, y], Float64) isa AbstractPolynomial{Float64}
9094
end
9195
@testset "Graded Lex Order" begin
9296
Mod.@polyvar x y z

0 commit comments

Comments
 (0)