Skip to content

Commit 95cb031

Browse files
committed
Sync perfect-numbers
1 parent d200695 commit 95cb031

3 files changed

Lines changed: 88 additions & 33 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
return {
2+
module_name = 'perfect_numbers',
3+
4+
generate_test = function(case)
5+
local template = [[
6+
assert.equal('%s', perfect_numbers.aliquot_sum(%s))]]
7+
return template:format(case.expected, case.input.number)
8+
end
9+
}
Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,52 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[163e8e86-7bfd-4ee2-bd68-d083dc3381a3]
6-
description = "Smallest perfect number is classified correctly"
13+
description = "Perfect numbers -> Smallest perfect number is classified correctly"
714

815
[169a7854-0431-4ae0-9815-c3b6d967436d]
9-
description = "Medium perfect number is classified correctly"
16+
description = "Perfect numbers -> Medium perfect number is classified correctly"
1017

1118
[ee3627c4-7b36-4245-ba7c-8727d585f402]
12-
description = "Large perfect number is classified correctly"
19+
description = "Perfect numbers -> Large perfect number is classified correctly"
1320

1421
[80ef7cf8-9ea8-49b9-8b2d-d9cb3db3ed7e]
15-
description = "Smallest abundant number is classified correctly"
22+
description = "Abundant numbers -> Smallest abundant number is classified correctly"
1623

1724
[3e300e0d-1a12-4f11-8c48-d1027165ab60]
18-
description = "Medium abundant number is classified correctly"
25+
description = "Abundant numbers -> Medium abundant number is classified correctly"
1926

2027
[ec7792e6-8786-449c-b005-ce6dd89a772b]
21-
description = "Large abundant number is classified correctly"
28+
description = "Abundant numbers -> Large abundant number is classified correctly"
29+
30+
[05f15b93-849c-45e9-9c7d-1ea131ef7d10]
31+
description = "Abundant numbers -> Perfect square abundant number is classified correctly"
2232

2333
[e610fdc7-2b6e-43c3-a51c-b70fb37413ba]
24-
description = "Smallest prime deficient number is classified correctly"
34+
description = "Deficient numbers -> Smallest prime deficient number is classified correctly"
2535

2636
[0beb7f66-753a-443f-8075-ad7fbd9018f3]
27-
description = "Smallest non-prime deficient number is classified correctly"
37+
description = "Deficient numbers -> Smallest non-prime deficient number is classified correctly"
2838

2939
[1c802e45-b4c6-4962-93d7-1cad245821ef]
30-
description = "Medium deficient number is classified correctly"
40+
description = "Deficient numbers -> Medium deficient number is classified correctly"
3141

3242
[47dd569f-9e5a-4a11-9a47-a4e91c8c28aa]
33-
description = "Large deficient number is classified correctly"
43+
description = "Deficient numbers -> Large deficient number is classified correctly"
3444

3545
[a696dec8-6147-4d68-afad-d38de5476a56]
36-
description = "Edge case (no factors other than itself) is classified correctly"
46+
description = "Deficient numbers -> Edge case (no factors other than itself) is classified correctly"
3747

3848
[72445cee-660c-4d75-8506-6c40089dc302]
39-
description = "Zero is rejected (not a natural number)"
49+
description = "Invalid inputs -> Zero is rejected (as it is not a positive integer)"
4050

4151
[2d72ce2c-6802-49ac-8ece-c790ba3dae13]
42-
description = "Negative integer is rejected (not a natural number)"
52+
description = "Invalid inputs -> Negative integer is rejected (as it is not a positive integer)"
Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,67 @@
11
local perfect_numbers = require('perfect-numbers')
22

33
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)
78

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)
1112

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)
1416
end)
1517

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)
1930

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)
2234
end)
2335

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)
2656
end)
2757

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)
3066
end)
3167
end)

0 commit comments

Comments
 (0)