<commit_before>require_relative '../../spec_helper'
require 'bigdecimal'

describe "BigDecimal" do
  it "is not defined unless it is required" do
    ruby_exe('puts Object.const_defined?(:BigDecimal)').should == "false\n"
  end
end

describe "Kernel#BigDecimal" do

  it "creates a new object of class BigDecimal" do
    BigDecimal("3.14159").should be_kind_of(BigDecimal)
    (0..9).each {|i|
      BigDecimal("1#{i}").should == 10 + i
      BigDecimal("-1#{i}").should == -10 - i
      BigDecimal("1E#{i}").should == 10**i
      BigDecimal("1000000E-#{i}").should == 10**(6-i).to_f
      # ^ to_f to avoid Rational type
    }
    (1..9).each {|i|
      BigDecimal("100.#{i}").to_s.should =~ /\A0\.100#{i}E3\z/i
      BigDecimal("-100.#{i}").to_s.should =~ /\A-0\.100#{i}E3\z/i
    }
  end

  it "accepts significant digits >= given precision" do
    BigDecimal("3.1415923", 10).precs[1].should >= 10
  end

  it "determines precision from initial value" do
    pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
    BigDecimal(pi_string).precs[1].should >= pi_string.size-1
  end

  it "ignores leading whitespace" do
    BigDecimal("  \t\n \r1234").should == BigDecimal("1234")<commit_msg>Test BigDecimal parsing for trailing whitespaces<commit_after>require_relative '../../spec_helper'
require 'bigdecimal'

describe "BigDecimal" do
  it "is not defined unless it is required" do
    ruby_exe('puts Object.const_defined?(:BigDecimal)').should == "false\n"
  end
end

describe "Kernel#BigDecimal" do

  it "creates a new object of class BigDecimal" do
    BigDecimal("3.14159").should be_kind_of(BigDecimal)
    (0..9).each {|i|
      BigDecimal("1#{i}").should == 10 + i
      BigDecimal("-1#{i}").should == -10 - i
      BigDecimal("1E#{i}").should == 10**i
      BigDecimal("1000000E-#{i}").should == 10**(6-i).to_f
      # ^ to_f to avoid Rational type
    }
    (1..9).each {|i|
      BigDecimal("100.#{i}").to_s.should =~ /\A0\.100#{i}E3\z/i
      BigDecimal("-100.#{i}").to_s.should =~ /\A-0\.100#{i}E3\z/i
    }
  end

  it "accepts significant digits >= given precision" do
    BigDecimal("3.1415923", 10).precs[1].should >= 10
  end

  it "determines precision from initial value" do
    pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
    BigDecimal(pi_string).precs[1].should >= pi_string.size-1
  end

  it "ignores leading and trailing whitespace" do
    BigDecimal("  \t\n \r1234\t\r\n ").should == BigDecimal("1234")
{'fraction_non_alphanumeric': 0.14910116320056396, 'fraction_numerical': 0.21290095170955234, 'mean_word_length': 4.067857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?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': '113931', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1074, 'n_words': 189}