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

describe Hamster::Set do
  [
    [:sort, ->(left, right) { left.length <=> right.length }],
    [:sort_by, ->(item) { item.length }],
  ].each do |method, comparator|

    describe "##{method}" do
      [
        [[], []],
        [["A"], ["A"]],
        [%w[Ichi Ni San], %w[Ni San Ichi]],
      ].each do |values, expected|

        describe "on #{values.inspect}" do
          before do
            @original = Hamster.set(*values)
          end

          describe "with a block" do
            before do
              @result = @original.send(method, &comparator)
            end

            it "returns #{expected.inspect}" do
              @result.should eql(Hamster.sorted_set(*expected, &comparator))
              @result.to_a.should == expected
            end
          end

          describe "without a block" do
            before do
              @result = @original.send(method)
            end

            it "returns #{expected.sort.inspect}" do
              @result.should eql(Hamster.sorted_set(*expected))
              @result.to_a.should == expected.sort
            end
          end
        end
      end
    end
  end
end<commit_msg>Updated style of Set#sort spec<commit_after>require "spec_helper"
require "hamster/set"

describe Hamster::Set do
  [
    [:sort, ->(left, right) { left.length <=> right.length }],
    [:sort_by, ->(item) { item.length }],
  ].each do |method, comparator|
    describe "##{method}" do
      [
        [[], []],
        [["A"], ["A"]],
        [%w[Ichi Ni San], %w[Ni San Ichi]],
      ].each do |values, expected|
        describe "on #{values.inspect}" do
          let(:set) { Hamster.set(*values) }

          describe "with a block" do
            let(:result) { set.send(method, &comparator) }

            it "returns #{expected.inspect}" do
              result.should eql(Hamster.sorted_set(*expected, &comparator))
              result.to_a.should == expected
            end
          end

          describe "without a block" do
            let(:result) { set.send(method) }

            it "returns #{expected.sort.inspect}" do
              result.should eql(Hamster.sorted_set(*expected))
              result.to_a.should == expected.sort
            end
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1373134328358209, 'fraction_numerical': 0.0, 'mean_word_length': 1.743859649122807, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1196009', 'n_tokens_mistral': 713, 'n_tokens_neox': 692, 'n_words': 174}