Skip to content

Commit

Permalink
Added tests for Stateful fix JuliaLang#30643
Browse files Browse the repository at this point in the history
  • Loading branch information
denizyuret committed Jan 8, 2019
1 parent 13dcbe3 commit c0eb6c9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,26 @@ end
@test @inferred(first(z)) == (1, "a", 1.0, 1, "a", 1.0, 1, "a", 1.0)
@test @inferred(first(Iterators.drop(z, 1))) == (2, "b", 2.0, 2, "a", 1.2, 1, "c", 1.0)
end

@testset "Stateful fix #30643" begin
@test Base.IteratorSize(1:10) isa Base.HasShape
a = Iterators.Stateful(1:10)
@test Base.IteratorSize(a) isa Base.HasLength
@test length(a) == 10
@test length(collect(a)) == 10
@test length(a) == 0
b = Iterators.Stateful(Iterators.take(1:10,3))
@test Base.IteratorSize(b) isa Base.HasLength
@test length(b) == 3
@test length(collect(b)) == 3
@test length(b) == 0
c = Iterators.Stateful(Iterators.countfrom(1))
@test Base.IteratorSize(c) isa Base.IsInfinite
@test length(Iterators.take(c,3)) == 3
@test length(collect(Iterators.take(c,3))) == 3
d = Iterators.Stateful(Iterators.filter(isodd,1:10))
@test Base.IteratorSize(d) isa Base.SizeUnknown
@test length(collect(Iterators.take(d,3))) == 3
@test length(collect(d)) == 2
@test length(collect(d)) == 0
end

0 comments on commit c0eb6c9

Please sign in to comment.