From 82b92cb57660f1e3f2f339a105a99f08c4760ef9 Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Fri, 8 Dec 2017 19:21:43 +0100 Subject: [PATCH] Fix zero() error in 'missing' test (#24984) The 'sparse' test defined zero(::String), which triggered a failure when it was run on before the 'missing' test on the same worker. --- test/sparse/sparse.jl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index c156f4f0ca9dd8..9bb22f6626dfa0 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -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