collatz-conjecture/collatz-conjecture.spec.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 1

Size

Lines of Code 31
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 18
mnd 0
bc 0
fnc 9
dl 0
loc 31
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10
1
import { steps } from './collatz-conjecture';
2
3
describe('steps()', () => {
4
  test('zero steps for one', () => {
5
    expect(steps(1)).toEqual(0);
6
  });
7
8
  test('divide if even', () => {
9
    expect(steps(16)).toEqual(4);
10
  });
11
12
  test('even and odd steps', () => {
13
    expect(steps(12)).toEqual(9);
14
  });
15
16
  test('Large number of even and odd steps', () => {
17
    expect(steps(1000000)).toEqual(152);
18
  });
19
20
  test('zero is an error', () => {
21
    expect(() => {
22
      steps(0);
23
    }).toThrow(new Error('Only positive numbers are allowed'));
24
  });
25
26
 test('negative value is an error', () => {
27
    expect(() => {
28
      steps(-15);
29
    }).toThrow(new Error('Only positive numbers are allowed'));
30
  });
31
});
32