<commit_before>require 'spec_helper'

describe PulseMeter::Utils do
  class Dummy
    include PulseMeter::Utils
  end

  let(:dummy){ Dummy.new }

  describe '#constantize' do
    context "when argument is a string with a valid class name" do
      it "should return class" do
        dummy.constantize("PulseMeter::Utils").should == PulseMeter::Utils
      end
    end
    context "when argument is a string with invalid class name" do
      it "should return nil" do
        dummy.constantize("Pumpkin::Eater").should be_nil
      end
    end
    context "when argument is not a string" do
      it "should return nil" do
        dummy.constantize({}).should be_nil
      end
    end
  end

  describe "#assert_positive_integer!" do
    it "should extract integer value from hash by passed key" do
      dummy.assert_positive_integer!({:val => 4}, :val).should == 4
    end

    context "when the value by the passed key is not integer" do
      it "should convert non-integers to integers" do
        dummy.assert_positive_integer!({:val => 4.4}, :val).should == 4
      end

      it "should change the original value to the obtained integer" do
        h = {:val => 4.4}
        dummy.assert_positive_integer!(h, :val).should == 4
        h[:val].should == 4
      end

      it "should raise exception if the original value cannot be converted to integer"do
        expect{ dummy.assert_positive_integer!({:val => :bad_int}, :val) }.to raise_exception(ArgumentError)
      end
    end

    it "should raise exception if the value is not positive" do
      expect{ dummy.assert_positive_integer!({:val => -1}, :val) }.to raise_exception(ArgumentError)
    end

    it "should raise exception if the value is not defined" do
      expect{ dummy.assert_positive_integer!({}, :val) }.to raise_exception(ArgumentError)
    end
  end

  describe "#assert_ranged_float!" do
    let(:epsilon) {0.001}

    it "should extract float value from hash by passed key" do
      dummy.assert_ranged_float!({:val => 4}, :val, 0, 100).should be_within(epsilon).of(4)
    end

    context "when the value by the passed key is not float" do
      it "should convert non-floats to floats" do
        dummy.assert_ranged_float!({:val => "4.0000"}, :val, 0, 100).should be_within(epsilon).of(4)
      end

      it "should change the original value to the obtained float" do
        h = {:val => "4.000"}
        dummy.assert_ranged_float!(h, :val, 0, 100).should be_within(epsilon).of(4)
        h[:val].should be_within(epsilon).of(4)
      end

      it "should raise exception if the original value cannot be converted to float" do
        expect{ dummy.assert_ranged_float!({:val => :bad_float}, :val, 0, 100) }.to raise_exception(ArgumentError)
      end
    end

    it "should raise exception if the value is not within range" do
      expect{ dummy.assert_ranged_float!({:val => -0.1}, :val, 0, 100) }.to raise_exception(ArgumentError)
      expect{ dummy.assert_ranged_float!({:val => 100.1}, :val, 0, 100) }.to raise_exception(ArgumentError)
    end

    it "should raise exception if the value is not defined" do
      expect{ dummy.assert_ranged_float!({}, :val) }.to raise_exception(ArgumentError)
    end
  end

  describe "#uniqid" do
    it "should return uniq strings" do
      uid1, uid2 = dummy.uniqid, dummy.uniqid
      uid1.should_not == uid2
    end
  end
end
<commit_msg>a little improvement to uniqid spec<commit_after>require 'spec_helper'

describe PulseMeter::Utils do
  class Dummy
    include PulseMeter::Utils
  end

  let(:dummy){ Dummy.new }

  describe '#constantize' do
    context "when argument is a string with a valid class name" do
      it "should return class" do
        dummy.constantize("PulseMeter::Utils").should == PulseMeter::Utils
      end
    end
    context "when argument is a string with invalid class name" do
      it "should return nil" do
        dummy.constantize("Pumpkin::Eater").should be_nil
      end
    end
    context "when argument is not a string" do
      it "should return nil" do
        dummy.constantize({}).should be_nil
      end
    end
  end

  describe "#assert_positive_integer!" do
    it "should extract integer value from hash by passed key" do
      dummy.assert_positive_integer!({:val => 4}, :val).should == 4
    end

    context "when the value by the passed key is not integer" do
      it "should convert non-integers to integers" do
        dummy.assert_positive_integer!({:val => 4.4}, :val).should == 4
      end

      it "should change the original value to the obtained integer" do
        h = {:val => 4.4}
        dummy.assert_positive_integer!(h, :val).should == 4
        h[:val].should == 4
      end

      it "should raise exception if the original value cannot be converted to integer"do
        expect{ dummy.assert_positive_integer!({:val => :bad_int}, :val) }.to raise_exception(ArgumentError)
      end
    end

    it "should raise exception if the value is not positive" do
      expect{ dummy.assert_positive_integer!({:val => -1}, :val) }.to raise_exception(ArgumentError)
    end

    it "should raise exception if the value is not defined" do
      expect{ dummy.assert_positive_integer!({}, :val) }.to raise_exception(ArgumentError)
    end
  end

  describe "#assert_ranged_float!" do
    let(:epsilon) {0.001}

    it "should extract float value from hash by passed key" do
      dummy.assert_ranged_float!({:val => 4}, :val, 0, 100).should be_within(epsilon).of(4)
    end

    context "when the value by the passed key is not float" do
      it "should convert non-floats to floats" do
        dummy.assert_ranged_float!({:val => "4.0000"}, :val, 0, 100).should be_within(epsilon).of(4)
      end

      it "should change the original value to the obtained float" do
        h = {:val => "4.000"}
        dummy.assert_ranged_float!(h, :val, 0, 100).should be_within(epsilon).of(4)
        h[:val].should be_within(epsilon).of(4)
      end

      it "should raise exception if the original value cannot be converted to float" do
        expect{ dummy.assert_ranged_float!({:val => :bad_float}, :val, 0, 100) }.to raise_exception(ArgumentError)
      end
    end

    it "should raise exception if the value is not within range" do
      expect{ dummy.assert_ranged_float!({:val => -0.1}, :val, 0, 100) }.to raise_exception(ArgumentError)
      expect{ dummy.assert_ranged_float!({:val => 100.1}, :val, 0, 100) }.to raise_exception(ArgumentError)
    end

    it "should raise exception if the value is not defined" do
      expect{ dummy.assert_ranged_float!({}, :val) }.to raise_exception(ArgumentError)
    end
  end

  describe "#uniqid" do
    it "should return uniq strings" do
      uniq_values = (1..1000).map{|_| dummy.uniqid}
      uniq_values.uniq.count.should == uniq_values.count
    end
  end
end

{'fraction_non_alphanumeric': 0.1055335388228387, 'fraction_numerical': 0.018347277264054013, 'mean_word_length': 3.0463182897862233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '4987016', 'n_tokens_mistral': 2204, 'n_tokens_neox': 2049, 'n_words': 716}