diff --git a/src/Primes.jl b/src/Primes.jl index 8676625..47e6451 100644 --- a/src/Primes.jl +++ b/src/Primes.jl @@ -362,7 +362,7 @@ julia> prodfactors(factor(100)) """ function prodfactors end -prodfactors(factors::Associative) = prod(p^i for (p, i) in factors) +prodfactors{K}(factors::Associative{K}) = isempty(factors) ? one(K) : prod(p^i for (p, i) in factors) prodfactors(factors::Union{AbstractArray, Set, IntSet}) = prod(factors) """ diff --git a/test/runtests.jl b/test/runtests.jl index e73287c..1c7e4ec 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -341,7 +341,8 @@ end end for T in (Int, UInt, BigInt) - for n in rand(T(1):T(100000), 10) + for n in [T(1); rand(T(2):T(100000), 10)] + # for n=T(1), must not error out (#51) for C = (Factorization, Vector, Dict) @test prodfactors(factor(C, n)) == n end