Sha256: ec51bb4dc81cd0b860192cafcc71b4ab849a84a2b40d0d04aa4fae27e082a172

Contents?: true

Size: 1.57 KB

Versions: 141

Compression:

Stored size: 1.57 KB

Contents

var BigInt = require('./big-integer');


describe('The big-integer module\'s returned object', function () {
  var bigI;

  beforeEach(function () {
    bigI = BigInt(42);
  });

  afterEach(function () {
    bigI = null;
  });

  it('is not a number', function () {
    expect(typeof 42).toBe('number');
    expect(typeof bigI).not.toBe('number');
    expect(typeof bigI).toBe('object');
  });

  it('can be compared to a stringified number by calling \'.toString()\'',
    function () {
      expect(bigI).not.toBe(42);
      expect(bigI).not.toBe('42');
      expect(bigI.toString()).toBe('42');
      // NOTE:
      // The '==' operator calls '.toString()' here in order to compare.
      expect(bigI == '42').toBe(true);
    // While the line above is easier to write and read, we will use the
    // 'expect(bigI.toString()).toBe(expected)' way so that test failure
    // messages will be more informative. Eg,
    // "Expected '84' to be '42'." instead of
    // "Expected false to be true."
    });

  it('is immutable', function () {
    bigI.add(10);
    expect(bigI.toString()).toBe('42');
    bigI.subtract(10);
    expect(bigI.toString()).toBe('42');
  });

  it('can add', function () {
    bigI = bigI.add(42);

    expect(bigI.toString()).toBe('84');
  });

  it('can perform power operations', function () {
    bigI = BigInt(10);
    bigI = bigI.pow(2);
    expect(bigI.toString()).toBe('100');
  });

  // ...see the official docs for more info, if you want.
  // The "Methods" section of the README is especially useful:
  //
  // https://github.com/peterolson/BigInteger.js#methods
});

Version data entries

141 entries across 141 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.138 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.137 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.136 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.135 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.134 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.133 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.132 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.131 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.130 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.129 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.128 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.127 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.126 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.125 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.124 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.123 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.122 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.121 tracks/javascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.120 tracks/javascript/exercises/grains/big-integer.spec.js