diff --git a/exercises/practice/isbn-verifier/.meta/test_template.tera b/exercises/practice/isbn-verifier/.meta/test_template.tera new file mode 100644 index 000000000..c51d0e82c --- /dev/null +++ b/exercises/practice/isbn-verifier/.meta/test_template.tera @@ -0,0 +1,13 @@ +use isbn_verifier::*; + +{% for test in cases %} +#[test] +#[ignore] +fn {{ test.description | snake_case }}() { + {% if test.expected %} + assert!(is_valid_isbn("{{ test.input.isbn }}")); + {% else %} + assert!(!is_valid_isbn("{{ test.input.isbn }}")); + {% endif %} +} +{% endfor -%} diff --git a/exercises/practice/isbn-verifier/.meta/tests.toml b/exercises/practice/isbn-verifier/.meta/tests.toml index 1519d218d..6d5a84599 100644 --- a/exercises/practice/isbn-verifier/.meta/tests.toml +++ b/exercises/practice/isbn-verifier/.meta/tests.toml @@ -1,10 +1,56 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[0caa3eac-d2e3-4c29-8df8-b188bc8c9292] +description = "valid isbn" + +[19f76b53-7c24-45f8-87b8-4604d0ccd248] +description = "invalid isbn check digit" + +[4164bfee-fb0a-4a1c-9f70-64c6a1903dcd] +description = "valid isbn with a check digit of 10" + +[3ed50db1-8982-4423-a993-93174a20825c] +description = "check digit is a character other than X" + +[9416f4a5-fe01-4b61-a07b-eb75892ef562] +description = "invalid check digit in isbn is not treated as zero" + +[c19ba0c4-014f-4dc3-a63f-ff9aefc9b5ec] +description = "invalid character in isbn is not treated as zero" + +[28025280-2c39-4092-9719-f3234b89c627] +description = "X is only valid as a check digit" + +[f6294e61-7e79-46b3-977b-f48789a4945b] +description = "valid isbn without separating dashes" + +[185ab99b-3a1b-45f3-aeec-b80d80b07f0b] +description = "isbn without separating dashes and X as check digit" + +[7725a837-ec8e-4528-a92a-d981dd8cf3e2] +description = "isbn without check digit and dashes" + +[47e4dfba-9c20-46ed-9958-4d3190630bdf] +description = "too long isbn and no dashes" [737f4e91-cbba-4175-95bf-ae630b41fb60] description = "too short isbn" +[5458a128-a9b6-4ff8-8afb-674e74567cef] +description = "isbn without check digit" + +[70b6ad83-d0a2-4ca7-a4d5-a9ab731800f7] +description = "check digit of X should not be used for 0" + [94610459-55ab-4c35-9b93-ff6ea1a8e562] description = "empty isbn" @@ -12,4 +58,10 @@ description = "empty isbn" description = "input is 9 characters" [ed6e8d1b-382c-4081-8326-8b772c581fec] -description = "invalid characters are not ignored" +description = "invalid characters are not ignored after checking length" + +[daad3e58-ce00-4395-8a8e-e3eded1cdc86] +description = "invalid characters are not ignored before checking length" + +[fb5e48d8-7c03-4bfb-a088-b101df16fdc3] +description = "input is too long but contains a valid isbn" diff --git a/exercises/practice/isbn-verifier/tests/isbn-verifier.rs b/exercises/practice/isbn-verifier/tests/isbn-verifier.rs index 6a831d51c..73f27f406 100644 --- a/exercises/practice/isbn-verifier/tests/isbn-verifier.rs +++ b/exercises/practice/isbn-verifier/tests/isbn-verifier.rs @@ -1,63 +1,67 @@ -use isbn_verifier::is_valid_isbn; +use isbn_verifier::*; #[test] -fn valid() { +fn valid_isbn() { assert!(is_valid_isbn("3-598-21508-8")); } #[test] #[ignore] -fn invalid_check_digit() { +fn invalid_isbn_check_digit() { assert!(!is_valid_isbn("3-598-21508-9")); } #[test] #[ignore] -fn valid_check_digit_of_10() { +fn valid_isbn_with_a_check_digit_of_10() { assert!(is_valid_isbn("3-598-21507-X")); } #[test] #[ignore] -fn invalid_character_as_check_digit() { +fn check_digit_is_a_character_other_than_x() { assert!(!is_valid_isbn("3-598-21507-A")); } #[test] #[ignore] -fn invalid_character_in_isbn() { +fn invalid_check_digit_in_isbn_is_not_treated_as_zero() { + assert!(!is_valid_isbn("4-598-21507-B")); +} + +#[test] +#[ignore] +fn invalid_character_in_isbn_is_not_treated_as_zero() { assert!(!is_valid_isbn("3-598-P1581-X")); } #[test] #[ignore] -#[allow(non_snake_case)] -fn invalid_isbn_with_invalid_X() { +fn x_is_only_valid_as_a_check_digit() { assert!(!is_valid_isbn("3-598-2X507-9")); } #[test] #[ignore] -fn valid_isbn_without_dashes() { +fn valid_isbn_without_separating_dashes() { assert!(is_valid_isbn("3598215088")); } #[test] #[ignore] -#[allow(non_snake_case)] -fn valid_isbn_without_dashes_and_X_as_check() { +fn isbn_without_separating_dashes_and_x_as_check_digit() { assert!(is_valid_isbn("359821507X")); } #[test] #[ignore] -fn invalid_isbn_without_dashes_and_no_check_digit() { +fn isbn_without_check_digit_and_dashes() { assert!(!is_valid_isbn("359821507")); } #[test] #[ignore] -fn invalid_isbn_without_dashes_and_too_long() { +fn too_long_isbn_and_no_dashes() { assert!(!is_valid_isbn("3598215078X")); } @@ -69,26 +73,13 @@ fn too_short_isbn() { #[test] #[ignore] -fn invalid_isbn_without_check_digit() { +fn isbn_without_check_digit() { assert!(!is_valid_isbn("3-598-21507")); } #[test] #[ignore] -fn valid_digits_invalid_length() { - assert!(!is_valid_isbn("35982150881")); -} - -#[test] -#[ignore] -fn special_characters() { - assert!(!is_valid_isbn("!@#%!@")); -} - -#[test] -#[ignore] -#[allow(non_snake_case)] -fn invalid_isbn_with_check_digit_X_instead_of_0() { +fn check_digit_of_x_should_not_be_used_for_0() { assert!(!is_valid_isbn("3-598-21515-X")); } @@ -106,12 +97,18 @@ fn input_is_9_characters() { #[test] #[ignore] -fn invalid_characters_are_not_ignored() { +fn invalid_characters_are_not_ignored_after_checking_length() { assert!(!is_valid_isbn("3132P34035")); } #[test] #[ignore] -fn too_long_but_contains_a_valid_isbn() { +fn invalid_characters_are_not_ignored_before_checking_length() { + assert!(!is_valid_isbn("3598P215088")); +} + +#[test] +#[ignore] +fn input_is_too_long_but_contains_a_valid_isbn() { assert!(!is_valid_isbn("98245726788")); } diff --git a/problem-specifications b/problem-specifications index 3d9837ec2..238b8b090 160000 --- a/problem-specifications +++ b/problem-specifications @@ -1 +1 @@ -Subproject commit 3d9837ec2953f7e678b63da6af82eb6db5035dd0 +Subproject commit 238b8b090c331273eaccd5daba06df6f62863342