Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Aug 12, 2017
1 parent 0567d8c commit 6875015
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ polynomial(p::AbstractPolynomial) = p
polynomial(p::APL{T}, ::Type{T}) where T = polynomial(terms(p))
polynomial(p::APL{T}) where T = polynomial(p, T)
polynomial(ts::AbstractVector, s::ListState=MessyState()) = sum(ts)
polynomial(ts::AbstractVector{<:AbstractTerm}, s::ListState=MessyState()) = polynomial(coefficient.(ts), monomial.(ts), s)
polynomial(ts::AbstractVector{<:AbstractTerm}, s::SortedUniqState) = polynomial(coefficient.(ts), monomial.(ts), s)
polynomial(a::AbstractVector, x::AbstractVector, s::ListState=MessyState()) = polynomial([α * m for (α, m) in zip(a, x)], s)
polynomial(f::Function, mv::AbstractVector{<:AbstractMonomialLike}) = polynomial([f(i) * mv[i] for i in 1:length(mv)])
function polynomial(Q::AbstractMatrix, mv::AbstractVector)
Expand Down Expand Up @@ -100,7 +100,7 @@ function uniqterms(ts::AbstractVector{T}) where T <: AbstractTerm
result
end
polynomial(ts::AbstractVector{<:AbstractTerm}, s::SortedState) = polynomial(uniqterms(ts), SortedUniqState())
polynomial(ts::AbstractVector{<:AbstractTerm}, s::UnsortedState) = polynomial(sort(ts, lt=(>)), sortstate(s))
polynomial(ts::AbstractVector{<:AbstractTerm}, s::UnsortedState=MessyState()) = polynomial(sort(ts, lt=(>)), sortstate(s))

"""
terms(p::AbstractPolynomialLike)
Expand Down
4 changes: 4 additions & 0 deletions test/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
Mod.@polyvar x

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

@test polynomial(1 + x) == 1 + x
Expand Down Expand Up @@ -87,6 +88,9 @@
@test removemonomials(4x^2*y + x*y + 2x, [x*y]) == 4x^2*y + 2x

@test_throws InexactError push!([1], x+1)

@test polynomial([1 2; 3 4], [x^2, y]) == x^4 + 5x^2*y + 4y^2
@test polynomial([1 2; 3 4], [x^2, y], Float64) isa AbstractPolynomial{Float64}
end
@testset "Graded Lex Order" begin
Mod.@polyvar x y z
Expand Down

0 comments on commit 6875015

Please sign in to comment.