-
-
Notifications
You must be signed in to change notification settings - Fork 60
Spec generators for square-root, sum-of-multiples, two-fer #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ryanplusplus
wants to merge
1
commit into
main
Choose a base branch
from
more-spec-generators
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| return { | ||
| module_name = 'SquareRoot', | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| assert.equal(%s, SquareRoot.%s(%s))]] | ||
|
|
||
| return template:format(tostring(case.expected), utils.snake_case(case.property), case.input.radicand) | ||
| end | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
exercises/practice/sum-of-multiples/.meta/spec_generator.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| return { | ||
| module_name = 'sum_of_multiples', | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| assert.equal(%s, sum_of_multiples(%s).to(%s))]] | ||
|
|
||
| local factors = '{ ' .. table.concat(utils.map(case.input.factors, tostring), ', ') .. ' }' | ||
| return template:format(tostring(case.expected), factors, case.input.limit) | ||
| end | ||
| } |
69 changes: 56 additions & 13 deletions
69
exercises/practice/sum-of-multiples/sum-of-multiples_spec.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,67 @@ | ||
| local sum_of_multiples = require('sum-of-multiples') | ||
|
|
||
| describe('sum-of-multiples', function() | ||
| it('should sum multiples of a single number', function() | ||
| assert.same(9, sum_of_multiples({ 3 }).to(7)) | ||
| assert.same(15, sum_of_multiples({ 5 }).to(12)) | ||
| it('no multiples within limit', function() | ||
| assert.equal(0, sum_of_multiples({ 3, 5 }).to(1)) | ||
| end) | ||
|
|
||
| it('should sum multiples of a list of numbers', function() | ||
| assert.same(33, sum_of_multiples({ 3, 5 }).to(11)) | ||
| assert.same(129, sum_of_multiples({ 7, 3 }).to(25)) | ||
| assert.same(153, sum_of_multiples({ 7, 3, 8 }).to(25)) | ||
| it('one factor has multiples within limit', function() | ||
| assert.equal(3, sum_of_multiples({ 3, 5 }).to(4)) | ||
| end) | ||
|
|
||
| it('should calculate multiples up to, but not including, the limit', function() | ||
| assert.same(9, sum_of_multiples({ 3 }).to(9)) | ||
| assert.same(23, sum_of_multiples({ 3, 5 }).to(10)) | ||
| it('more than one multiple within limit', function() | ||
| assert.equal(9, sum_of_multiples({ 3 }).to(7)) | ||
| end) | ||
|
|
||
| it('should not include a multiple more than once', function() | ||
| assert.same(35, sum_of_multiples({ 2, 5 }).to(11)) | ||
| assert.same(sum_of_multiples({ 2 }).to(11), sum_of_multiples({ 2, 4 }).to(11)) | ||
| it('more than one factor with multiples within limit', function() | ||
| assert.equal(23, sum_of_multiples({ 3, 5 }).to(10)) | ||
| end) | ||
|
|
||
| it('each multiple is only counted once', function() | ||
| assert.equal(2318, sum_of_multiples({ 3, 5 }).to(100)) | ||
| end) | ||
|
|
||
| it('a much larger limit', function() | ||
| assert.equal(233168, sum_of_multiples({ 3, 5 }).to(1000)) | ||
| end) | ||
|
|
||
| it('three factors', function() | ||
| assert.equal(51, sum_of_multiples({ 7, 13, 17 }).to(20)) | ||
| end) | ||
|
|
||
| it('factors not relatively prime', function() | ||
| assert.equal(30, sum_of_multiples({ 4, 6 }).to(15)) | ||
| end) | ||
|
|
||
| it('some pairs of factors relatively prime and some not', function() | ||
| assert.equal(4419, sum_of_multiples({ 5, 6, 8 }).to(150)) | ||
| end) | ||
|
|
||
| it('one factor is a multiple of another', function() | ||
| assert.equal(275, sum_of_multiples({ 5, 25 }).to(51)) | ||
| end) | ||
|
|
||
| it('much larger factors', function() | ||
| assert.equal(2203160, sum_of_multiples({ 43, 47 }).to(10000)) | ||
| end) | ||
|
|
||
| it('all numbers are multiples of 1', function() | ||
| assert.equal(4950, sum_of_multiples({ 1 }).to(100)) | ||
| end) | ||
|
|
||
| it('no factors means an empty sum', function() | ||
| assert.equal(0, sum_of_multiples({}).to(10000)) | ||
| end) | ||
|
|
||
| it('the only multiple of 0 is 0', function() | ||
| assert.equal(0, sum_of_multiples({ 0 }).to(1)) | ||
| end) | ||
|
|
||
| it('the factor 0 does not affect the sum of multiples of other factors', function() | ||
| assert.equal(3, sum_of_multiples({ 3, 0 }).to(4)) | ||
| end) | ||
|
|
||
| it('solutions using include-exclude must extend to cardinality greater than 3', function() | ||
| assert.equal(39614537, sum_of_multiples({ 2, 3, 5, 7, 11 }).to(10000)) | ||
| end) | ||
| end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| return { | ||
| module_name = 'TwoFer', | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| assert.equal(%s, TwoFer.%s(%s))]] | ||
|
|
||
| local name = case.input.name and utils.stringify(case.input.name) or '' | ||
| return template:format(utils.stringify(case.expected), utils.snake_case(case.property), name) | ||
| end | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Embarassingly, I left some debug code in here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gasp!