Skip to content

Commit

Permalink
Add tests for negative degree (#271)
Browse files Browse the repository at this point in the history
* Add tests for negative degree

* Fix format
  • Loading branch information
blegat authored Jul 12, 2023
1 parent 06c924a commit bf52394
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/monomial_vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end
Returns the return type of `monomial_vector`.
"""
function monomial_vector_type(
X::Union{AbstractVector{PT},Type{<:AbstractVector{PT}}},
::Union{AbstractVector{PT},Type{<:AbstractVector{PT}}},
) where {PT<:_APL}
return monomial_vector_type(PT)
end
Expand Down Expand Up @@ -109,3 +109,13 @@ Returns the vector of monomials in the entries of `X` in increasing order and wi
Calling `merge_monomial_vectors` on ``[[xy, x, xy], [x^2y, x]]`` should return ``[x^2y, xy, x]``.
"""
merge_monomial_vectors(X) = monomial_vector(reduce(vcat, X))

function error_for_negative_degree(deg)
if deg < 0
throw(
ArgumentError(
"The degree should be a nonnegative number but the provided degree `$deg` is negative.",
),
)
end
end
7 changes: 7 additions & 0 deletions test/monomial_vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,11 @@
v[1]^3,
]
end

@testset "Negative degree" begin
Mod.@polyvar x[1:3]
@test_throws ArgumentError monomials(x, -1)
@test_throws ArgumentError monomials(x, -1:1)
@test_throws ArgumentError monomials(x, [1, -1])
end
end
5 changes: 4 additions & 1 deletion test/ncmonomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
end
end
@testset "Non-commutative MonomialVector" begin
Mod.@ncpolyvar x y
v = Mod.@ncpolyvar x y
@test_throws ArgumentError monomials(v, -1)
@test_throws ArgumentError monomials(v, -1:1)
@test_throws ArgumentError monomials(v, [1, -1])
X = empty_monomial_vector(typeof(x))
@test iszero(nvariables(X))
@test isempty(variables(X))
Expand Down

0 comments on commit bf52394

Please sign in to comment.