source: project/release/4/isbn/trunk/tests/run.scm @ 22169

Last change on this file since 22169 was 22169, checked in by Christian Kellermann, 9 years ago

isbn: welcome the openlibrary api

File size: 2.4 KB
Line 
1(use test)
2
3(include "../isbn.scm")
4(import isbn)
5(include "../openlibrary.scm")
6(import openlibrary)
7
8
9(test-group "ISBN-10"
10            (test "normal isbn" #t (valid-isbn? "3895760633"))
11            (test "isbn with X as check digit" #t (valid-isbn? "052103311X"))
12            (test "dashes as separators" #t (valid-isbn? "0-521-03311-X"))
13            (test "spaces as separators" #t (valid-isbn? "0 521 03311 X"))
14            (test "spaces and dashes (should fail but we are forgiving"
15                  #t (valid-isbn? "0-521-03311 X"))
16            (test "uncommon separator places"
17                  #t (valid-isbn? "0-5--2-1--03-3-1-1X"))
18            (test "wrong number" #f (valid-isbn? "1123122312")))
19
20(test-group "ISBN-13"
21            (test "normal isbn-13" #t (valid-isbn? "9780387202488"))
22            (test "isbn with 0 check digit (10)"
23                  #t (valid-isbn? "9783937514390")))
24
25(test-group "ISBN classification"
26            (test "ISBN-10" 10 (isbn-type "3895760633"))
27            (test "ISBN-13" 13 (isbn-type "978-8-17525-766-5"))
28            (test "Invalid ISBN" #f (isbn-type "1123122312")))
29
30(test-group "ISBN upgrade"
31            (test "normal isbn" "978-8-17525-766-5" (isbn10->isbn13 "817525766-0"))
32            (test "isbn with X as check digit" "978-0-52103-311-4" (isbn10->isbn13 "052103311X")))
33
34(test-group "normalize-isbn"
35            (test "Normalize ISBN-13 (with 10 check digit)"
36                  "9783937514390" (normalize-isbn "978-3-937514-39-0"))
37            (test "Normalize ISBN-10 (with 10 check digit)"
38                  "052103311X" (normalize-isbn "0-521-03311-X")))
39
40(define literate-programming
41  '((title . "Literate programming")
42    (authors ("Donald Knuth"))
43    (publisher ("Center for the Study of Language and Information"))
44    (publishing-date . "1992")
45    (number-of-pages . 368)
46    (cover-urls
47     ("small" . "http://covers.openlibrary.org/b/id/715228-S.jpg")
48     ("large" . "http://covers.openlibrary.org/b/id/715228-L.jpg")
49     ("medium" . "http://covers.openlibrary.org/b/id/715228-M.jpg"))
50    (isbn-numbers (("0937073806" "0937073814")))))
51
52(define literate-programming-simplified
53  '((title . "Literate programming")
54    (authors ("Donald Knuth"))
55    (publishing-date . "1992")
56    (number-of-pages . 368)))
57
58(test-group "openlibrary.org API"
59            (test "Requesting entry for ISBN-10 09370-73890-6"
60                  literate-programming
61                  (isbn->alist "0937073806"))
62            (test "Requesting same ISBN with restricted return values"
63                  literate-programming-simplified
64                  (isbn->alist "0937073806" '(title authors publishing-date number-of-pages))))
Note: See TracBrowser for help on using the repository browser.