Skip to content

Commit

Permalink
add push and append to SortedArray
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrisonJ committed Apr 29, 2024
1 parent 19b33d2 commit 99ab784
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/sorted_containers/sorted_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ def add(value)
expand(pos)
end
@size += 1
self
end
alias << add
alias push add
alias append add

# rubocop:enable Metrics/MethodLength

Expand Down
5 changes: 5 additions & 0 deletions spec/sorted_array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@
expect(array.to_a).to eq((1..1000).to_a)
end

it "should return the array" do
array = SortedContainers::SortedArray.new
expect(array.add(5)).to eq(array)
end

it "a load factor of 10 should work" do
array = SortedContainers::SortedArray.new([], load_factor: 10)
(1..1000).to_a.shuffle.each do |i|
Expand Down

0 comments on commit 99ab784

Please sign in to comment.