From eaea1600a8d662a36c97077ae56399fa38fc5695 Mon Sep 17 00:00:00 2001 From: Koustav Chowdhury Date: Sun, 31 Dec 2023 20:47:07 +0530 Subject: [PATCH] Fix problem with deque clear! --- src/deque.jl | 2 ++ test/test_deque.jl | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/deque.jl b/src/deque.jl index edd5aa94b..9d674c09d 100644 --- a/src/deque.jl +++ b/src/deque.jl @@ -38,6 +38,8 @@ isrear(blk::DequeBlock) = blk.next === blk # reset the block to empty, and position function reset!(blk::DequeBlock{T}, front::Int) where T + empty!(blk.data) + blk.data = Vector{T}(undef, blk.capa) blk.front = front blk.back = front - 1 blk.prev = blk diff --git a/test/test_deque.jl b/test/test_deque.jl index 8c35ba289..d5891fee0 100644 --- a/test/test_deque.jl +++ b/test/test_deque.jl @@ -196,5 +196,20 @@ @test length(sprint(dump,q)) >= 0 @test typeof(empty!(q)) === typeof(Deque{Int}()) @test isempty(q) + @test num_blocks(q) == 1 + @test q.head === q.rear + @test sizeof(q.head.data) == q.head.capa * sizeof(eltype(q)) + end + + @testset "push! after empty!" begin + q = Deque{Int}(1) + push!(q,1) + push!(q,2) + empty!(q) + push!(q,3) + @test length(q) == 1 + @test first(q) == 3 + @test last(q) == 3 + @test num_blocks(q) == 1 end end # @testset Deque