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

describe "BigDecimal#to_s" do

  before :each do
    @bigdec_str = "3.14159265358979323846264338327950288419716939937"
    @bigneg_str = "-3.1415926535897932384626433832795028841971693993"
    @bigdec = BigDecimal(@bigdec_str)
    @bigneg = BigDecimal(@bigneg_str)
  end

  it "return type is of class String" do
    @bigdec.to_s.kind_of?(String).should == true
    @bigneg.to_s.kind_of?(String).should == true
  end

  it "the default format looks like 0.xxxxenn" do
    @bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/
  end

  it "does not add an exponent for zero values" do
    BigDecimal("0").to_s.should == "0.0"
    BigDecimal("+0").to_s.should == "0.0"
    BigDecimal("-0").to_s.should == "-0.0"
  end

  it "takes an optional argument" do
    -> {@bigdec.to_s("F")}.should_not raise_error()
  end

  it "starts with + if + is supplied and value is positive" do
    @bigdec.to_s("+").should =~ /^\+.*/
    @bigneg.to_s("+").should_not =~ /^\+.*/
  end

  it "inserts a space every n chars, if integer n is supplied" do
    re =\
      /\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i
    @bigdec.to_s(3).should =~ re

    str1 = '-123.45678 90123 45678 9'
    BigDecimal("-123.45678901234567890").to_s('5F').should ==  str1<commit_msg>Fixed  BigDecimal#to_s 5F formatting issue.<commit_after>require_relative '../../spec_helper'
require 'bigdecimal'

describe "BigDecimal#to_s" do

  before :each do
    @bigdec_str = "3.14159265358979323846264338327950288419716939937"
    @bigneg_str = "-3.1415926535897932384626433832795028841971693993"
    @bigdec = BigDecimal(@bigdec_str)
    @bigneg = BigDecimal(@bigneg_str)
  end

  it "return type is of class String" do
    @bigdec.to_s.kind_of?(String).should == true
    @bigneg.to_s.kind_of?(String).should == true
  end

  it "the default format looks like 0.xxxxenn" do
    @bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/
  end

  it "does not add an exponent for zero values" do
    BigDecimal("0").to_s.should == "0.0"
    BigDecimal("+0").to_s.should == "0.0"
    BigDecimal("-0").to_s.should == "-0.0"
  end

  it "takes an optional argument" do
    -> {@bigdec.to_s("F")}.should_not raise_error()
  end

  it "starts with + if + is supplied and value is positive" do
    @bigdec.to_s("+").should =~ /^\+.*/
    @bigneg.to_s("+").should_not =~ /^\+.*/
  end

  it "inserts a space every n chars, if integer n is supplied" do
    re =\
      /\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i
    @bigdec.to_s(3).should =~ re

    str1 = '-123.45678 90123 45678 9'
    BigDecimal("-123.45678901234567890").to_s('5F').should ==  str1
    BigDecimal('1000010').to_s('5F').should == "10000 10.0"
{'fraction_non_alphanumeric': 0.15631768953068592, 'fraction_numerical': 0.15270758122743683, 'mean_word_length': 3.25, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3286964', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1096, 'n_words': 250}