Skip to content

Commit

Permalink
Add empty? guard clause to Deque#rotate!
Browse files Browse the repository at this point in the history
  • Loading branch information
willcosgrove committed Dec 18, 2017
1 parent a1e90f0 commit 9985d87
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/std/deque_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@ describe "Deque" do
a.rotate!(8)
a.should eq(Deque{4, 1, 2, 3})
end

it "rotates with size=0" do
a = Deque(Int32).new
a.rotate!
a.should eq(Deque(Int32).new)
end
end

describe "shift" do
Expand Down
1 change: 1 addition & 0 deletions src/deque.cr
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ class Deque(T)
# * For positive *n*, equivalent to `n.times { push(shift) }`.
# * For negative *n*, equivalent to `(-n).times { unshift(pop) }`.
def rotate!(n : Int = 1)
return if empty?
if @size == @capacity
@start = (@start + n) % @capacity
else
Expand Down

0 comments on commit 9985d87

Please sign in to comment.