Skip to content

Commit bd200d8

Browse files
Sync isbn-verifier tests (#539)
1 parent 06dfd2c commit bd200d8

File tree

3 files changed

+75
-29
lines changed

3 files changed

+75
-29
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
return {
2+
module_name = 'isbn_verifier',
3+
4+
generate_test = function(case)
5+
local template = [[
6+
assert.is_%s(isbn_verifier.valid('%s'))]]
7+
return template:format(case.expected, case.input.isbn)
8+
end
9+
}

exercises/practice/isbn-verifier/.meta/tests.toml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
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
[0caa3eac-d2e3-4c29-8df8-b188bc8c9292]
6-
description = "valid isbn number"
13+
description = "valid isbn"
714

815
[19f76b53-7c24-45f8-87b8-4604d0ccd248]
916
description = "invalid isbn check digit"
1017

1118
[4164bfee-fb0a-4a1c-9f70-64c6a1903dcd]
12-
description = "valid isbn number with a check digit of 10"
19+
description = "valid isbn with a check digit of 10"
1320

1421
[3ed50db1-8982-4423-a993-93174a20825c]
1522
description = "check digit is a character other than X"
1623

24+
[9416f4a5-fe01-4b61-a07b-eb75892ef562]
25+
description = "invalid check digit in isbn is not treated as zero"
26+
1727
[c19ba0c4-014f-4dc3-a63f-ff9aefc9b5ec]
18-
description = "invalid character in isbn"
28+
description = "invalid character in isbn is not treated as zero"
1929

2030
[28025280-2c39-4092-9719-f3234b89c627]
2131
description = "X is only valid as a check digit"
@@ -48,7 +58,10 @@ description = "empty isbn"
4858
description = "input is 9 characters"
4959

5060
[ed6e8d1b-382c-4081-8326-8b772c581fec]
51-
description = "invalid characters are not ignored"
61+
description = "invalid characters are not ignored after checking length"
62+
63+
[daad3e58-ce00-4395-8a8e-e3eded1cdc86]
64+
description = "invalid characters are not ignored before checking length"
5265

5366
[fb5e48d8-7c03-4bfb-a088-b101df16fdc3]
5467
description = "input is too long but contains a valid isbn"
Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,79 @@
1-
local valid = require('isbn-verifier').valid
1+
local isbn_verifier = require('isbn-verifier')
22

33
describe('isbn-verifier', function()
4-
it('valid isbn number', function()
5-
assert.is_true(valid('3-598-21508-8'))
4+
it('valid isbn', function()
5+
assert.is_true(isbn_verifier.valid('3-598-21508-8'))
66
end)
77

88
it('invalid isbn check digit', function()
9-
assert.is_false(valid('3-598-21508-9'))
9+
assert.is_false(isbn_verifier.valid('3-598-21508-9'))
1010
end)
1111

12-
it('valid isbn number with a check digit of 10', function()
13-
assert.is_true(valid('3-598-21507-X'))
12+
it('valid isbn with a check digit of 10', function()
13+
assert.is_true(isbn_verifier.valid('3-598-21507-X'))
1414
end)
1515

16-
it('check digit is a character other than X', function()
17-
assert.is_false(valid('3-598-21507-A'))
16+
it('check digit is a character other than x', function()
17+
assert.is_false(isbn_verifier.valid('3-598-21507-A'))
1818
end)
1919

20-
it('invalid character in isbn', function()
21-
assert.is_false(valid('3-598-2K507-0'))
20+
it('invalid check digit in isbn is not treated as zero', function()
21+
assert.is_false(isbn_verifier.valid('4-598-21507-B'))
2222
end)
2323

24-
it('X is only valid as a check digit', function()
25-
assert.is_false(valid('3-598-2X507-9'))
24+
it('invalid character in isbn is not treated as zero', function()
25+
assert.is_false(isbn_verifier.valid('3-598-P1581-X'))
26+
end)
27+
28+
it('x is only valid as a check digit', function()
29+
assert.is_false(isbn_verifier.valid('3-598-2X507-9'))
2630
end)
2731

2832
it('valid isbn without separating dashes', function()
29-
assert.is_true(valid('3598215088'))
33+
assert.is_true(isbn_verifier.valid('3598215088'))
3034
end)
3135

32-
it('isbn without separating dashes and X as check digit', function()
33-
assert.is_true(valid('359821507X'))
36+
it('isbn without separating dashes and x as check digit', function()
37+
assert.is_true(isbn_verifier.valid('359821507X'))
3438
end)
3539

3640
it('isbn without check digit and dashes', function()
37-
assert.is_false(valid('359821507'))
41+
assert.is_false(isbn_verifier.valid('359821507'))
3842
end)
3943

4044
it('too long isbn and no dashes', function()
41-
assert.is_false(valid('3598215078X'))
45+
assert.is_false(isbn_verifier.valid('3598215078X'))
46+
end)
47+
48+
it('too short isbn', function()
49+
assert.is_false(isbn_verifier.valid('00'))
4250
end)
4351

4452
it('isbn without check digit', function()
45-
assert.is_false(valid('3-598-21507'))
53+
assert.is_false(isbn_verifier.valid('3-598-21507'))
54+
end)
55+
56+
it('check digit of x should not be used for 0', function()
57+
assert.is_false(isbn_verifier.valid('3-598-21515-X'))
58+
end)
59+
60+
it('empty isbn', function()
61+
assert.is_false(isbn_verifier.valid(''))
62+
end)
63+
64+
it('input is 9 characters', function()
65+
assert.is_false(isbn_verifier.valid('134456729'))
66+
end)
67+
68+
it('invalid characters are not ignored after checking length', function()
69+
assert.is_false(isbn_verifier.valid('3132P34035'))
4670
end)
4771

48-
it('too long isbn', function()
49-
assert.is_false(valid('3-598-21507-XX'))
72+
it('invalid characters are not ignored before checking length', function()
73+
assert.is_false(isbn_verifier.valid('3598P215088'))
5074
end)
5175

52-
it('check digit of X should not be used for 0', function()
53-
assert.is_false(valid('3-598-21515-X'))
76+
it('input is too long but contains a valid isbn', function()
77+
assert.is_false(isbn_verifier.valid('98245726788'))
5478
end)
5579
end)

0 commit comments

Comments
 (0)