Skip to content

Commit 2267021

Browse files
authored
fix prodfactor(factor(1)) (was an error) (#51)
1 parent ef3a171 commit 2267021

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Primes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ julia> prodfactors(factor(100))
362362
"""
363363
function prodfactors end
364364

365-
prodfactors(factors::Associative) = prod(p^i for (p, i) in factors)
365+
prodfactors{K}(factors::Associative{K}) = isempty(factors) ? one(K) : prod(p^i for (p, i) in factors)
366366
prodfactors(factors::Union{AbstractArray, Set, IntSet}) = prod(factors)
367367

368368
"""

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ end
372372
end
373373

374374
for T in (Int, UInt, BigInt)
375-
for n in rand(T(1):T(100000), 10)
375+
for n in [T(1); rand(T(2):T(100000), 10)]
376+
# for n=T(1), must not error out (#51)
376377
for C = (Factorization, Vector, Dict)
377378
@test prodfactors(factor(C, n)) == n
378379
end

0 commit comments

Comments
 (0)