<commit_before>require "spec_helper"
require "hamster/hash"

describe Hamster::Hash do
  [:remove, :reject, :delete_if].each do |method|
    describe "##{method}" do
      let(:hash) { Hamster.hash("A" => "aye", "B" => "bee", "C" => "see") }

      context "when nothing matches" do
        it "returns self" do
          hash.send(method) { |key, value| false }.should equal(hash)
        end
      end

      context "when only some things match" do
        context "with a block" do
          let(:result) { hash.send(method) { |key, value| key == "A" && value == "aye" }}

          it "preserves the original" do
            result
            hash.should eql(Hamster.hash("A" => "aye", "B" => "bee", "C" => "see"))
          end

          it "returns a set with the matching values" do
            result.should eql(Hamster.hash("B" => "bee", "C" => "see"))
          end
        end

        context "with no block" do
          it "returns an Enumerator" do
            hash.send(method).class.should be(Enumerator)
            hash.send(method).to_a.sort.should == [['A', 'aye'], ['B', 'bee'], ['C', 'see']]
            hash.send(method).each { true }.should eql(Hamster.hash)
          end
        end

        context "on a large hash, with many combinations of input" do
          array = 1000.times.collect { |n| [n, n] }
          hash  = Hamster::Hash.new(array)
          [0, 10, 100, 200, 500, 800, 900, 999, 1000].each do |threshold|
            result = hash.send(method) { |k,v| k >= threshold}
            result.size.should == threshold
            0.upto(threshold-1) { |n| result.key?(n).should == true }
            threshold.upto(1000) { |n| result.key?(n).should == false }
          end
        end
      end
    end
  end
end<commit_msg>Tweaked implementation of Hash#remove spec<commit_after>require "spec_helper"
require "hamster/hash"

describe Hamster::Hash do
  [:remove, :reject, :delete_if].each do |method|
    describe "##{method}" do
      let(:hash) { Hamster.hash("A" => "aye", "B" => "bee", "C" => "see") }

      context "when nothing matches" do
        it "returns self" do
          hash.send(method) { |key, value| false }.should equal(hash)
        end
      end

      context "when only some things match" do
        context "with a block" do
          let(:result) { hash.send(method) { |key, value| key == "A" && value == "aye" }}

          it "preserves the original" do
            result
            hash.should eql(Hamster.hash("A" => "aye", "B" => "bee", "C" => "see"))
          end

          it "returns a set with the matching values" do
            result.should eql(Hamster.hash("B" => "bee", "C" => "see"))
          end
        end

        context "with no block" do
          it "returns an Enumerator" do
            hash.send(method).class.should be(Enumerator)
            hash.send(method).to_a.sort.should == [['A', 'aye'], ['B', 'bee'], ['C', 'see']]
            hash.send(method).each { true }.should eql(Hamster.hash)
          end
        end

        context "on a large hash, with many combinations of input" do
          it "still works" do
            array = 1000.times.collect { |n| [n, n] }
            hash  = Hamster::Hash.new(array)
            [0, 10, 100, 200, 500, 800, 900, 999, 1000].each do |threshold|
              result = hash.send(method) { |k,v| k >= threshold}
              result.size.should == threshold
              0.upto(threshold-1) { |n| result.key?(n).should == true }
              threshold.upto(1000) { |n| result.key?(n).should == false }
            end
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.15263593706872758, 'fraction_numerical': 0.019321004692243997, 'mean_word_length': 1.980263157894737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6596289', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1123, 'n_words': 336}