Skip to content

Commit 4b52eb1

Browse files
authored
Merge pull request #220 from jverzani/issue_219
close issue #219
2 parents f69e2d5 + b37df99 commit 4b52eb1

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ Base.rem(n::AbstractPolynomial, d::AbstractPolynomial) = divrem(n, d)[2]
545545
Comparisons =#
546546
Base.isequal(p1::P, p2::P) where {P <: AbstractPolynomial} = hash(p1) == hash(p2)
547547
Base.:(==)(p1::AbstractPolynomial, p2::AbstractPolynomial) =
548-
(p1.var == p2.var) && (coeffs(p1) == coeffs(p2))
548+
check_same_variable(p1,p2) && (coeffs(p1) == coeffs(p2))
549549
Base.:(==)(p::AbstractPolynomial, n::Number) = degree(p) <= 0 && p[0] == n
550550
Base.:(==)(n::Number, p::AbstractPolynomial) = p == n
551551

src/polynomials/ImmutablePolynomial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function isconstant(p::ImmutablePolynomial{N}) where {N}
138138
end
139139
for op in [:isequal, :(==)]
140140
@eval function Base.$op(p1::ImmutablePolynomial{N,T}, p2::ImmutablePolynomial{M,S}) where {N,T,M,S}
141-
(p1.var == p2.var) || return false
141+
check_same_variable(p1,p2) || return false
142142
p1s, p2s = coeffs(p1), coeffs(p2)
143143
(N == M && $op(p1s,p2s)) && return true
144144
n1 = findlast(!iszero, p1s) # now trim out zeros

src/polynomials/LaurentPolynomial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ end
153153
##
154154
Base.copy(p::P) where {P <: LaurentPolynomial} = P(copy(coeffs(p)), range(p), p.var)
155155
Base.:(==)(p1::LaurentPolynomial, p2::LaurentPolynomial) =
156-
(p1.var == p2.var) && (range(p1) == range(p2)) && (coeffs(p1) == coeffs(p2))
156+
check_same_variable(p1, p2) && (range(p1) == range(p2)) && (coeffs(p1) == coeffs(p2))
157157
Base.hash(p::LaurentPolynomial, h::UInt) = hash(p.var, hash(range(p), hash(coeffs(p), h)))
158158

159159
degree(p::LaurentPolynomial) = p.n[]

test/StandardBasis.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,19 @@ end
230230
@test P([0.5]) + 2 == P([2.5])
231231
@test 2 - P([0.5]) == P([1.5])
232232

233-
# check isapprox ignores variable mismatch when constants are involved, issue #217
234-
@test Polynomial(1, :x) Polynomial(1, :y)
235-
@test (variable(Polynomial, :x) variable(Polynomial, :x))
236-
@test_throws ErrorException variable(Polynomial, :x) variable(Polynomial, :y)
233+
# check how ==, ===, isapprox ignore variable mismatch when constants are involved, issue #217, issue #219
234+
@test zero(P, :x) == zero(P, :y)
235+
@test one(P, :x) == one(P, :y)
236+
@test !(variable(P, :x) == variable(P,:y))
237+
238+
@test !(zero(P, :x) === zero(P, :y))
239+
@test !(one(P, :x) === one(P, :y))
240+
@test !(variable(P, :x) === variable(P,:y))
241+
242+
@test zero(P, :x) zero(P, :y)
243+
@test one(P, :x) one(P, :y)
244+
@test (variable(P, :x) variable(P, :x))
245+
@test_throws ErrorException variable(P, :x) variable(P, :y)
237246

238247
end
239248
end

0 commit comments

Comments
 (0)