defmodule IsbnVerifierTest do use ExUnit.Case test "valid isbn number" do assert IsbnVerifier.isbn?("3-598-21508-8") end test "invalid isbn check digit" do refute IsbnVerifier.isbn?("3-598-21508-9") end test "valid isbn number with a check digit of 10" do assert IsbnVerifier.isbn?("3-598-21507-X") end test "check digit is a character other than X" do refute IsbnVerifier.isbn?("3-598-21507-A") end test "check digit in isbn is not treated as zero" do refute IsbnVerifier.isbn?("4-598-21507-B") end test "invalid character in isbn" do refute IsbnVerifier.isbn?("3-598-P1581-X") end test "X is only valid as a check digit" do refute IsbnVerifier.isbn?("3-598-2X507-9") end test "valid isbn without separating dashes" do assert IsbnVerifier.isbn?("3598215088") end test "isbn without separating dashes and X as check digit" do assert IsbnVerifier.isbn?("359821507X") end test "isbn without check digit and dashes" do refute IsbnVerifier.isbn?("359821507") end test "too long isbn and no dashes" do refute IsbnVerifier.isbn?("3598215078X") end test "too short isbn" do refute IsbnVerifier.isbn?("00") end test "isbn without check digit" do refute IsbnVerifier.isbn?("3-598-21507") end test "too long isbn" do refute IsbnVerifier.isbn?("3-598-21507-XA") end test "check digit of X should not be used for 0" do refute IsbnVerifier.isbn?("3-598-21515-X") end test "input is 9 characters" do refute IsbnVerifier.isbn?("134456729") end test "invalid characters are not ignored" do refute IsbnVerifier.isbn?("3132P34035") end test "invalid characters are not ignored before checking length" do refute IsbnVerifier.isbn?("3598P215088") end test "input is too long but contains a valid isbn" do refute IsbnVerifier.isbn?("98245726788") end # Test cases from international ISBN to test variable dash placement # Adapted from https://en.wikipedia.org/wiki/International_Standard_Book_Number#Registrant_element test "Qatar NCCAH, Doha" do assert IsbnVerifier.isbn?("99921-58-10-7") end test "Singapore World Scientific" do assert IsbnVerifier.isbn?("9971-5-0210-0") end test "Greece Sigma Publications" do assert IsbnVerifier.isbn?("960-425-059-0") end test "Czech Republic; Slovakia Taita Publishers" do assert IsbnVerifier.isbn?("80-902734-1-6") end test "Brazil Companhia das Letras" do assert IsbnVerifier.isbn?("85-359-0277-5") end test "English-speaking area Simon Wallenberg Press" do assert IsbnVerifier.isbn?("1-84356-028-3") end test "English-speaking area Scribner" do assert IsbnVerifier.isbn?("0-684-84328-5") end test "English-speaking area Frederick Ungar" do assert IsbnVerifier.isbn?("0-8044-2957-X") end test "English-speaking area J. A. Allen & Co." do assert IsbnVerifier.isbn?("0-85131-041-9") end test "English-speaking area Edupedia Publications Pvt Ltd." do assert IsbnVerifier.isbn?("93-86954-21-4") end test "English-speaking area Willmann-Bell" do assert IsbnVerifier.isbn?("0-943396-04-2") end test "English-speaking area KT Publishing" do assert IsbnVerifier.isbn?("0-9752298-0-X") end end