Skip to content

Commit bf52394

Browse files
authored
Add tests for negative degree (#271)
* Add tests for negative degree * Fix format
1 parent 06c924a commit bf52394

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/monomial_vector.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ end
6666
Returns the return type of `monomial_vector`.
6767
"""
6868
function monomial_vector_type(
69-
X::Union{AbstractVector{PT},Type{<:AbstractVector{PT}}},
69+
::Union{AbstractVector{PT},Type{<:AbstractVector{PT}}},
7070
) where {PT<:_APL}
7171
return monomial_vector_type(PT)
7272
end
@@ -109,3 +109,13 @@ Returns the vector of monomials in the entries of `X` in increasing order and wi
109109
Calling `merge_monomial_vectors` on ``[[xy, x, xy], [x^2y, x]]`` should return ``[x^2y, xy, x]``.
110110
"""
111111
merge_monomial_vectors(X) = monomial_vector(reduce(vcat, X))
112+
113+
function error_for_negative_degree(deg)
114+
if deg < 0
115+
throw(
116+
ArgumentError(
117+
"The degree should be a nonnegative number but the provided degree `$deg` is negative.",
118+
),
119+
)
120+
end
121+
end

test/monomial_vector.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,11 @@
100100
v[1]^3,
101101
]
102102
end
103+
104+
@testset "Negative degree" begin
105+
Mod.@polyvar x[1:3]
106+
@test_throws ArgumentError monomials(x, -1)
107+
@test_throws ArgumentError monomials(x, -1:1)
108+
@test_throws ArgumentError monomials(x, [1, -1])
109+
end
103110
end

test/ncmonomial.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
end
3838
end
3939
@testset "Non-commutative MonomialVector" begin
40-
Mod.@ncpolyvar x y
40+
v = Mod.@ncpolyvar x y
41+
@test_throws ArgumentError monomials(v, -1)
42+
@test_throws ArgumentError monomials(v, -1:1)
43+
@test_throws ArgumentError monomials(v, [1, -1])
4144
X = empty_monomial_vector(typeof(x))
4245
@test iszero(nvariables(X))
4346
@test isempty(variables(X))

0 commit comments

Comments
 (0)