diff --git a/docs/src/circ_deque.md b/docs/src/circ_deque.md index d39062a33..eb9697085 100644 --- a/docs/src/circ_deque.md +++ b/docs/src/circ_deque.md @@ -9,6 +9,7 @@ Usage: ```julia a = CircularDeque{Int}(n) # allocate a deque with maximum capacity n isempty(a) # test whether the deque is empty +isfull(a) # test whether the deque is full empty!(a) # reset the deque capacity(a) # return capacity length(a) # get the number of elements currently in the deque diff --git a/src/circ_deque.jl b/src/circ_deque.jl index 3159d7d6a..4d7640415 100644 --- a/src/circ_deque.jl +++ b/src/circ_deque.jl @@ -23,6 +23,13 @@ Return the capacity of the circular deque """ capacity(D::CircularDeque) = D.capacity +""" + isfull(D::CircularDeque) + +Test whether the deque is full. +""" +isfull(D::CircularDeque) = length(D) == D.capacity + function Base.empty!(D::CircularDeque) D.n = 0 D.first = 1 diff --git a/test/test_circ_deque.jl b/test/test_circ_deque.jl index adf3ddd6d..3ff729b10 100644 --- a/test/test_circ_deque.jl +++ b/test/test_circ_deque.jl @@ -64,6 +64,14 @@ @test D[7-i] === 6 @test popfirst!(D) === i end + empty!(D) + @test isfull(D) == false + for i = 1:4 + push!(D, 1) + end + @test isfull(D) == false + push!(D, 1) + @test isfull(D) == true end @testset "pushfirst! works on an empty deque" begin