|
1 | 1 | local perfect_numbers = require('perfect-numbers') |
2 | 2 |
|
3 | 3 | describe('perfect-numbers', function() |
4 | | - it('should be able to calculate the Aliquot sum of a number with no divisors', function() |
5 | | - assert.equal(0, perfect_numbers.aliquot_sum(1)) |
6 | | - end) |
| 4 | + describe('perfect numbers', function() |
| 5 | + it('smallest perfect number is classified correctly', function() |
| 6 | + assert.equal('perfect', perfect_numbers.aliquot_sum(6)) |
| 7 | + end) |
7 | 8 |
|
8 | | - it('should be able to calculate the Aliquot sum of a number with a single divisor', function() |
9 | | - assert.equal(1, perfect_numbers.aliquot_sum(2)) |
10 | | - end) |
| 9 | + it('medium perfect number is classified correctly', function() |
| 10 | + assert.equal('perfect', perfect_numbers.aliquot_sum(28)) |
| 11 | + end) |
11 | 12 |
|
12 | | - it('should be able to calculate the Aliquot sum of a number with a multiple divisors', function() |
13 | | - assert.equal(15, perfect_numbers.aliquot_sum(16)) |
| 13 | + it('large perfect number is classified correctly', function() |
| 14 | + assert.equal('perfect', perfect_numbers.aliquot_sum(33550336)) |
| 15 | + end) |
14 | 16 | end) |
15 | 17 |
|
16 | | - it('should be able to calculate the Aliquot sum of a large number', function() |
17 | | - assert.equal(229, perfect_numbers.aliquot_sum(1115)) |
18 | | - end) |
| 18 | + describe('abundant numbers', function() |
| 19 | + it('smallest abundant number is classified correctly', function() |
| 20 | + assert.equal('abundant', perfect_numbers.aliquot_sum(12)) |
| 21 | + end) |
| 22 | + |
| 23 | + it('medium abundant number is classified correctly', function() |
| 24 | + assert.equal('abundant', perfect_numbers.aliquot_sum(30)) |
| 25 | + end) |
| 26 | + |
| 27 | + it('large abundant number is classified correctly', function() |
| 28 | + assert.equal('abundant', perfect_numbers.aliquot_sum(33550335)) |
| 29 | + end) |
19 | 30 |
|
20 | | - it('should classify numbers whose Aliquot sum is less than itself as deficient', function() |
21 | | - assert.equal('deficient', perfect_numbers.classify(13)) |
| 31 | + it('perfect square abundant number is classified correctly', function() |
| 32 | + assert.equal('abundant', perfect_numbers.aliquot_sum(196)) |
| 33 | + end) |
22 | 34 | end) |
23 | 35 |
|
24 | | - it('should classify numbers whose Aliquot sum is equal to itself as perfect', function() |
25 | | - assert.equal('perfect', perfect_numbers.classify(28)) |
| 36 | + describe('deficient numbers', function() |
| 37 | + it('smallest prime deficient number is classified correctly', function() |
| 38 | + assert.equal('deficient', perfect_numbers.aliquot_sum(2)) |
| 39 | + end) |
| 40 | + |
| 41 | + it('smallest non-prime deficient number is classified correctly', function() |
| 42 | + assert.equal('deficient', perfect_numbers.aliquot_sum(4)) |
| 43 | + end) |
| 44 | + |
| 45 | + it('medium deficient number is classified correctly', function() |
| 46 | + assert.equal('deficient', perfect_numbers.aliquot_sum(32)) |
| 47 | + end) |
| 48 | + |
| 49 | + it('large deficient number is classified correctly', function() |
| 50 | + assert.equal('deficient', perfect_numbers.aliquot_sum(33550337)) |
| 51 | + end) |
| 52 | + |
| 53 | + it('edge case (no factors other than itself) is classified correctly', function() |
| 54 | + assert.equal('deficient', perfect_numbers.aliquot_sum(1)) |
| 55 | + end) |
26 | 56 | end) |
27 | 57 |
|
28 | | - it('should classify numbers whose Aliquot sum is greater than itself as abundant', function() |
29 | | - assert.equal('abundant', perfect_numbers.classify(12)) |
| 58 | + describe('invalid inputs', function() |
| 59 | + it('zero is rejected (as it is not a positive integer)', function() |
| 60 | + assert.equal('table: 0x8d2c60bc0', perfect_numbers.aliquot_sum(0)) |
| 61 | + end) |
| 62 | + |
| 63 | + it('negative integer is rejected (as it is not a positive integer)', function() |
| 64 | + assert.equal('table: 0x8d2c60f80', perfect_numbers.aliquot_sum(-1)) |
| 65 | + end) |
30 | 66 | end) |
31 | 67 | end) |
0 commit comments