Repository navigation
More spec generators #687
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
Merged
+158
−109
Merged
More spec generators #687
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
65e5690
Spec generator for pangram
ryanplusplus d7e710e
Spec generator for reverse-string
ryanplusplus 29574f4
Spec generator for rna-transcription
ryanplusplus 406c7ab
Spec generator for scrabble-score
ryanplusplus 72b66f0
Spec generator for nucleotide-count
ryanplusplus 8192f65
Merge branch 'main' of https://github.com/exercism/lua into more-spec…
ryanplusplus b6d2c73
Merge branch 'main' of https://github.com/exercism/lua into more-spec…
ryanplusplus 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
35 changes: 35 additions & 0 deletions
35
exercises/practice/nucleotide-count/.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,35 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| local function render_counts(counts) | ||
| local keys = {} | ||
| for k in pairs(counts) do | ||
| table.insert(keys, k) | ||
| end | ||
| table.sort(keys) | ||
|
|
||
| local entries = utils.map(keys, function(k) | ||
| return k .. ' = ' .. counts[k] | ||
| end) | ||
|
|
||
| return '{ ' .. table.concat(entries, ', ') .. ' }' | ||
| end | ||
|
|
||
| return { | ||
| module_name = 'DNA', | ||
|
|
||
| generate_test = function(case) | ||
| if case.expected.error then | ||
| local template = [[ | ||
| assert.has_error(function() | ||
| DNA:new(%s) | ||
| end)]] | ||
| return template:format(utils.stringify(case.input.strand)) | ||
| else | ||
| local template = [[ | ||
| local dna = DNA:new(%s) | ||
| local expected = %s | ||
| assert.are.same(expected, dna.nucleotideCounts)]] | ||
| return template:format(utils.stringify(case.input.strand), render_counts(case.expected)) | ||
| end | ||
| end | ||
| } |
72 changes: 17 additions & 55 deletions
72
exercises/practice/nucleotide-count/nucleotide-count_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,71 +1,33 @@ | ||
| local DNA = require('nucleotide-count') | ||
|
|
||
| describe('nucleotide-count', function() | ||
| it('has no nucleotides', function() | ||
| local expected = { A = 0, T = 0, C = 0, G = 0 } | ||
| dna = DNA:new('') | ||
| local result = dna.nucleotideCounts | ||
| assert.are.same(expected, result) | ||
| end) | ||
|
|
||
| it('has no adenosine', function() | ||
| it('empty strand', function() | ||
| local dna = DNA:new('') | ||
| local expected = 0 | ||
| result = dna:count('A') | ||
| assert.are.same(expected, result) | ||
| end) | ||
|
|
||
| it('repetitive cytosine gets counts', function() | ||
| local dna = DNA:new('CCCCC') | ||
| local expected = 5 | ||
| result = dna:count('C') | ||
| assert.are.same(expected, result) | ||
| local expected = { A = 0, C = 0, G = 0, T = 0 } | ||
| assert.are.same(expected, dna.nucleotideCounts) | ||
| end) | ||
|
|
||
| it('repetitive sequence has only guanosine', function() | ||
| local dna = DNA:new('GGGGGGGG') | ||
| expected = { A = 0, T = 0, C = 0, G = 8 } | ||
| result = dna.nucleotideCounts | ||
| assert.are.same(expected, result) | ||
| it('can count one nucleotide in single-character input', function() | ||
| local dna = DNA:new('G') | ||
| local expected = { A = 0, C = 0, G = 1, T = 0 } | ||
| assert.are.same(expected, dna.nucleotideCounts) | ||
| end) | ||
|
|
||
| it('counts only thymine', function() | ||
| local dna = DNA:new('GGGGTAACCCGG') | ||
| expected = 1 | ||
| result = dna:count('T') | ||
| assert.are.same(expected, result) | ||
| it('strand with repeated nucleotide', function() | ||
| local dna = DNA:new('GGGGGGG') | ||
| local expected = { A = 0, C = 0, G = 7, T = 0 } | ||
| assert.are.same(expected, dna.nucleotideCounts) | ||
| end) | ||
|
|
||
| it('counts a nucleotide only once', function() | ||
| local dna = DNA:new('GGTTGG') | ||
| expected = 2 | ||
| result = dna:count('T') | ||
| assert.are.same(expected, result) | ||
| it('strand with multiple nucleotides', function() | ||
| local dna = DNA:new('AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC') | ||
| local expected = { A = 20, C = 12, G = 17, T = 21 } | ||
| assert.are.same(expected, dna.nucleotideCounts) | ||
| end) | ||
|
|
||
| it('validates dna sequences', function() | ||
| assert.has.errors(function() | ||
| DNA:new('INVALID') | ||
| end) | ||
| it('strand with invalid nucleotides', function() | ||
| assert.has_error(function() | ||
| DNA:new('INVALID') | ||
| end, 'Invalid Sequence') | ||
| end) | ||
|
|
||
| it('validates counting nucleotides', function() | ||
| local dna = DNA:new('GGTTGG') | ||
| assert.has.errors(function() | ||
| dna:count('X') | ||
| DNA:new('AGXXACT') | ||
| end) | ||
| assert.has_error(function() | ||
| dna:count('X') | ||
| end, 'Invalid Nucleotide') | ||
| end) | ||
|
|
||
| it('counts all nucleotides', function() | ||
| local dna = DNA:new('AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC') | ||
| expected = { A = 20, T = 21, G = 17, C = 12 } | ||
| result = dna.nucleotideCounts | ||
| assert.are.same(expected, result) | ||
| 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,11 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| return { | ||
| module_name = 'is_pangram', | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| assert.is_%s(is_pangram(%s))]] | ||
| return template:format(case.expected, utils.stringify(case.input.sentence)) | ||
| 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 |
|---|---|---|
| @@ -1,56 +1,43 @@ | ||
| local is_pangram = require('pangram') | ||
|
|
||
| describe('pangram', function() | ||
| it('should not consider the empty string to be a pangram', function() | ||
| it('empty sentence', function() | ||
| assert.is_false(is_pangram('')) | ||
| end) | ||
|
|
||
| it('should not consider a sentence with 26 of the same letter to be a pangram', function() | ||
| assert.is_false(is_pangram(string.rep('a', 26))) | ||
| end) | ||
|
|
||
| it('should consider the alphabet to be a pangram', function() | ||
| it('perfect lower case', function() | ||
| assert.is_true(is_pangram('abcdefghijklmnopqrstuvwxyz')) | ||
| end) | ||
|
|
||
| it('should consider a sentence with one of each letter to be a pangram', function() | ||
| it('only lower case', function() | ||
| assert.is_true(is_pangram('the quick brown fox jumps over the lazy dog')) | ||
| end) | ||
|
|
||
| it('should allow mixed case in pangrams', function() | ||
| assert.is_true(is_pangram('The Quick Brown Fox Jumps Over The Lazy Dog')) | ||
| it("missing the letter 'x'", function() | ||
| assert.is_false(is_pangram('a quick movement of the enemy will jeopardize five gunboats')) | ||
| end) | ||
|
|
||
| it('should allow punctuation in pangrams', function() | ||
| assert.is_true(is_pangram('the.quick.brown.fox.jumps.over.the.lazy.dog')) | ||
| it("missing the letter 'h'", function() | ||
| assert.is_false(is_pangram('five boxing wizards jump quickly at it')) | ||
| end) | ||
|
|
||
| it('should allow underscores in pangrams', function() | ||
| assert.is_true(is_pangram('the_quick_brown_fox_jumps_over_the_lazy.dog')) | ||
| it('with underscores', function() | ||
| assert.is_true(is_pangram('the_quick_brown_fox_jumps_over_the_lazy_dog')) | ||
| end) | ||
|
|
||
| it('should allow numbers in pangrams', function() | ||
| it('with numbers', function() | ||
| assert.is_true(is_pangram('the 1 quick brown fox jumps over the 2 lazy dogs')) | ||
| end) | ||
|
|
||
| it('should not allow letters in pangrams to be replaced by numbers', function() | ||
| it('missing letters replaced by numbers', function() | ||
| assert.is_false(is_pangram('7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog')) | ||
| end) | ||
|
|
||
| it('should not consider a sentence with only 25 unique letters to be a pangram', function() | ||
| assert.is_false(is_pangram('a quick movement of the enemy will jeopardize five gunboats')) | ||
| assert.is_false(is_pangram('the quick brown fish jumps over the lazy dog')) | ||
| end) | ||
|
|
||
| it('should allow non-ASCII characters in pangrams', function() | ||
| assert.is_true(is_pangram('Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.')) | ||
| end) | ||
|
|
||
| it('should not consider non-ASCII characters to be letters', function() | ||
| assert.is_false(is_pangram('äbcdefghijklmnopqrstuvwxyz')) | ||
| it('mixed case and punctuation', function() | ||
| assert.is_true(is_pangram('"Five quacking Zephyrs jolt my wax bed."')) | ||
| end) | ||
|
|
||
| it('should not consider a-m and A-M to be a pangram', function() | ||
| it('a-m and a-m are 26 different characters but not a pangram', function() | ||
| assert.is_false(is_pangram('abcdefghijklm ABCDEFGHIJKLM')) | ||
| end) | ||
| end) |
11 changes: 11 additions & 0 deletions
11
exercises/practice/reverse-string/.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,11 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| return { | ||
| module_name = 'reverse_string', | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| assert.are.equal(%s, reverse_string(%s))]] | ||
| return template:format(utils.stringify(case.expected), utils.stringify(case.input.value)) | ||
| 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
11 changes: 11 additions & 0 deletions
11
exercises/practice/rna-transcription/.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,11 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| return { | ||
| module_name = 'to_rna', | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| assert.are.equal(%s, to_rna(%s))]] | ||
| return template:format(utils.stringify(case.expected), utils.stringify(case.input.dna)) | ||
| end | ||
| } |
18 changes: 11 additions & 7 deletions
18
exercises/practice/rna-transcription/rna-transcription_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,23 +1,27 @@ | ||
| local to_rna = require('rna-transcription') | ||
|
|
||
| describe('rna-transcription', function() | ||
| it('transcribes cytosine to guanosine', function() | ||
| it('empty rna sequence', function() | ||
| assert.are.equal('', to_rna('')) | ||
| end) | ||
|
|
||
| it('rna complement of cytosine is guanine', function() | ||
| assert.are.equal('G', to_rna('C')) | ||
| end) | ||
|
|
||
| it('transcribes guanosine to cytosine', function() | ||
| it('rna complement of guanine is cytosine', function() | ||
| assert.are.equal('C', to_rna('G')) | ||
| end) | ||
|
|
||
| it('transcribes adenosine to uracil', function() | ||
| assert.are.equal('U', to_rna('A')) | ||
| it('rna complement of thymine is adenine', function() | ||
| assert.are.equal('A', to_rna('T')) | ||
| end) | ||
|
|
||
| it('transcribes thymine to adenosine', function() | ||
| assert.are.equal('A', to_rna('T')) | ||
| it('rna complement of adenine is uracil', function() | ||
| assert.are.equal('U', to_rna('A')) | ||
| end) | ||
|
|
||
| it('transcribes all DNA nucleotides to their RNA complements', function() | ||
| it('rna complement', function() | ||
| assert.are.equal('UGCACCAGAAUU', to_rna('ACGTGGTCTTAA')) | ||
| end) | ||
| end) |
11 changes: 11 additions & 0 deletions
11
exercises/practice/scrabble-score/.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,11 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| return { | ||
| module_name = 'scrabble_score', | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| assert.are.equal(%d, scrabble_score.score(%s))]] | ||
| return template:format(case.expected, utils.stringify(case.input.word)) | ||
| end | ||
| } |
46 changes: 33 additions & 13 deletions
46
exercises/practice/scrabble-score/scrabble-score_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,27 +1,47 @@ | ||
| local score = require('scrabble-score').score | ||
| local scrabble_score = require('scrabble-score') | ||
|
|
||
| describe('scrabble-score', function() | ||
| it('scores an empty word as zero', function() | ||
| assert.are.equal(0, score('')) | ||
| it('lowercase letter', function() | ||
| assert.are.equal(1, scrabble_score.score('a')) | ||
| end) | ||
|
|
||
| it('scores a nil as zero', function() | ||
| assert.are.equal(0, score(nil)) | ||
| it('uppercase letter', function() | ||
| assert.are.equal(1, scrabble_score.score('A')) | ||
| end) | ||
|
|
||
| it('scores a very short word', function() | ||
| assert.are.equal(1, score('a')) | ||
| it('valuable letter', function() | ||
| assert.are.equal(4, scrabble_score.score('f')) | ||
| end) | ||
|
|
||
| it('scores the word by the number of letters', function() | ||
| assert.are.equal(6, score('street')) | ||
| it('short word', function() | ||
| assert.are.equal(2, scrabble_score.score('at')) | ||
| end) | ||
|
|
||
| it('scores more complicated words with more', function() | ||
| assert.are.equal(22, score('quirky')) | ||
| it('short, valuable word', function() | ||
| assert.are.equal(12, scrabble_score.score('zoo')) | ||
| end) | ||
|
|
||
| it('scores case insensitive words', function() | ||
| assert.are.equal(41, score('OXYPHENBUTAZONE')) | ||
| it('medium word', function() | ||
| assert.are.equal(6, scrabble_score.score('street')) | ||
| end) | ||
|
|
||
| it('medium, valuable word', function() | ||
| assert.are.equal(22, scrabble_score.score('quirky')) | ||
| end) | ||
|
|
||
| it('long, mixed-case word', function() | ||
| assert.are.equal(41, scrabble_score.score('OxyphenButazone')) | ||
| end) | ||
|
|
||
| it('english-like word', function() | ||
| assert.are.equal(8, scrabble_score.score('pinata')) | ||
| end) | ||
|
|
||
| it('empty input', function() | ||
| assert.are.equal(0, scrabble_score.score('')) | ||
| end) | ||
|
|
||
| it('entire alphabet available', function() | ||
| assert.are.equal(87, scrabble_score.score('abcdefghijklmnopqrstuvwxyz')) | ||
| end) | ||
| end) |
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.
This is not called out in the common problem specification