From 99ab7844044680fe5f267376e9181a86157cfd36 Mon Sep 17 00:00:00 2001 From: Garrison Jensen Date: Mon, 29 Apr 2024 15:55:43 -0700 Subject: [PATCH] add push and append to SortedArray --- lib/sorted_containers/sorted_array.rb | 3 +++ spec/sorted_array_spec.rb | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lib/sorted_containers/sorted_array.rb b/lib/sorted_containers/sorted_array.rb index 3d7c46d..351f38b 100644 --- a/lib/sorted_containers/sorted_array.rb +++ b/lib/sorted_containers/sorted_array.rb @@ -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 diff --git a/spec/sorted_array_spec.rb b/spec/sorted_array_spec.rb index c5a8c06..6ba5ddb 100644 --- a/spec/sorted_array_spec.rb +++ b/spec/sorted_array_spec.rb @@ -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|