Sha256: 336a49264195edbb5e5ba66967bc97479da151ded0c33ce8cbc474e7dcb15347

Contents?: true

Size: 1.51 KB

Versions: 188

Compression:

Stored size: 1.51 KB

Contents

import BigInt from './big-integer';

describe('The big-integer module\'s returned object', () => {
  let bigI;

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

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

  test('is not a number', () => {
    expect(typeof 42).toBe('number');
    expect(typeof bigI).not.toBe('number');
    expect(typeof bigI).toBe('object');
  });

  test('can be compared to a stringified number by calling \'.toString()\'', () => {
    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."
  });

  test('is immutable', () => {
    bigI.add(10);
    expect(bigI.toString()).toBe('42');
    bigI.subtract(10);
    expect(bigI.toString()).toBe('42');
  });

  test('can add', () => {
    bigI = bigI.add(42);

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

  test('can perform power operations', () => {
    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

188 entries across 188 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.179 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.178 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.177 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.176 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.175 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.174 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.173 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.172 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.171 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.170 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.169 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.167 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.166 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.165 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.164 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.163 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.162 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.161 tracks/ecmascript/exercises/grains/big-integer.spec.js
trackler-2.2.1.160 tracks/ecmascript/exercises/grains/big-integer.spec.js