| Total Complexity | 9 |
| Complexity/F | 1 |
| Lines of Code | 31 |
| Function Count | 9 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 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 |