Repository: JuliaCollections/DataStructures.jl
Pull request #743 (2021-06-17 09:41:46)

Change enqueue! dequeue! to push! popfirst!
Attempt number two. I think I covered everything.


Patch:
diff --git a/docs/src/stack_and_queue.md b/docs/src/stack_and_queue.md
index aa7148b..2747cec 100644
--- a/docs/src/stack_and_queue.md
+++ b/docs/src/stack_and_queue.md
@@ -23,10 +23,10 @@ Usage of Queue:
 
 ```julia
 q = Queue{Int}()
-enqueue!(q, x)
+push!(q, x)
 x = first(q)
 x = last(q)
-x = dequeue!(q)
+x = popfirst!(q)
 ```
 
 Both `Stack` and `Queue` implement the Iterator interface; iterating
diff --git a/src/deprecations.jl b/src/deprecations.jl
index 2b33b3d..c9b1024 100644
--- a/src/deprecations.jl
+++ b/src/deprecations.jl
@@ -7,3 +7,6 @@
 Base.@deprecate_binding DisjointSets DisjointSet
 Base.@deprecate_binding IntDisjointSets IntDisjointSet
 @deprecate DisjointSets(xs...) DisjointSet(xs)
+# Enqueue and dequeue deprecations
+@deprecate enqueue!(q::Queue, x) Base.push!(q, x)
+@deprecate dequeue!(q::Queue) Base.popfirst!(q)
diff --git a/src/queue.jl b/src/queue.jl
index 7a77e2a..75605a2 100644
--- a/src/queue.jl
+++ b/src/queue.jl
@@ -20,21 +20,21 @@ Base.first(s::Queue) = first(s.store)
 Base.last(s::Queue) = last(s.store)
 
 """
-    enqueue!(s::Queue, x)
+    push!(s::Queue, x)
 
 Inserts the value `x` to the end of the queue `s`.
 """
-function enqueue!(s::Queue, x)
+function Base.push!(s::Queue, x)
     push!(s.store, x)
     return s
 end
 
 """
-    dequeue!(s::Queue)
+    popfirst!(s::Queue)
 
 Removes an element from the front of the queue `s` and returns it.
 """
-dequeue!(s::Queue) = popfirst!(s.store)
+Base.popfirst!(s::Queue) = popfirst!(s.store)
 
 Base.empty!(s::Queue) = (empty!(s.store); s)
 


Test patch:
diff --git a/test/test_deprecations.jl b/test/test_deprecations.jl
index f33cd60..ec69bc6 100644
--- a/test/test_deprecations.jl
+++ b/test/test_deprecations.jl
@@ -33,7 +33,7 @@ function test_reverse_iter(it::T) where T
 end
 @testset "reverse_iter" begin
     @testset "Queue" begin
-        q = Queue{Int}(); enqueue!(q, 1); enqueue!(q, 2)
+        q = Queue{Int}(); push!(q, 1); push!(q, 2)
         test_reverse_iter(q)
     end
     @testset "Stack" begin
@@ -41,3 +41,38 @@ end
         test_reverse_iter(s)
     end
 end
+
+@testset "enqueue! dequeue!" begin
+    s = Queue{Int}(5)
+    n = 100
+
+    @test length(s) == 0
+    @test eltype(s) == Int
+    @test eltype(typeof(s)) == Int
+    @test isempty(s)
+    @test_throws ArgumentError first(s)
+    @test_throws ArgumentError last(s)
+    @test_throws ArgumentError dequeue!(s)
+
+    for i = 1 : n
+        enqueue!(s, i)
+        @test first(s) == 1
+        @test last(s) == i
+        @test !isempty(s)
+        @test length(s) == i
+    end
+
+    for i = 1 : n
+        x = dequeue!(s)
+        @test x == i
+        if i < n
+            @test first(s) == i + 1
+            @test last(s) == n
+        else
+            @test_throws ArgumentError first(s)
+            @test_throws ArgumentError last(s)
+        end
+        @test isempty(s) == (i == n)
+        @test length(s) == n - i
+    end
+end
diff --git a/test/test_queue.jl b/test/test_queue.jl
index 3686198..6c6c4c9 100644
--- a/test/test_queue.jl
+++ b/test/test_queue.jl
@@ -18,10 +18,10 @@
         @test isempty(s)
         @test_throws ArgumentError first(s)
         @test_throws ArgumentError last(s)
-        @test_throws ArgumentError dequeue!(s)
+        @test_throws ArgumentError popfirst!(s)
 
         for i = 1 : n
-            enqueue!(s, i)
+            push!(s, i)
             @test first(s) == 1
             @test last(s) == i
             @test !isempty(s)
@@ -29,7 +29,7 @@
         end
 
         for i = 1 : n
-            x = dequeue!(s)
+            x = popfirst!(s)
             @test x == i
             if i < n
                 @test first(s) == i + 1
@@ -48,24 +48,24 @@
         s = Queue{Int}()
 
         @test s == t
-        enqueue!(s, 10)
+        push!(s, 10)
         @test s != t
-        enqueue!(t, 10)
+        push!(t, 10)
         @test s == t
-        enqueue!(t, 20)
+        push!(t, 20)
         @test s != t
 
         @testset "different types" begin
             r = Queue{Float32}()
-            enqueue!(r, 10)
+            push!(r, 10)
             @test s == r
         end
     end
 
     @testset "emptyness" begin
         s = Queue{Int}()
-        enqueue!(s, 1)
-        enqueue!(s, 3)
+        push!(s, 1)
+        push!(s, 3)
         @test !isempty(s)
         empty!(s)
         @test isempty(s)
@@ -79,7 +79,7 @@
         arr = Int64[]
 
         for i = 1:n
-            enqueue!(q,i)
+            push!(q,i)
             push!(arr,i)
         end