Sha256: f8196e17dfc3290f1daf8d207d6a611d9d1168cf77737063589229bbf28f5228

Contents?: true

Size: 1.96 KB

Versions: 6

Compression:

Stored size: 1.96 KB

Contents

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

var TwitterCldr = require('../../../../lib/assets/javascripts/twitter_cldr/en.js');

describe("AbbreviatedNumberFormatter", function() {
  beforeEach(function() {
    formatter = new TwitterCldr.AbbreviatedNumberFormatter();
  });

  describe("#transform_number", function() {
    it("chops off the number to the necessary number of sig figs", function() {
      expect(formatter.transform_number(Math.pow(10, 3))).toEqual(1);
      expect(formatter.transform_number(Math.pow(10, 4))).toEqual(10);
      expect(formatter.transform_number(Math.pow(10, 5))).toEqual(100);
      expect(formatter.transform_number(Math.pow(10, 6))).toEqual(1);
      expect(formatter.transform_number(Math.pow(10, 7))).toEqual(10);
      expect(formatter.transform_number(Math.pow(10, 8))).toEqual(100);
      expect(formatter.transform_number(Math.pow(10, 9))).toEqual(1);
      expect(formatter.transform_number(Math.pow(10, 10))).toEqual(10);
      expect(formatter.transform_number(Math.pow(10, 11))).toEqual(100);
      expect(formatter.transform_number(Math.pow(10, 12))).toEqual(1);
      expect(formatter.transform_number(Math.pow(10, 13))).toEqual(10);
      expect(formatter.transform_number(Math.pow(10, 14))).toEqual(100);
    });

    it("returns the original number if greater than 10^15", function() {
      expect(formatter.transform_number(Math.pow(10, 15))).toEqual(Math.pow(10, 15));
    });

    it("returns the original number if less than 10^3", function() {
      expect(formatter.transform_number(999)).toEqual(999);
    });
  });

  describe("#get_key", function() {
    it("builds a power-of-ten key based on the number of digits in the input", function() {
      for(var i = 3; i < 15; i ++) {
        var zeroes = "";
        for(var j = 0; j < (i - 3); j ++) {
          zeroes += "0";
        }
        expect(formatter.get_key(parseInt("1337" + zeroes))).toEqual(Math.pow(10, i).toString());
      }
    });
  });
});

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
twitter_cldr_js-2.2.4 spec/js/numbers/abbreviated/abbreviated_number.spec.js
twitter_cldr_js-2.2.3 spec/js/numbers/abbreviated/abbreviated_number.spec.js
twitter_cldr_js-2.2.2 spec/js/numbers/abbreviated/abbreviated_number.spec.js
twitter_cldr_js-2.2.0 spec/js/numbers/abbreviated/abbreviated_number.spec.js
twitter_cldr_js-2.1.0 spec/js/numbers/abbreviated/abbreviated_number.spec.js
twitter_cldr_js-2.0.0 spec/js/numbers/abbreviated/abbreviated_number.spec.js