Skip to content

Commit

Permalink
Add integration tests for SortedHash
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrisonJ committed May 22, 2024
1 parent 7ba95aa commit 83302be
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/sorted_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1193,4 +1193,38 @@
expect(pair).to be_nil
end
end

describe "integration tests" do
it "methods done in succession should work" do
dict = SortedContainers::SortedHash.new
(0..1000).each { |i| dict[i] = i }
dict.delete_if { |key, _value| key.even? }
dict.keep_if { |key, _value| key % 3 == 0 }
dict.reject! { |key, _value| key % 5 == 0 }
dict.select! { |key, _value| key % 7 == 0 }
expect(dict.keys).to eq([21, 63, 147, 189, 231,
273, 357, 399, 441, 483,
567, 609, 651, 693, 777,
819, 861, 903, 987])
expect(dict.bisect_left(148)).to eq(3)
expect(dict.bisect_right(148)).to eq(3)
expect(dict.first).to eq([21, 21])
expect(dict.last).to eq([987, 987])
dict[147] = nil
dict.compact!
expect(dict.bisect_left(148)).to eq(2)
expect(dict.bisect_right(148)).to eq(2)
dict.delete_at(1)
expect(dict.bisect_left(148)).to eq(1)
expect(dict.bisect_right(148)).to eq(1)
expect(dict.keys).to eq([21, 189, 231,
273, 357, 399, 441, 483,
567, 609, 651, 693, 777,
819, 861, 903, 987])
expect(dict.shift).to eq([21, 21])
expect(dict.keys).to eq([189, 231, 273, 357, 399,
441, 483, 567, 609, 651,
693, 777, 819, 861, 903, 987])
end
end
end

0 comments on commit 83302be

Please sign in to comment.