<commit_before>require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)

# Describes Numeric#step shared specs between different argument styles.
# To be able to do it, the @step_args var must contain a Proc that transforms
# the step call arguments passed as positional arguments to the style of
# arguments pretended to test.
describe :numeric_step, :shared => true do
  before :each do
    ScratchPad.record []
    @prc = lambda { |x| ScratchPad << x }
  end

  it "defaults to step = 1" do
    1.send(@method, *@step_args.call(5), &@prc)
    ScratchPad.recorded.should eql [1, 2, 3, 4, 5]
  end

  describe "when self, stop and step are Fixnums" do
    it "yields only Fixnums" do
      1.send(@method, *@step_args.call(5, 1)) { |x| x.should be_an_instance_of(Fixnum) }
    end

    describe "with a positive step" do
      it "yields while increasing self by step until stop is reached" do
        1.send(@method, *@step_args.call(5, 1), &@prc)
        ScratchPad.recorded.should eql [1, 2, 3, 4, 5]
      end

      it "yields once when self equals stop" do
        1.send(@method, *@step_args.call(1, 1), &@prc)
        ScratchPad.recorded.should eql [1]
      end

      it "does not yield when self is greater than stop" do
        2.send(@method, *@step_args.call(1, 1), &@prc)
        ScratchPad.recorded.should eql []
      end
    end

    describe "with a negative step" do
      it "yields while decreasing self by step until stop is reached" do
        5.send(@method, *@step_args.call(1, -1), &@prc)
        ScratchPad.recorded.should eql [5, 4, 3, 2, 1]
      end

      it "yields once when self equals stop" do
        5.send(@method, *@step_args.call(5, -1), &@prc)
        ScratchPad.recorded.should eql [5]
      end

      it "does not yield when self is less than stop" do
        1.send(@method, *@step_args.call(5, -1), &@prc)
        ScratchPad.recorded.should == []
      end
    end
  end

  describe "when self, stop or step are a Float" do
    it "yields Floats even if only self is a Float" do
      1.5.send(@method, *@step_args.call(5, 1)) { |x| x.should be_an_instance_of(Float) }
    end

    it "yields Floats even if only stop is a Float" do
      1.send(@method, *@step_args.call(5.0, 1)) { |x| x.should be_an_instance_of(Float) }
    end

    it "yields Floats even if only step is a Float" do
      1.send(@method, *@step_args.call(5, 1.0)) { |x| x.should be_an_instance_of(Float) }
    end

    describe "with a positive step" do
      it "yields while increasing self by step while < stop" do<commit_msg>Improve test description to avoid misinterpretation.<commit_after>require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)

# Describes Numeric#step shared specs between different argument styles.
# To be able to do it, the @step_args var must contain a Proc that transforms
# the step call arguments passed as positional arguments to the style of
# arguments pretended to test.
describe :numeric_step, :shared => true do
  before :each do
    ScratchPad.record []
    @prc = lambda { |x| ScratchPad << x }
  end

  it "defaults to step = 1" do
    1.send(@method, *@step_args.call(5), &@prc)
    ScratchPad.recorded.should eql [1, 2, 3, 4, 5]
  end

  describe "when self, stop and step are Fixnums" do
    it "yields only Fixnums" do
      1.send(@method, *@step_args.call(5, 1)) { |x| x.should be_an_instance_of(Fixnum) }
    end

    describe "with a positive step" do
      it "yields while increasing self by step until stop is reached" do
        1.send(@method, *@step_args.call(5, 1), &@prc)
        ScratchPad.recorded.should eql [1, 2, 3, 4, 5]
      end

      it "yields once when self equals stop" do
        1.send(@method, *@step_args.call(1, 1), &@prc)
        ScratchPad.recorded.should eql [1]
      end

      it "does not yield when self is greater than stop" do
        2.send(@method, *@step_args.call(1, 1), &@prc)
        ScratchPad.recorded.should eql []
      end
    end

    describe "with a negative step" do
      it "yields while decreasing self by step until stop is reached" do
        5.send(@method, *@step_args.call(1, -1), &@prc)
        ScratchPad.recorded.should eql [5, 4, 3, 2, 1]
      end

      it "yields once when self equals stop" do
        5.send(@method, *@step_args.call(5, -1), &@prc)
        ScratchPad.recorded.should eql [5]
      end

      it "does not yield when self is less than stop" do
        1.send(@method, *@step_args.call(5, -1), &@prc)
        ScratchPad.recorded.should == []
      end
    end
  end

  describe "when at least one of self, stop or step is a Float" do
    it "yields Floats even if only self is a Float" do
      1.5.send(@method, *@step_args.call(5, 1)) { |x| x.should be_an_instance_of(Float) }
    end

    it "yields Floats even if only stop is a Float" do
      1.send(@method, *@step_args.call(5.0, 1)) { |x| x.should be_an_instance_of(Float) }
    end

    it "yields Floats even if only step is a Float" do
      1.send(@method, *@step_args.call(5, 1.0)) { |x| x.should be_an_instance_of(Float) }
    end

    describe "with a positive step" do
      it "yields while increasing self by step while < stop" do
{'fraction_non_alphanumeric': 0.11946232487694056, 'fraction_numerical': 0.020068156001514577, 'mean_word_length': 2.7816750178954903, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '5510092', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1792, 'n_words': 624}