Sha256: 4b0afbc27d85460176ba57f620b172f1e4b730e8cc79cd830fa5371af9d7931a

Contents?: true

Size: 1.99 KB

Versions: 208

Compression:

Stored size: 1.99 KB

Contents

/**
 * In JavaScript, integers beyond +/- 9007199254740991 cannot be accurately
 * represented. To see this in action, console.log() out the expected number
 * of grains on square #64:
 *
 * console.log(9223372036854775808);
 * // =>       9223372036854776000
 * //                         ^^^^
 *
 * This is because, in JavaScript, integers are represented as 64-bit floating
 * point numbers. If you want to learn more, see:
 *
 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
 * http://stackoverflow.com/questions/307179/what-is-javascripts-highest-integer-value-that-a-number-can-go-to-without-losin
 *
 * So, an accurate solution to this problem requires the use of a
 * "big integer" type. There are multiple ways to use big integer types.
 * We have provided you with BigInteger.js. You can read more about it here:
 *
 * https://github.com/peterolson/BigInteger.js
 * ^--- The "Methods" section of the README will be especially helpful.
 *
 * https://github.com/peterolson/BigInteger.js/blob/master/spec/spec.js
 * ^--- Tests are a good way to understand, in addition to the README.
 *
 * To get you started, this folder has a file of the big-integer module.
 * See its tests in this folder for a quick primer on how to use it! ( :
 */

import Grains from './grains';

describe('Grains', () => {
  const grains = new Grains();

  it('square 1', () => {
    expect(grains.square(1)).toBe('1');
  });

  xit('square 2', () => {
    expect(grains.square(2)).toBe('2');
  });

  xit('square 3', () => {
    expect(grains.square(3)).toBe('4');
  });

  xit('square 4', () => {
    expect(grains.square(4)).toBe('8');
  });

  xit('square 16', () => {
    expect(grains.square(16)).toBe('32768');
  });

  xit('square 32', () => {
    expect(grains.square(32)).toBe('2147483648');
  });

  xit('square 64', () => {
    expect(grains.square(64)).toBe('9223372036854775808');
  });

  xit('total', () => {
    expect(grains.total()).toBe('18446744073709551615');
  });

});

Version data entries

208 entries across 208 versions & 1 rubygems

Version Path
trackler-2.1.0.53 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.52 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.51 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.50 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.49 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.48 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.47 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.46 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.45 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.44 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.43 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.42 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.41 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.40 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.39 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.38 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.37 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.36 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.34 tracks/ecmascript/exercises/grains/grains.spec.js
trackler-2.1.0.33 tracks/ecmascript/exercises/grains/grains.spec.js