Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for pair printing & sparsevec #13943

Merged
merged 2 commits into from
Nov 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ function f13127()
end
@test f13127() == "f"

let a = Pair(1.0,2.0)
@test sprint(show,a) == "1.0=>2.0"
end
let a = Pair(Pair(1,2),Pair(3,4))
@test sprint(show,a) == "(1=>2)=>(3=>4)"
end

#test methodshow.jl functions
@test Base.inbase(Base)
@test Base.inbase(LinAlg)
Expand Down
9 changes: 9 additions & 0 deletions test/sparsedir/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,27 @@ let x = spv_x1
end

let a = SparseVector(8, [2, 5, 6], Int32[12, 35, 72])
# vec
@test vec(a) == a

# reinterpret
au = reinterpret(UInt32, a)
@test isa(au, SparseVector{UInt32,Int})
@test exact_equal(au, SparseVector(8, [2, 5, 6], UInt32[12, 35, 72]))

# float
af = float(a)
@test float(af) == af
@test isa(af, SparseVector{Float64,Int})
@test exact_equal(af, SparseVector(8, [2, 5, 6], [12., 35., 72.]))
@test sparsevec(transpose(transpose(af))) == af

# complex
acp = complex(af)
@test complex(acp) == acp
@test isa(acp, SparseVector{Complex128,Int})
@test exact_equal(acp, SparseVector(8, [2, 5, 6], complex([12., 35., 72.])))
@test sparsevec(ctranspose(ctranspose(acp))) == acp
end

### Type conversion
Expand Down Expand Up @@ -574,7 +581,9 @@ let x = sprand(16, 0.5), x2 = sprand(16, 0.4)
# scale
let sx = SparseVector(x.n, x.nzind, x.nzval * 2.5)
@test exact_equal(scale(x, 2.5), sx)
@test exact_equal(scale(x, 2.5 + 0.0*im), complex(sx))
@test exact_equal(scale(2.5, x), sx)
@test exact_equal(scale(2.5 + 0.0*im, x), complex(sx))
@test exact_equal(x * 2.5, sx)
@test exact_equal(2.5 * x, sx)
@test exact_equal(x .* 2.5, sx)
Expand Down