Skip to content

Commit 624e6fc

Browse files
committed
Add tests for ISBNs with invalid check digits
1 parent 1f8d59c commit 624e6fc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/models/detector/standard_identifiers_test.rb

+26
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ class StandardIdentifiersTest < ActiveSupport::TestCase
2323
end
2424
end
2525

26+
test 'ISBN-10 examples with incorrect check digits are not detected' do
27+
# from wikipedia
28+
samples = ['99921-58-10-1', '9971-5-0210-1', '960-425-059-1', '80-902734-1-1', '85-359-0277-1',
29+
'1-84356-028-1', '0-684-84328-1', '0-8044-2957-1', '0-85131-041-1', '93-86954-21-1', '0-943396-04-1',
30+
'0-9752298-0-1']
31+
32+
samples.each do |isbn|
33+
actual = Detector::StandardIdentifiers.new(isbn).detections
34+
35+
assert_nil(actual[:isbn])
36+
end
37+
end
38+
2639
test 'ISBN-13 examples' do
2740
samples = ['978-99921-58-10-4', '978-9971-5-0210-2', '978-960-425-059-2', '978-80-902734-1-2',
2841
'978-85-359-0277-8', '978-1-84356-028-9', '978-0-684-84328-5', '978-0-8044-2957-3',
@@ -36,6 +49,19 @@ class StandardIdentifiersTest < ActiveSupport::TestCase
3649
end
3750
end
3851

52+
test 'ISBN-13 examples with incorrect check digits are not detected' do
53+
samples = ['978-99921-58-10-1', '978-9971-5-0210-1', '978-960-425-059-1', '978-80-902734-1-1',
54+
'978-85-359-0277-1', '978-1-84356-028-1', '978-0-684-84328-1', '978-0-8044-2957-1',
55+
'978-0-85131-041-2', '978-93-86954-21-1', '978-0-943396-04-1', '978-0-9752298-0-1', '9798531132171',
56+
'9798577456831', '979-8-886-45174-1', '9781319145441']
57+
58+
samples.each do |isbn|
59+
actual = Detector::StandardIdentifiers.new(isbn).detections
60+
61+
assert_nil(actual[:isbn])
62+
end
63+
end
64+
3965
test 'not ISBNs' do
4066
samples = ['orange cats like popcorn', '1234-6798', 'another ISBN not found here', '99921-58-10-1', '979-8-886-45174-1']
4167

0 commit comments

Comments
 (0)