Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76988 - in sandbox/SOC/2011/checks: boost/checks libs/checks/test
From: pierre.talbot.6114_at_[hidden]
Date: 2012-02-11 16:33:42


Author: trademark
Date: 2012-02-11 16:33:41 EST (Sat, 11 Feb 2012)
New Revision: 76988
URL: http://svn.boost.org/trac/boost/changeset/76988

Log:
Remove the tests and code aimed to check if prefix (or pattern) in number are corrects such as the prefix 978 for ISBN13. It's beyond the scoop of this library where the focus is on the computation of check digit
Text files modified:
   sandbox/SOC/2011/checks/boost/checks/amex.hpp | 28 ++--------------------------
   sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp | 15 ---------------
   sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 23 +++++------------------
   sandbox/SOC/2011/checks/boost/checks/isbn.hpp | 21 +--------------------
   sandbox/SOC/2011/checks/boost/checks/limits.hpp | 2 +-
   sandbox/SOC/2011/checks/boost/checks/mastercard.hpp | 28 ++--------------------------
   sandbox/SOC/2011/checks/boost/checks/visa.hpp | 27 ++-------------------------
   sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp | 24 ------------------------
   8 files changed, 13 insertions(+), 155 deletions(-)

Modified: sandbox/SOC/2011/checks/boost/checks/amex.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/amex.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/amex.hpp 2012-02-11 16:33:41 EST (Sat, 11 Feb 2012)
@@ -32,30 +32,6 @@
 namespace boost {
     namespace checks{
 
-/*! \class amex_algorithm
- \brief This class can be used to compute or validate checksum with the Luhn algorithm, but filter following the Amex pattern.
-
- \tparam checkdigit_size Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
-*/
-
-struct amex_algorithm : boost::checks::luhn_algorithm
-{
- /*!
- \brief Verify that a number matches the Amex pattern.
-
- \param current_valid_value is the current valid value analysed.
- \param current_value_position is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
-
- \throws std::invalid_argument if the first character is not equal to 3 or the second is not equal to 4 or 7. The exception contains a descriptive message of what was expected.
-
- \remarks This function use the macro AMEX_SIZE to find the real position from left to right.
- */
- template <typename value_type>
- static bool require(const value_type &value, std::size_t value_pos)
- {
- return (AMEX_SIZE - value_pos != 1 || value == '3') && (AMEX_SIZE - value_pos != 2 || value == '4' || value == '7');
- }
-};
 
 /*!
     \brief Validate a sequence according to the amex_check_algorithm type.
@@ -73,7 +49,7 @@
 template <typename check_range>
 bool check_amex (const check_range& check_seq)
 {
- return boost::checks::check_sequence<amex_algorithm, AMEX_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_algorithm, AMEX_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -93,7 +69,7 @@
 template <typename check_range>
 typename boost::range_value<check_range>::type compute_amex(const check_range& check_seq)
 {
- return boost::checks::compute_checkdigit<amex_algorithm, AMEX_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, AMEX_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 

Modified: sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp 2012-02-11 16:33:41 EST (Sat, 11 Feb 2012)
@@ -122,21 +122,6 @@
     return std::size_t();
   }
 
- /*!
- \brief Filtering of a valid value according to its position.
-
- \post Do nothing.
-
- \param current_valid_value is the current valid value analysed.
- \param current_value_position is the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
-
- \remarks This function should be overloaded if you want to filter the values with their positions.
- */
- template <typename value_type>
- static bool require(const value_type&, std::size_t)
- {
- return true;
- }
 };
 
 

Modified: sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp 2012-02-11 16:33:41 EST (Sat, 11 Feb 2012)
@@ -50,28 +50,15 @@
 std::size_t compute_checksum(seq_iterator seq_begin, seq_iterator seq_end, counter_type &counter)
 {
   std::size_t checksum = 0;
- bool error = false;
- for(; seq_begin != seq_end && !error && !size_contract::reach_one_past_the_end(*counter); ++seq_begin)
+ for(; seq_begin != seq_end && !size_contract::reach_one_past_the_end(*counter); ++seq_begin)
   {
- try
+ if(!algorithm::skip(*seq_begin))
     {
- if(!algorithm::skip(*seq_begin))
- {
- if(!algorithm::require(*seq_begin, *counter))
- error = true;
- else
- {
- std::size_t value = algorithm::convert(*seq_begin);
- checksum = algorithm::process(checksum, value, *counter);
- ++counter;
- }
- }
- }
- catch(boost::checks::translation_exception){
+ std::size_t value = algorithm::convert(*seq_begin);
+ checksum = algorithm::process(checksum, value, *counter);
+ ++counter;
     }
   }
- if(error)
- throw std::invalid_argument("");
   size_contract::respect_size_contract(*counter);
   return checksum;
 }

Modified: sandbox/SOC/2011/checks/boost/checks/isbn.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/isbn.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/isbn.hpp 2012-02-11 16:33:41 EST (Sat, 11 Feb 2012)
@@ -38,26 +38,7 @@
 
     \tparam checkdigit_size Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
 */
-struct isbn13_algorithm : boost::checks::modulus10_algorithm<boost::checks::ean_weight>
-{
- /*!
- \brief Verify that a number matches the ISBN-13 pattern.
-
- \param value is the current valid value analysed.
- \param value_position is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
-
- \throws std::invalid_argument if the three first character are not equal to 978 or 979. The exception contains a descriptive message of what was expected.
-
- \remarks This function use the macro EAN13_SIZE to find the real position from left to right.
- */
- template <typename value_type>
- static bool require(const value_type &value, std::size_t value_pos)
- {
- return (EAN13_SIZE - value_pos != 1 || value == '9') &&
- (EAN13_SIZE - value_pos != 2 || value == '7') &&
- (EAN13_SIZE - value_pos != 3 || value == '8' || value == '9');
- }
-};
+typedef boost::checks::modulus10_algorithm<boost::checks::ean_weight> isbn13_algorithm;
 
 /*!
     \brief Validate a sequence according to the isbn13_check_algorithm type.

Modified: sandbox/SOC/2011/checks/boost/checks/limits.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/limits.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/limits.hpp 2012-02-11 16:33:41 EST (Sat, 11 Feb 2012)
@@ -40,7 +40,7 @@
   static void respect_size_contract(std::size_t valid_value_counter)
   {
     BOOST_STATIC_ASSERT_MSG( expected_size > 0 , "The expected size must be greater than 0!" );
- if( valid_value_counter != expected_size )
+ if(valid_value_counter != expected_size)
       throw exception_size_failure("Too few or too many valid values in the sequence!") ;
   }
 

Modified: sandbox/SOC/2011/checks/boost/checks/mastercard.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/mastercard.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/mastercard.hpp 2012-02-11 16:33:41 EST (Sat, 11 Feb 2012)
@@ -30,30 +30,6 @@
 namespace boost {
     namespace checks{
 
-/*! \class mastercard_algorithm
- \brief This class can be used to compute or validate checksum with the Luhn algorithm, but filter following the Mastercard pattern.
-
- \tparam checkdigit_size Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
-*/
-struct mastercard_algorithm : boost::checks::luhn_algorithm
-{
- /*!
- \brief Verify that a number matches the Mastercard pattern.
-
- \param current_valid_value is the current valid value analysed.
- \param current_value_position is the number of valid values already counted(the current value is not included).\n This is also the position(above the valid values)of the current value analysed(0 <= valid_value_counter < n).
-
- \throws std::invalid_argument if the first character is not equal to 5 or the second is not between 1 and 5. The exception contains a descriptive message of what was expected.
-
- \remarks This function use the macro MASTERCARD_SIZE to find the real position from left to right.
- */
- template <typename value_type>
- static bool require(const value_type &value, std::size_t value_pos)
- {
- return (MASTERCARD_SIZE - value_pos != 1 || value == '5') && (MASTERCARD_SIZE - value_pos != 2 || (value >= '1' && value <= '5'));
- }
-};
-
 /*!
     \brief Validate a sequence according to the mastercard_check_algorithm type.
 
@@ -70,7 +46,7 @@
 template <typename check_range>
 bool check_mastercard(const check_range& check_seq)
 {
- return boost::checks::check_sequence<mastercard_algorithm, MASTERCARD_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_algorithm, MASTERCARD_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -90,7 +66,7 @@
 template <typename check_range>
 typename boost::range_value<check_range>::type compute_mastercard(const check_range& check_seq)
 {
- return boost::checks::compute_checkdigit<mastercard_algorithm, MASTERCARD_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, MASTERCARD_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 

Modified: sandbox/SOC/2011/checks/boost/checks/visa.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/visa.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/visa.hpp 2012-02-11 16:33:41 EST (Sat, 11 Feb 2012)
@@ -30,29 +30,6 @@
 namespace boost {
     namespace checks{
 
-/*! \class visa_algorithm
- \brief This class can be used to compute or validate checksum with the Luhn algorithm, but filter following the Visa pattern.
-
- \tparam checkdigit_size Helper functions to provide same behavior on a sequence with and without check digits. No "real" value in the sequence will be skipped.
-*/
-struct visa_algorithm : boost::checks::luhn_algorithm
-{
- /*!
- \brief Verify that a number matches the Visa pattern.
-
- \param current_valid_value is the current valid value analysed.
- \param current_value_position is the number of valid value already counted(the current value is not included).\n This is also the position(above the valid values)of the current value analysed(0 <= valid_value_counter < n).
-
- \throws std::invalid_argument if the first character is not equal to 4. The exception contains a descriptive message of what was expected.
-
- \remarks This function use the macro VISA_SIZE to find the real position from left to right.
- */
- template <typename value_type>
- static bool require(const value_type &value, std::size_t value_pos)
- {
- return VISA_SIZE - value_pos != 1 || value == '4';
- }
-};
 
 /*!
     \brief Validate a sequence according to the visa_check_algorithm type.
@@ -70,7 +47,7 @@
 template <typename check_range>
 bool check_visa(const check_range& check_seq)
 {
- return boost::checks::check_sequence<visa_algorithm, VISA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_algorithm, VISA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -90,7 +67,7 @@
 template <typename check_range>
 typename boost::range_value<check_range>::type compute_visa(const check_range& check_seq)
 {
- return boost::checks::compute_checkdigit<visa_algorithm, VISA_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, VISA_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 

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 2012-02-11 16:33:41 EST (Sat, 11 Feb 2012)
@@ -52,18 +52,14 @@
   std::string visa_valid = "4417 1234 5678 9113";
   std::string visa_low_size_failure = "417 1234 5678 9113"; // A missing digit '4'.
   std::string visa_big_size_failure = "44417 1234 5678 9113"; // An extra '4' digit.
- std::string visa_mii_failure = "3417 1234 5678 9113";
 
   BOOST_CHECK(boost::checks::check_visa(visa_valid));
   BOOST_CHECK_THROW(boost::checks::check_visa(visa_low_size_failure), std::invalid_argument);
   BOOST_CHECK_THROW(boost::checks::check_visa(visa_big_size_failure), std::invalid_argument);
- BOOST_CHECK_THROW(boost::checks::check_visa(visa_mii_failure), std::invalid_argument);
 
   std::string visa_valid_without_checkdigit = "4417 1234 5678 911";
- std::string visa_mii_failure_without_checkdigit = "3417 1234 5678 911";
 
   BOOST_CHECK_EQUAL(boost::checks::compute_visa(visa_valid_without_checkdigit), '3');
- BOOST_CHECK_THROW(boost::checks::compute_visa(visa_mii_failure_without_checkdigit), std::invalid_argument);
 }
 
 BOOST_AUTO_TEST_CASE(amex_tests)
@@ -71,21 +67,14 @@
   std::string amex_valid = "3782 822463 10005";
   std::string amex_low_size_failure = "378 822463 10005";
   std::string amex_big_size_failure = "33782 822463 10005";
- std::string amex_mii_failure = "4782 822463 10005";
- std::string amex_iin_failure = "3882 822463 10005";
 
   BOOST_CHECK(boost::checks::check_amex(amex_valid));
   BOOST_CHECK_THROW(boost::checks::check_amex(amex_low_size_failure), std::invalid_argument);
   BOOST_CHECK_THROW(boost::checks::check_amex(amex_big_size_failure), std::invalid_argument);
- BOOST_CHECK_THROW(boost::checks::check_amex(amex_mii_failure), std::invalid_argument);
- BOOST_CHECK_THROW(boost::checks::check_amex(amex_iin_failure), std::invalid_argument);
 
   std::string amex_valid_without_checkdigit = "3782 822463 1000";
- std::string amex_mii_failure_without_checkdigit = "4782 822463 1000";
- std::string amex_iin_failure_without_checkdigit = "3682 822463 1000";
 
   BOOST_CHECK_EQUAL(boost::checks::compute_amex(amex_valid_without_checkdigit), '5');
- BOOST_CHECK_THROW(boost::checks::compute_amex(amex_mii_failure_without_checkdigit), std::invalid_argument);
 }
 
 BOOST_AUTO_TEST_CASE(mastercard_tests)
@@ -93,21 +82,14 @@
   std::string mastercard_valid = "5105 1051 0510 5100";
   std::string mastercard_low_size_failure = "515 1051 0510 5100";
   std::string mastercard_big_size_failure = "51505 1051 0510 5100";
- std::string mastercard_mii_failure = "4105 1051 0510 5100";
- std::string mastercard_iin_failure = "5005 1051 0510 5100";
 
   BOOST_CHECK(boost::checks::check_mastercard(mastercard_valid));
   BOOST_CHECK_THROW(boost::checks::check_mastercard(mastercard_low_size_failure), std::invalid_argument);
   BOOST_CHECK_THROW(boost::checks::check_mastercard(mastercard_big_size_failure), std::invalid_argument);
- BOOST_CHECK_THROW(boost::checks::check_mastercard(mastercard_mii_failure), std::invalid_argument);
- BOOST_CHECK_THROW(boost::checks::check_mastercard(mastercard_iin_failure), std::invalid_argument);
 
   std::string mastercard_valid_without_checkdigit = "5105 1051 0510 510";
- std::string mastercard_mii_failure_without_checkdigit = "6105 1051 0510 510";
- std::string mastercard_iin_failure_without_checkdigit = "5605 1051 0510 510";
 
   BOOST_CHECK_EQUAL(boost::checks::compute_mastercard(mastercard_valid_without_checkdigit), '0');
- BOOST_CHECK_THROW(boost::checks::compute_mastercard(mastercard_mii_failure_without_checkdigit), std::invalid_argument);
 }
 
 BOOST_AUTO_TEST_CASE(ean_tests)
@@ -156,17 +138,11 @@
   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-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