Skip to content

Commit d04daf1

Browse files
sync prime-factors (#564)
1 parent ffc5137 commit d04daf1

File tree

3 files changed

+58
-19
lines changed

3 files changed

+58
-19
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local function render_numbers(numbers)
2+
return table.concat(numbers, ', ')
3+
end
4+
5+
return {
6+
module_name = 'prime_factors',
7+
8+
generate_test = function(case)
9+
local template = [[
10+
assert.are.same({ %s }, prime_factors(%s))]]
11+
return template:format(render_numbers(case.expected), case.input.value)
12+
end
13+
}

exercises/practice/prime-factors/.meta/tests.toml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
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
[924fc966-a8f5-4288-82f2-6b9224819ccd]
613
description = "no factors"
714

815
[17e30670-b105-4305-af53-ddde182cb6ad]
916
description = "prime number"
1017

18+
[238d57c8-4c12-42ef-af34-ae4929f94789]
19+
description = "another prime number"
20+
1121
[f59b8350-a180-495a-8fb1-1712fbee1158]
1222
description = "square of a prime"
1323

24+
[756949d3-3158-4e3d-91f2-c4f9f043ee70]
25+
description = "product of first prime"
26+
1427
[bc8c113f-9580-4516-8669-c5fc29512ceb]
1528
description = "cube of a prime"
1629

30+
[7d6a3300-a4cb-4065-bd33-0ced1de6cb44]
31+
description = "product of second prime"
32+
33+
[073ac0b2-c915-4362-929d-fc45f7b9a9e4]
34+
description = "product of third prime"
35+
36+
[6e0e4912-7fb6-47f3-a9ad-dbcd79340c75]
37+
description = "product of first and second prime"
38+
1739
[00485cd3-a3fe-4fbe-a64a-a4308fc1f870]
1840
description = "product of primes and non-primes"
1941

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
11
local prime_factors = require('prime-factors')
22

33
describe('prime-factors', function()
4-
it('returns an empty array for 1', function()
4+
it('no factors', function()
55
assert.are.same({}, prime_factors(1))
66
end)
77

8-
it('factors 2', function()
8+
it('prime number', function()
99
assert.are.same({ 2 }, prime_factors(2))
1010
end)
1111

12-
it('factors 3', function()
12+
it('another prime number', function()
1313
assert.are.same({ 3 }, prime_factors(3))
1414
end)
1515

16-
it('factors 4', function()
17-
assert.are.same({ 2, 2 }, prime_factors(4))
16+
it('square of a prime', function()
17+
assert.are.same({ 3, 3 }, prime_factors(9))
1818
end)
1919

20-
it('factors 6', function()
21-
assert.are.same({ 2, 3 }, prime_factors(6))
20+
it('product of first prime', function()
21+
assert.are.same({ 2, 2 }, prime_factors(4))
2222
end)
2323

24-
it('factors 8', function()
24+
it('cube of a prime', function()
2525
assert.are.same({ 2, 2, 2 }, prime_factors(8))
2626
end)
2727

28-
it('factors 9', function()
29-
assert.are.same({ 3, 3 }, prime_factors(9))
30-
end)
31-
32-
it('factors 27', function()
28+
it('product of second prime', function()
3329
assert.are.same({ 3, 3, 3 }, prime_factors(27))
3430
end)
3531

36-
it('factors 625', function()
32+
it('product of third prime', function()
3733
assert.are.same({ 5, 5, 5, 5 }, prime_factors(625))
3834
end)
3935

40-
it('factors 901255', function()
36+
it('product of first and second prime', function()
37+
assert.are.same({ 2, 3 }, prime_factors(6))
38+
end)
39+
40+
it('product of primes and non-primes', function()
41+
assert.are.same({ 2, 2, 3 }, prime_factors(12))
42+
end)
43+
44+
it('product of primes', function()
4145
assert.are.same({ 5, 17, 23, 461 }, prime_factors(901255))
4246
end)
4347

44-
it('factors 93819012551', function()
48+
it('factors include a large prime', function()
4549
assert.are.same({ 11, 9539, 894119 }, prime_factors(93819012551))
4650
end)
4751
end)

0 commit comments

Comments
 (0)