Skip to content

Commit c2eeace

Browse files
kshyattararslan
authored andcommitted
A few more tests and Compat stuff for 0.7 (#133)
* A few more tests and Compat stuff for 0.7 * Use !iszero
1 parent d53401c commit c2eeace

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

REQUIRE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
julia 0.6
2-
Compat 0.39.0
2+
Compat 0.48.0

src/Polynomials.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ export polyval, polyint, polyder, roots, polyfit
1313
export Pade, padeval
1414

1515
import Base: start, next, done, length, size, eltype, collect, eachindex
16-
import Base: endof, getindex, setindex!, copy, zero, one, convert, norm, gcd
16+
import Base: endof, getindex, setindex!, copy, zero, one, convert, gcd
1717
import Base: show, print, *, /, //, -, +, ==, isapprox, divrem, div, rem, eltype
18-
import Base: promote_rule, truncate, chop, conj, transpose, dot, hash
18+
import Base: promote_rule, truncate, chop, conj, transpose, hash
1919
import Base: isequal
20+
import Compat.LinearAlgebra: norm, dot, eigvals, diagm, vecnorm, qrfact
2021

2122
const SymbolLike = Union{AbstractString,Char,Symbol}
2223

@@ -79,7 +80,8 @@ struct Poly{T}
7980
return new{T}(zeros(T,1),Symbol(var))
8081
else
8182
# determine the last nonzero element and truncate a accordingly
82-
a_last = max(1,findlast(x->x!=zero(T), a))
83+
last_nz = findlast(!iszero, a)
84+
a_last = max(1, last_nz === nothing ? 0 : last_nz)
8385
new{T}(a[1:a_last], Symbol(var))
8486
end
8587
end

test/runtests.jl

+9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# assert file to test polynomial implementation
22
using Compat
33
using Compat.Test
4+
using Compat.LinearAlgebra
45
using Polynomials
56

7+
import Compat.SparseArrays: sparse, speye, nnz
8+
69
pNULL = Poly(Float32[])
710
p0 = Poly([0])
811
p1 = Poly([1,0,0,0,0,0,0,0,0,0,0,0,0,0])
@@ -27,6 +30,8 @@ p1000 = Poly(randn(1000))
2730
sprint(show, p1000)
2831
sprint(show, pNULL)
2932

33+
@test Poly([1, -2, 1]) == poly(diagm(0=>[1., 1.]))
34+
3035
@test p3 == Poly([1,2,1])
3136
@test pN*10 == Poly([2760, 30, 870, 150, 240])
3237
@test pN/10 == Poly([27.6, 0.3, 8.7, 1.5, 2.4])
@@ -164,6 +169,8 @@ psum = p1 + p2 - p3
164169
@test truncate(Poly([2,1]),reltol=1,abstol=0) == Poly([0])
165170
@test truncate(Poly([2,1]),reltol=0,abstol=1) == Poly([2])
166171

172+
@test norm(Poly([1., 2.])) == norm([1., 2.])
173+
@test norm(Poly([1., 2.]), 1) == norm([1., 2.], 1)
167174

168175
## setindex!
169176
println("Test for setindex!()")
@@ -205,6 +212,8 @@ as = [im, 1, 2]
205212
bs = [1, 1, 2]
206213
@test conj(Poly(as)) == Poly(conj(as))
207214
@test conj(Poly(bs)) == Poly(conj(bs))
215+
## and transpose
216+
@test transpose(Poly(as)) == Poly(as)
208217

209218
## unnecessary copy in convert #65
210219
p1 = Poly([1,2])

0 commit comments

Comments
 (0)