forked from SiZapPaaiGwat/javascript-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime-factor-tree.spec.js
More file actions
28 lines (22 loc) · 1 KB
/
prime-factor-tree.spec.js
File metadata and controls
28 lines (22 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
var primeFactorTree = require('../../src/primes/prime-factor-tree').primeFactorTree;
describe('Prime factor tree', function () {
it('for number 104743 should return [104743]', function () {
expect(primeFactorTree(104743).toString()).toEqual([104743].toString());
});
it('for number 18 should return [2, 3, 3]', function () {
expect(primeFactorTree(18).toString()).toEqual([2, 3, 3].toString());
});
it('should give the empty list for number less or equal 1', function () {
expect(primeFactorTree(-12).toString()).toEqual([].toString());
expect(primeFactorTree(0).toString()).toEqual([].toString());
expect(primeFactorTree(1).toString()).toEqual([].toString());
});
it('sum of primes for given number 600851475143 should be 9238', function () {
var primes = primeFactorTree(600851475143);
var sumOfPrimes = primes.reduce(function (previousValue, currentValue) {
return previousValue + currentValue;
});
expect(sumOfPrimes).toEqual(9238);
});
});