Skip to content

Commit 35c2af1

Browse files
authored
Implement equality between ExponentsIterator (#344)
1 parent c9f99bc commit 35c2af1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/comparison.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,13 @@ function Base.IteratorSize(::Type{<:ExponentsIterator{M,Int}}) where {M}
481481
return Base.HasLength()
482482
end
483483

484+
function Base.:(==)(a::ExponentsIterator, b::ExponentsIterator)
485+
return typeof(a.object) == typeof(b.object) &&
486+
length(a.object) == length(b.object) &&
487+
a.mindegree == b.mindegree &&
488+
a.maxdegree == b.maxdegree
489+
end
490+
484491
function _length(it::ExponentsIterator, maxdegree)
485492
if maxdegree < it.mindegree
486493
return 0

test/comparison.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ function _test(nvars::Int, M; kws...)
1717
return
1818
end
1919

20+
function test_equal()
21+
exp = ExponentsIterator{LexOrder}([0])
22+
@test exp == ExponentsIterator{LexOrder}([0])
23+
@test exp != ExponentsIterator{LexOrder}((0,))
24+
@test exp != ExponentsIterator{LexOrder}([0, 0])
25+
@test exp != ExponentsIterator{LexOrder}([0], mindegree = 1)
26+
@test exp != ExponentsIterator{LexOrder}([0], maxdegree = 2)
27+
end
28+
2029
function test_errors()
2130
err = ArgumentError(
2231
"The `mindegree` of `ExponentsIterator` cannot be negative.",

0 commit comments

Comments
 (0)