Skip to content

Commit 577ae4b

Browse files
author
Arda Aytekin
committed
Fix bug in setindex!() - closes #48
Fixed the bug in `setindex!()` which was resulting in clearing the coefficient of the highest order term in the polynomial. Added some tests to avoid future bugs.
1 parent a6202ff commit 577ae4b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Polynomials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function setindex!(p::Poly, v, i)
196196
n = length(p.a)
197197
if n < i+1
198198
resize!(p.a,i+1)
199-
p.a[n:i] = 0
199+
p.a[n+1:i] = 0
200200
end
201201
p.a[i+1] = v
202202
v

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,10 @@ psum = p1 + p2 - p3
153153
@test truncate(Poly([2,1]),reltol=1/2,abstol=0) == Poly([2])
154154
@test truncate(Poly([2,1]),reltol=1,abstol=0) == Poly([0])
155155
@test truncate(Poly([2,1]),reltol=0,abstol=1) == Poly([2])
156+
157+
## setindex!
158+
println("Test for setindex!()")
159+
p1 = Poly([1,2,1])
160+
p1[5] = 1
161+
@test p1[5] == 1
162+
@test p1 == Poly([1,2,1,0,0,1])

0 commit comments

Comments
 (0)