Skip to content

Commit

Permalink
Fix zero() error in 'missing' test (#24984)
Browse files Browse the repository at this point in the history
The 'sparse' test defined zero(::String), which triggered a failure
when it was run on before the 'missing' test on the same worker.
  • Loading branch information
nalimilan authored and ararslan committed Dec 8, 2017
1 parent 3719905 commit 1761a6e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1135,14 +1135,19 @@ end
A = sparse(["a", "b"])
@test_throws MethodError findmin(A, 1)

# Support the case, when user defined `zero` and `isless` for non-numerical type
#
Base.zero(::Type{T}) where T<:AbstractString = ""
for (tup, rval, rind) in [((1,), ["a"], [1])]
# Support the case when user defined `zero` and `isless` for non-numerical type
struct CustomType
x::String
end
Base.zero(::Type{CustomType}) = CustomType("")
Base.isless(x::CustomType, y::CustomType) = isless(x.x, y.x)
A = sparse([CustomType("a"), CustomType("b")])

for (tup, rval, rind) in [((1,), [CustomType("a")], [1])]
@test isequal(findmin(A, tup), (rval, rind))
end

for (tup, rval, rind) in [((1,), ["b"], [2])]
for (tup, rval, rind) in [((1,), [CustomType("b")], [2])]
@test isequal(findmax(A, tup), (rval, rind))
end

Expand Down

0 comments on commit 1761a6e

Please sign in to comment.