Sha256: 8eb5addcd33bb832d910af0a9c19915966c0d5f938abf64ab589cd34df6c1304

Contents?: true

Size: 1.07 KB

Versions: 17

Compression:

Stored size: 1.07 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

require 'spec_helper'

include TwitterCldr::Formatters
include TwitterCldr::Tokenizers

describe AbbreviatedNumberFormatter do
  let(:formatter) { AbbreviatedNumberFormatter.new(locale: :en) }
  let(:number) { 123456 }

  describe "#truncate_number" do
    let(:number) { 1234 }

    def truncate(number, decimal_digits)
      formatter.send(:truncate_number, number, decimal_digits)
    end

    it "truncates the number based on number of decimal digits requested" do
      expect(truncate(number, 1)).to eq(1.234)
      expect(truncate(number, 2)).to eq(12.34)
      expect(truncate(number, 3)).to eq(123.4)
      expect(truncate(number, 4)).to eq(1234)
      expect(truncate(number, 5)).to eq(1234)
      expect(truncate(number, 6)).to eq(1234)
    end

    it "returns the original number if less than 10^3" do
      expect(truncate(999, 3)).to eq(999)
    end

    it "returns the original number if greater than 10^15" do
      expect(truncate(10 ** 15, 3)).to eq(10 ** 15)
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.4.5 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.4.4 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.4.3 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.4.2 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.4.1 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.4.0 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.3.1 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.3.0 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.2.0 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.1.0 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-4.0.0 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-3.6.0 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-3.5.0 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-3.4.0 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb
twitter_cldr-3.3.0 spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb