Skip to content

Commit bef0d8a

Browse files
committed
address review comments and more tests
1 parent 03b00df commit bef0d8a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Primes.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ end
531531

532532
# add: checked add (when makes sense), result of same type as first argument
533533

534-
add(n::BigInt, x::Int) = n+x
534+
add(n::BigInt, x::Int) = n + x
535535
add(n::Integer, x::Int) = Base.checked_add(n, oftype(n, x))
536536

537537
# add_! : "may" mutate the Integer argument (only for BigInt currently)
@@ -723,13 +723,14 @@ struct PrevPrimes{T<:Integer}
723723
start::T
724724
end
725725

726-
iterate(np::PrevPrimes, state=np.start) =
726+
function iterate(np::PrevPrimes, state=np.start)
727727
if isone(state)
728728
nothing
729729
else
730730
p = prevprime(state)
731731
(p, p-one(p))
732732
end
733+
end
733734

734735
IteratorSize(::Type{<:PrevPrimes}) = Base.SizeUnknown()
735736
IteratorEltype(::Type{<:PrevPrimes}) = Base.HasEltype()

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ end
407407
@test nextprimes(4, 1)[1] == nextprimes(5, 1)[1] == 5
408408
@test eltype(nextprimes(10)) == Int
409409
@test eltype(nextprimes(big(10))) == BigInt
410+
@test Base.IteratorEltype(nextprimes(10)) == Base.HasEltype()
411+
@test Base.IteratorSize(nextprimes(10)) == Base.IsInfinite()
412+
410413
end
411414

412415

@@ -419,6 +422,7 @@ end
419422
@test prevprimes(6, 1)[1] == prevprimes(5, 1)[1] == 5
420423
@test prevprimes(4, 1)[1] == prevprimes(3, 1)[1] == 3
421424
@test prevprimes(2, 1)[1] == 2
425+
@test isempty(prevprimes(1, 1))
422426
let p8 = collect(prevprimes(typemax(Int8)))
423427
@test length(p8) == 31
424428
@test p8[end] == 2
@@ -427,4 +431,6 @@ end
427431
end
428432
@test eltype(prevprimes(10)) == Int
429433
@test eltype(prevprimes(big(10))) == BigInt
434+
@test Base.IteratorEltype(prevprimes(10)) == Base.HasEltype()
435+
@test Base.IteratorSize(prevprimes(10)) == Base.SizeUnknown()
430436
end

0 commit comments

Comments
 (0)