Repository navigation
Additional spec generators #690
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
Merged
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,11 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| return { | ||
| module_name = 'crypto_square', | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| assert.are.equal(%s, crypto_square.ciphertext(%s))]] | ||
| return template:format(utils.stringify(case.expected), utils.stringify(case.input.plaintext)) | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| local function render_items(items) | ||
| return table.concat(utils.map(items, function(item) | ||
| return ('{ weight = %d, value = %d }'):format(item.weight, item.value) | ||
| end), ', ') | ||
| end | ||
|
|
||
| return { | ||
| module_name = 'knapsack', | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| local items = { %s } | ||
| local maximum_weight = %d | ||
|
|
||
| assert.are.equal(%d, knapsack.maximum_value(maximum_weight, items))]] | ||
| return template:format(render_items(case.input.items), case.input.maximumWeight, case.expected) | ||
| 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/matching-brackets/.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 = 'brackets', | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| assert.is_%s(brackets.valid(%s))]] | ||
| return template:format(case.expected, utils.stringify(case.input.value)) | ||
| end | ||
| } |
43 changes: 21 additions & 22 deletions
43
exercises/practice/matching-brackets/matching-brackets_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,85 +1,84 @@ | ||
| -- canonical test data 2.0.0 | ||
| local brackets = require('matching-brackets') | ||
|
|
||
| describe('matching-brackets', function() | ||
| it('should accept paired square brackets', function() | ||
| it('paired square brackets', function() | ||
| assert.is_true(brackets.valid('[]')) | ||
| end) | ||
|
|
||
| it('should accept empty string', function() | ||
| it('empty string', function() | ||
| assert.is_true(brackets.valid('')) | ||
| end) | ||
|
|
||
| it('should reject unpaired brackets', function() | ||
| it('unpaired brackets', function() | ||
| assert.is_false(brackets.valid('[[')) | ||
| end) | ||
|
|
||
| it('should reject wrong ordered brackets', function() | ||
| it('wrong ordered brackets', function() | ||
| assert.is_false(brackets.valid('}{')) | ||
| end) | ||
|
|
||
| it('should reject wrong closing bracket', function() | ||
| it('wrong closing bracket', function() | ||
| assert.is_false(brackets.valid('{]')) | ||
| end) | ||
|
|
||
| it('should accept paired with whitespace', function() | ||
| it('paired with whitespace', function() | ||
| assert.is_true(brackets.valid('{ }')) | ||
| end) | ||
|
|
||
| it('should reject partially paired brackets', function() | ||
| it('partially paired brackets', function() | ||
| assert.is_false(brackets.valid('{[])')) | ||
| end) | ||
|
|
||
| it('should accept simple nested brackets', function() | ||
| it('simple nested brackets', function() | ||
| assert.is_true(brackets.valid('{[]}')) | ||
| end) | ||
|
|
||
| it('should accept several paired brackets', function() | ||
| it('several paired brackets', function() | ||
| assert.is_true(brackets.valid('{}[]')) | ||
| end) | ||
|
|
||
| it('should accept paired and nested brackets', function() | ||
| it('paired and nested brackets', function() | ||
| assert.is_true(brackets.valid('([{}({}[])])')) | ||
| end) | ||
|
|
||
| it('should reject unopened closing brackets', function() | ||
| it('unopened closing brackets', function() | ||
| assert.is_false(brackets.valid('{[)][]}')) | ||
| end) | ||
|
|
||
| it('should reject unpaired and nested brackets', function() | ||
| it('unpaired and nested brackets', function() | ||
| assert.is_false(brackets.valid('([{])')) | ||
| end) | ||
|
|
||
| it('should reject paired and wrong nested brackets', function() | ||
| it('paired and wrong nested brackets', function() | ||
| assert.is_false(brackets.valid('[({]})')) | ||
| end) | ||
|
|
||
| it('should reject paired and wrong nested brackets but innermost are correct', function() | ||
| it('paired and wrong nested brackets but innermost are correct', function() | ||
| assert.is_false(brackets.valid('[({}])')) | ||
| end) | ||
|
|
||
| it('should reject paired and incomplete brackets', function() | ||
| it('paired and incomplete brackets', function() | ||
| assert.is_false(brackets.valid('{}[')) | ||
| end) | ||
|
|
||
| it('should reject too many closing brackets', function() | ||
| it('too many closing brackets', function() | ||
| assert.is_false(brackets.valid('[]]')) | ||
| end) | ||
|
|
||
| it('should reject early unexpected brackets', function() | ||
| it('early unexpected brackets', function() | ||
| assert.is_false(brackets.valid(')()')) | ||
| end) | ||
|
|
||
| it('should reject early mismatched brackets', function() | ||
| it('early mismatched brackets', function() | ||
| assert.is_false(brackets.valid('{)()')) | ||
| end) | ||
|
|
||
| it('should accept math expression', function() | ||
| it('math expression', function() | ||
| assert.is_true(brackets.valid('(((185 + 223.85) * 15) - 543)/2')) | ||
| end) | ||
|
|
||
| it('should accept complex latex expression', function() | ||
| it('complex latex expression', function() | ||
| assert.is_true(brackets.valid( | ||
| [[\left(\begin{array}{cc} \frac{1}{3} & x\\ \mathrm{e}^{x} &... x^2 \end{array}\right)]])) | ||
| '\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... x^2 \\end{array}\\right)')) | ||
| end) | ||
| end) |
26 changes: 26 additions & 0 deletions
26
exercises/practice/pythagorean-triplet/.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,26 @@ | ||
| local utils = require 'utils' | ||
|
|
||
| local function render_triplets(triplets) | ||
| return '{ ' .. table.concat(utils.map(triplets, function(triplet) | ||
| return '{ ' .. table.concat(triplet, ', ') .. ' }' | ||
| end), ', ') .. ' }' | ||
| end | ||
|
|
||
| return { | ||
| module_name = 'triplets_with_sum', | ||
|
|
||
| test_helpers = [[ | ||
| local function sort(triplets) | ||
| table.sort(triplets, function(a, b) | ||
| return a[1] < b[1] | ||
| end) | ||
| return triplets | ||
| end | ||
| ]], | ||
|
|
||
| generate_test = function(case) | ||
| local template = [[ | ||
| assert.same(%s, sort(triplets_with_sum(%d)))]] | ||
| return template:format(render_triplets(case.expected), case.input.n) | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| local function render_queen(queen) | ||
| return ('Queen({ row = %d, column = %d })'):format(queen.position.row, queen.position.column) | ||
| end | ||
|
|
||
| return { | ||
| module_name = 'Queen', | ||
|
|
||
| generate_test = function(case) | ||
| if case.property == 'create' then | ||
| local template = [[ | ||
| assert.%s(function() | ||
| %s | ||
| end)]] | ||
| local assertion = type(case.expected) == 'table' and 'has_error' or 'has_no_error' | ||
| return template:format(assertion, render_queen(case.input.queen)) | ||
| else | ||
| local template = [[ | ||
| local q1 = %s | ||
| local q2 = %s | ||
| assert.is_%s(q1.can_attack(q2))]] | ||
| return template:format(render_queen(case.input.white_queen), render_queen(case.input.black_queen), case.expected) | ||
| end | ||
| end | ||
| } |
Oops, something went wrong.
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 fixes https://github.com/exercism/lua/pull/690/changes#diff-0745fedbfda3ea79019ffc728ad013f8a767d32eb58a27775fbf4231e7d84783R82 which otherwise needs
[[and]]to contain an escaped backslash.