|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73905 - sandbox/SOC/2011/checks/libs/checks/test
From: pierre.talbot.6114_at_[hidden]
Date: 2011-08-18 18:21:12
Author: trademark
Date: 2011-08-18 18:21:11 EDT (Thu, 18 Aug 2011)
New Revision: 73905
URL: http://svn.boost.org/trac/boost/changeset/73905
Log:
Add ISBN10 and ISBN13 tests.
Text files modified:
sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
Modified: sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp (original)
+++ sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp 2011-08-18 18:21:11 EDT (Thu, 18 Aug 2011)
@@ -139,6 +139,42 @@
BOOST_CHECK_EQUAL ( boost::checks::compute_upca (upca_valid_without_checkdigit), '2' ) ;
}
+BOOST_AUTO_TEST_CASE(isbn_tests)
+{
+
+ std::string isbn13_valid = "978-0-13-235088-4" ; // Clean Code: a handbook of agile software craftsmanship, Robert C. Martin.
+ std::string isbn13_not_valid = "979-0-13-235088-4" ;
+ std::string isbn13_low_size_failure = "978--13-235088-4" ;
+ std::string isbn13_big_size_failure = "978-00-13-235088-4" ;
+ std::string isbn13_ean_id_failure = "977-0-13-235088-4" ;
+ std::string isbn13_ean_id_failure2 = "988-0-13-235088-4" ;
+ std::string isbn13_ean_id_failure3 = "878-0-13-235088-4" ;
+
+ BOOST_CHECK ( boost::checks::check_isbn13 (isbn13_valid) ) ;
+ BOOST_CHECK ( !boost::checks::check_isbn13 (isbn13_not_valid) ) ;
+ BOOST_CHECK_THROW ( boost::checks::check_isbn13 (isbn13_low_size_failure) , std::invalid_argument ) ;
+ BOOST_CHECK_THROW ( boost::checks::check_isbn13 (isbn13_big_size_failure) , std::invalid_argument ) ;
+ BOOST_CHECK_THROW ( boost::checks::check_isbn13 (isbn13_ean_id_failure) , std::invalid_argument ) ;
+ BOOST_CHECK_THROW ( boost::checks::check_isbn13 (isbn13_ean_id_failure2) , std::invalid_argument ) ;
+ BOOST_CHECK_THROW ( boost::checks::check_isbn13 (isbn13_ean_id_failure3) , std::invalid_argument ) ;
+
+ std::string isbn13_valid_without_checkdigit = "978-0-13-235088-" ;
+ std::string isbn13_not_valid_without_checkdigit = "979-0-13-235088-" ;
+ BOOST_CHECK_EQUAL ( boost::checks::compute_isbn13 (isbn13_valid_without_checkdigit), '4' ) ;
+ BOOST_CHECK_NE ( boost::checks::compute_isbn13 (isbn13_not_valid_without_checkdigit), '4' ) ;
+
+ std::string isbn10_valid = "0-201-70073-5" ; // The C++ Programming Language, Special Edition, Bjarne Stroustrup.
+ std::string isbn10_low_size_failure = "00-201-70073-5" ;
+ std::string isbn10_big_size_failure = "-201-70073-5" ;
+
+ BOOST_CHECK ( boost::checks::check_isbn10 (isbn10_valid) ) ;
+ BOOST_CHECK_THROW ( boost::checks::check_isbn10 (isbn10_low_size_failure) , std::invalid_argument ) ;
+ BOOST_CHECK_THROW ( boost::checks::check_isbn10 (isbn10_big_size_failure) , std::invalid_argument ) ;
+
+ std::string isbn10_valid_without_checkdigit = "0-201-70073-" ;
+ BOOST_CHECK_EQUAL ( boost::checks::compute_isbn10 (isbn10_valid_without_checkdigit), '5' ) ;
+}
+
BOOST_AUTO_TEST_SUITE_END()
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk