|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76994 - in sandbox/SOC/2011/checks: boost/checks libs/checks/test
From: pierre.talbot.6114_at_[hidden]
Date: 2012-02-12 11:34:31
Author: trademark
Date: 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
New Revision: 76994
URL: http://svn.boost.org/trac/boost/changeset/76994
Log:
The computation of checkdigit don't try to cast in a good return type anymore. We return a std::size_t for single checkdigit check or std::pair<std::size_t, std::size_t> for 2 checkdigits check. Remove the translate_exception, not anymore needed.
Removed:
sandbox/SOC/2011/checks/boost/checks/limits.hpp
sandbox/SOC/2011/checks/boost/checks/translation_exception.hpp
Text files modified:
sandbox/SOC/2011/checks/boost/checks/amex.hpp | 5 -
sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp | 14 ++---
sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 74 ++++++++++++++++++++-----------
sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp | 38 ++++++++--------
sandbox/SOC/2011/checks/boost/checks/ean.hpp | 6 +-
sandbox/SOC/2011/checks/boost/checks/isbn.hpp | 4
sandbox/SOC/2011/checks/boost/checks/luhn.hpp | 4
sandbox/SOC/2011/checks/boost/checks/mastercard.hpp | 4
sandbox/SOC/2011/checks/boost/checks/modulus10.hpp | 6 -
sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 24 ++-------
sandbox/SOC/2011/checks/boost/checks/modulus97.hpp | 31 +++---------
sandbox/SOC/2011/checks/boost/checks/upc.hpp | 4
sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp | 19 ++------
sandbox/SOC/2011/checks/boost/checks/visa.hpp | 4
sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp | 2
sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp | 91 ++++++++++++++++++++++-----------------
16 files changed, 161 insertions(+), 169 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-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,5 +1,5 @@
// Boost checks/amex.hpp header file
-// (C) Copyright Pierre Talbot 2011
+// (C) Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
@@ -33,7 +33,6 @@
namespace boost {
namespace checks{
-
/*!
\brief Validate a sequence according to the amex_check_algorithm type.
@@ -68,7 +67,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_amex(const check_range& check_seq)
+std::size_t compute_amex(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<luhn_algorithm, AMEX_SIZE, boost::checks::basic_checkdigit>(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-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,5 +1,5 @@
// Boost checks/basic_check_algorithm.hpp header file ------------------------------------//
-// (C) Copyright Pierre Talbot 2011
+// (C) Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
@@ -19,8 +19,6 @@
#endif
#include <cstddef> // std::size_t
-#include <boost/lexical_cast.hpp>
-#include <boost/checks/translation_exception.hpp>
namespace boost{
namespace checks{
@@ -82,10 +80,9 @@
\remarks This function should be overloaded if you want to compute the check digit of a sequence.
*/
- template <typename checkdigit>
- static checkdigit compute_checkdigit(std::size_t checksum)
+ static std::size_t compute_checkdigit(std::size_t checksum)
{
- return checkdigit();
+ return std::size_t();
}
/*!
@@ -101,10 +98,9 @@
\remarks This function should be overloaded if you want your algorithm to compute more than one check digit (through it works for just one check digit too).
*/
- template <typename checkdigits_iter>
- static checkdigits_iter compute_multicheckdigit(std::size_t checksum, checkdigits_iter checkdigits)
+ static std::pair<std::size_t, std::size_t> compute_multicheckdigit(std::size_t checksum)
{
- return checkdigits;
+ return std::pair<std::size_t, std::size_t>();
}
/*!
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-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,5 +1,5 @@
// Boost checks/basic_checks.hpp header file
-// (C) Copyright Pierre Talbot 2011
+// (C) Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
@@ -18,15 +18,12 @@
#include <cstddef> // std::size_t
-#include <boost/checks/translation_exception.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/checks/limits.hpp>
-
#include <boost/checks/detail/sequence_counter.hpp>
namespace boost {
namespace checks{
+static const std::size_t bad_sequence = -1;
/*!
\brief Run through a sequence and calculate the checksum with the algorithm policy class.
@@ -44,13 +41,13 @@
\returns The checksum of the sequence calculated with algorithm.
*/
template <typename algorithm,
- typename size_contract,
+ std::size_t size_expected,
typename seq_iterator,
typename counter_type>
std::size_t compute_checksum(seq_iterator seq_begin, seq_iterator seq_end, counter_type &counter)
{
std::size_t checksum = 0;
- for(; seq_begin != seq_end && !size_contract::reach_one_past_the_end(*counter); ++seq_begin)
+ for(; seq_begin != seq_end && *counter < size_expected; ++seq_begin)
{
if(!algorithm::skip(*seq_begin))
{
@@ -59,7 +56,26 @@
++counter;
}
}
- size_contract::respect_size_contract(*counter);
+ if(*counter != size_expected || seq_begin != seq_end)
+ return bad_sequence;
+ return checksum;
+}
+
+template <typename algorithm,
+ typename seq_iterator,
+ typename counter_type>
+std::size_t compute_checksum(seq_iterator seq_begin, seq_iterator seq_end, counter_type &counter)
+{
+ std::size_t checksum = 0;
+ for(; seq_begin != seq_end; ++seq_begin)
+ {
+ if(!algorithm::skip(*seq_begin))
+ {
+ std::size_t value = algorithm::convert(*seq_begin);
+ checksum = algorithm::process(checksum, value, *counter);
+ ++counter;
+ }
+ }
return checksum;
}
@@ -81,7 +97,7 @@
bool check_sequence(seq_iterator seq_begin, seq_iterator seq_end)
{
boost::checks::detail::simple_counter::type counter = boost::checks::detail::simple_counter()();
- std::size_t checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end, counter);
+ std::size_t checksum = compute_checksum<algorithm>(seq_begin, seq_end, counter);
return algorithm::validate_checksum(checksum);
}
@@ -105,8 +121,10 @@
bool check_sequence(seq_iterator seq_begin, seq_iterator seq_end)
{
boost::checks::detail::simple_counter::type counter = boost::checks::detail::simple_counter()();
- std::size_t checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end, counter);
- return algorithm::validate_checksum(checksum);
+ std::size_t checksum = compute_checksum<algorithm, size_expected>(seq_begin, seq_end, counter);
+ if(checksum != bad_sequence)
+ return algorithm::validate_checksum(checksum);
+ return false;
}
/*!
@@ -125,12 +143,12 @@
template <typename algorithm,
typename checkdigit,
typename seq_iterator>
-typename seq_iterator::value_type compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
+std::size_t compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
typename counter_type::type counter = counter_type()();
- std::size_t checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end, counter);
- return algorithm::template compute_checkdigit<typename seq_iterator::value_type>(checksum);
+ std::size_t checksum = compute_checksum<algorithm>(seq_begin, seq_end, counter);
+ return algorithm::compute_checkdigit(checksum);
}
/*!
@@ -151,12 +169,14 @@
std::size_t size_expected,
typename checkdigit,
typename seq_iterator>
-typename seq_iterator::value_type compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
+std::size_t compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
typename counter_type::type counter = counter_type()();
- std::size_t checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end, counter);
- return algorithm::template compute_checkdigit<typename seq_iterator::value_type>(checksum);
+ std::size_t checksum = compute_checksum<algorithm, size_expected>(seq_begin, seq_end, counter);
+ if(checksum != size_expected)
+ return algorithm::compute_checkdigit(checksum);
+ return bad_sequence;
}
/*!
@@ -177,14 +197,13 @@
*/
template <typename algorithm,
typename checkdigit,
- typename seq_iterator,
- typename checkdigit_iterator>
-checkdigit_iterator compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end, checkdigit_iterator checkdigits)
+ typename seq_iterator>
+std::pair<std::size_t, std::size_t> compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end)
{
typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
typename counter_type::type counter = counter_type()();
- std::size_t checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end, counter);
- return algorithm::compute_multicheckdigit(checksum, checkdigits);
+ std::size_t checksum = compute_checksum<algorithm>(seq_begin, seq_end, counter);
+ return algorithm::compute_multicheckdigit(checksum);
}
/*!
@@ -206,14 +225,15 @@
template <typename algorithm,
std::size_t size_expected,
typename checkdigit,
- typename seq_iterator,
- typename checkdigit_iterator>
-checkdigit_iterator compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end, checkdigit_iterator checkdigits)
+ typename seq_iterator>
+std::pair<std::size_t, std::size_t> compute_multicheckdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
typename counter_type::type counter = counter_type()();
- std::size_t checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end, counter);
- return algorithm::compute_multicheckdigit(checksum, checkdigits);
+ std::size_t checksum = compute_checksum<algorithm, size_expected>(seq_begin, seq_end, counter);
+ if(checksum != bad_sequence)
+ return algorithm::compute_multicheckdigit(checksum);
+ return std::pair<std::size_t, std::size_t>(bad_sequence, bad_sequence);
}
} // namespace checks
Modified: sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,6 +1,6 @@
// Boost checks/checks_fwd.hpp header file
-// (C)Copyright Pierre Talbot 2011
+// (C)Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0.(See
// accompanying file LICENSE_1_0.txt or copy at
@@ -81,10 +81,10 @@
bool check_luhn(const check_range& check_seq);
template <size_t size_expected, typename check_range>
-typename boost::range_value<check_range>::type compute_luhn(const check_range& check_seq);
+std::size_t compute_luhn(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_luhn(const check_range& check_seq);
+std::size_t compute_luhn(const check_range& check_seq);
// Verhoeff
@@ -95,10 +95,10 @@
bool check_verhoeff(const check_range& check_seq);
template <size_t size_expected, typename check_range>
-typename boost::range_value<check_range>::type compute_verhoeff(const check_range& check_seq);
+std::size_t compute_verhoeff(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_verhoeff(const check_range& check_seq);
+std::size_t compute_verhoeff(const check_range& check_seq);
// Modulus 11
@@ -109,10 +109,10 @@
bool check_modulus11(const check_range& check_seq);
template <size_t size_expected, typename check_range>
-typename boost::range_value<check_range>::type compute_modulus11(const check_range& check_seq);
+std::size_t compute_modulus11(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_modulus11(const check_range& check_seq);
+std::size_t compute_modulus11(const check_range& check_seq);
// Modulus 97-10(ISO/IEC 7064:2003)
@@ -122,11 +122,11 @@
template <typename check_range>
bool check_mod97_10(const check_range& check_seq);
-template <size_t size_expected, typename check_range, typename checkdigits_iter>
-checkdigits_iter compute_mod97_10(const check_range& check_seq, checkdigits_iter mod97_checkdigits);
+template <size_t size_expected, typename check_range>
+std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq);
-template <typename check_range, typename checkdigits_iter>
-checkdigits_iter compute_mod97_10(const check_range& check_seq, checkdigits_iter mod97_checkdigits);
+template <typename check_range>
+std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq);
// EAN-13 and EAN-8
@@ -134,13 +134,13 @@
bool check_ean13(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_ean13(const check_range& check_seq);
+std::size_t compute_ean13(const check_range& check_seq);
template <typename check_range>
bool check_ean8(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_ean8(const check_range& check_seq);
+std::size_t compute_ean8(const check_range& check_seq);
// IBSN-10 and ISBN-13
@@ -148,13 +148,13 @@
bool check_isbn10(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_isbn10(const check_range& check_seq);
+std::size_t compute_isbn10(const check_range& check_seq);
template <typename check_range>
bool check_isbn13(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_isbn13(const check_range& check_seq);
+std::size_t compute_isbn13(const check_range& check_seq);
// UPC-A
@@ -162,7 +162,7 @@
bool check_upca(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_upca(const check_range& check_seq);
+std::size_t compute_upca(const check_range& check_seq);
// American Express
@@ -171,7 +171,7 @@
bool check_amex(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_amex(const check_range& check_seq);
+std::size_t compute_amex(const check_range& check_seq);
// VISA
@@ -179,7 +179,7 @@
bool check_visa(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_visa(const check_range& check_seq);
+std::size_t compute_visa(const check_range& check_seq);
// Mastercard
@@ -187,7 +187,7 @@
bool check_mastercard(const check_range& check_seq);
template <typename check_range>
-typename boost::range_value<check_range>::type compute_mastercard(const check_range& check_seq);
+std::size_t compute_mastercard(const check_range& check_seq);
}} // namespace boost namespace checks
Modified: sandbox/SOC/2011/checks/boost/checks/ean.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/ean.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/ean.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,5 +1,5 @@
// Boost checks/ean.hpp header file
-// (C) Copyright Pierre Talbot 2011
+// (C) Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
@@ -78,7 +78,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_ean13(const check_range& check_seq)
+std::size_t compute_ean13(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<ean_algorithm, EAN13_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
@@ -115,7 +115,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_ean8(const check_range& check_seq)
+std::size_t compute_ean8(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<ean_algorithm, EAN8_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
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-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -73,7 +73,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_isbn13 (const check_range& check_seq)
+std::size_t compute_isbn13 (const check_range& check_seq)
{
return boost::checks::compute_checkdigit<isbn13_algorithm, EAN13_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
@@ -110,7 +110,7 @@
\returns The check digit. The check digit is in the range [0..9,X].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_isbn10(const check_range& check_seq)
+std::size_t compute_isbn10(const check_range& check_seq)
{
return boost::checks::compute_modulus11<ISBN10_SIZE>(check_seq);
}
Deleted: sandbox/SOC/2011/checks/boost/checks/limits.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/limits.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
+++ (empty file)
@@ -1,95 +0,0 @@
-// Boost checks/limits.hpp header file ------------------------------------//
-// (C) Copyright Pierre Talbot 2011
-// Distributed under the Boost Software License, Version 1.0. (See
-// accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt
-// See http://www.boost.org for updates, documentation, and revision history.
-
-/*! \file
- \brief Provides two types of size contract to manage the expected size of the check sequence.
-*/
-
-#ifndef BOOST_CHECK_LIMITS_HPP
-#define BOOST_CHECK_LIMITS_HPP
-
-#ifdef _MSC_VER
- #pragma once
-#endif
-
-#include <cstddef>
-#include <boost/static_assert.hpp>
-
-namespace boost{
- namespace checks{
-
-/*! \class strict_size_contract
- \brief This is a contract class used to verify that a sequence has the expected size.
-
- \tparam expected_size The expected size of the sequence. (Expected_size > 0, enforced with static assert).
- \tparam exception_size_failure If the size is not respected an exception_size_failure exception will be thrown. Default exception class is std::invalid_argument.
-*/
-template <std::size_t expected_size, class exception_size_failure = std::invalid_argument>
-struct strict_size_contract
-{
- /*! \fn static void respect_size_contract(const std::size_t valid_value_counter)
- \brief Enforce the size contract.
-
- \param valid_value_counter Number of valid values in the sequence.
- \throws exception_size_failure If the terms of the contract are not respected. (valid_value_counter != expected_size).
- */
- 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)
- throw exception_size_failure("Too few or too many valid values in the sequence!") ;
- }
-
- /*! \fn static bool reach_one_past_the_end(const std::size_t valid_value_counter)
- \brief Tells if the expected interval of value [0..n) is outstripped.
-
- \param valid_value_counter Number of valid values in the sequence already counted.
- \returns true if valid_value_counter is one past the end of the expected size, else false.
- */
- static bool reach_one_past_the_end(std::size_t valid_value_counter)
- {
- BOOST_STATIC_ASSERT_MSG( expected_size > 0 , "The expected size must be greater than 0!" );
- return valid_value_counter > expected_size;
- }
-};
-
-/*! \class no_null_size_contract
- \brief This is a contract class used to verify that a sequence does not have a size of zero.
-
- \tparam exception_size_failure If the size is null, a exception_size_failure exception will be thrown. Default exception class is std::invalid_argument.
-*/
-template <class exception_size_failure = std::invalid_argument>
-struct no_null_size_contract
-{
-/*! \fn static void respect_size_contract(const std::size_t valid_value_counter)
- \brief Enforce the size contract.
-
- \param valid_value_counter Number of valid values in the sequence.
- \throws exception_size_failure if the terms of the contract are not respected. (valid_value_counter == 0).
- */
- static void respect_size_contract(std::size_t valid_value_counter)
- {
- if( valid_value_counter == 0 )
- throw exception_size_failure("No valid value in this sequence!") ;
- }
-
-/*! \fn static bool reach_one_past_the_end(const std::size_t valid_value_counter)
- \brief Warns if the expected interval of value [0..n) is exceeded.
-
- \param valid_value_counter Number of valid values in the sequence already counted.
- \returns false.
- */
- static bool reach_one_past_the_end(std::size_t /* valid_value_counter */)
- {
- return false;
- }
-};
-
-}} // namespace boost namespace checks
-
-
-#endif // BOOST_CHECKS_LIMITS_HPP
Modified: sandbox/SOC/2011/checks/boost/checks/luhn.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/luhn.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/luhn.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -126,7 +126,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <size_t size_expected, typename check_range>
-typename boost::range_value<check_range>::type compute_luhn(const check_range& check_seq)
+std::size_t compute_luhn(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<luhn_algorithm, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
@@ -145,7 +145,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_luhn (const check_range& check_seq)
+std::size_t compute_luhn (const check_range& check_seq)
{
return boost::checks::compute_checkdigit<luhn_algorithm, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
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-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,5 +1,5 @@
// Boost checks/mastercard.hpp header file
-// (C)Copyright Pierre Talbot 2011
+// (C)Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0.(See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
@@ -65,7 +65,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_mastercard(const check_range& check_seq)
+std::size_t compute_mastercard(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<luhn_algorithm, MASTERCARD_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
Modified: sandbox/SOC/2011/checks/boost/checks/modulus10.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/modulus10.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/modulus10.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -17,7 +17,6 @@
#endif
#include <cstddef>
-#include <boost/lexical_cast.hpp>
#include <boost/checks/weighted_sum.hpp>
namespace boost{
@@ -55,10 +54,9 @@
\returns The modulus 10 check digit of checksum.
*/
- template <typename checkdigit>
- static checkdigit compute_checkdigit(std::size_t checksum)
+ static std::size_t compute_checkdigit(std::size_t checksum)
{
- return boost::lexical_cast<checkdigit>((10 - checksum % 10) % 10);
+ return ((10 - checksum % 10) % 10);
}
};
Modified: sandbox/SOC/2011/checks/boost/checks/modulus11.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/modulus11.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/modulus11.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,5 +1,5 @@
// Boost checks/modulus11.hpp header file ------------------------------------//
-// (C)Copyright Pierre Talbot 2011
+// (C)Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0.(See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
@@ -19,8 +19,7 @@
#include <boost/range/rbegin.hpp>
#include <boost/range/rend.hpp>
#include <boost/range/iterator_range.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/checks/translation_exception.hpp>
+
#include <boost/checks/weight.hpp>
#include <boost/checks/basic_checks.hpp>
#include <boost/checks/weighted_sum.hpp>
@@ -95,21 +94,10 @@
\returns The modulus 11 check digit of checksum. 'X' is returned if the check digit value is equal to 10.
*/
- template <typename checkdigit>
- static checkdigit compute_checkdigit(std::size_t checksum)
+ static std::size_t compute_checkdigit(std::size_t checksum)
{
- return translate_checkdigit<checkdigit>((11 - checksum % 11)% 11);
+ return ((11 - checksum % 11)% 11);
}
-
-protected:
- template <typename checkdigit>
- static checkdigit translate_checkdigit(std::size_t _checkdigit)
- {
- if(_checkdigit == 10)
- return static_cast<checkdigit>('X');
- return boost::lexical_cast<checkdigit>(_checkdigit);
- }
-
};
/*!
@@ -174,7 +162,7 @@
\returns The check digit. The check digit is in the range [0..9,X].
*/
template <std::size_t size_expected, typename check_range>
-typename boost::range_value<check_range>::type compute_modulus11(const check_range& check_seq)
+std::size_t compute_modulus11(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<mod11_algorithm, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
@@ -193,7 +181,7 @@
\returns The check digit. The check digit is in the range [0..9,X].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_modulus11(const check_range& check_seq)
+std::size_t compute_modulus11(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<mod11_algorithm, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
Modified: sandbox/SOC/2011/checks/boost/checks/modulus97.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/modulus97.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/modulus97.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,6 +1,6 @@
// Boost checks/modulus97.hpp header file
-// (C) Copyright Pierre Talbot 2011
+// (C) Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
@@ -18,8 +18,6 @@
#endif
#include <boost/preprocessor/repetition.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/checks/translation_exception.hpp>
#include <boost/checks/weight.hpp>
#include <boost/checks/weighted_sum.hpp>
@@ -66,22 +64,11 @@
\returns An iterator initialized at one pass to the end of the two check digits.
*/
- template <typename checkdigits_iter>
- static checkdigits_iter compute_multicheckdigit(std::size_t checksum, checkdigits_iter checkdigits)
+ static std::pair<std::size_t, std::size_t> compute_multicheckdigit(std::size_t checksum)
{
std::size_t mod97_checkdigits = 98 - (checksum % 97);
- try
- {
- *checkdigits = boost::lexical_cast<typename checkdigits_iter::value_type>(mod97_checkdigits / 10);
- ++checkdigits;
- *checkdigits = boost::lexical_cast<typename checkdigits_iter::value_type>(mod97_checkdigits % 10);
- ++checkdigits;
- }
- catch( boost::bad_lexical_cast ){
- throw boost::checks::translation_exception();
- }
- return checkdigits;
+ return std::pair<std::size_t, std::size_t>(mod97_checkdigits / 10, mod97_checkdigits % 10);
}
};
@@ -188,10 +175,10 @@
\returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
*/
-template <size_t size_expected, typename check_range, typename checkdigits_iter>
-checkdigits_iter compute_mod97_10(const check_range& check_seq, checkdigits_iter mod97_checkdigits)
+template <size_t size_expected, typename check_range>
+std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq)
{
- return boost::checks::compute_multicheckdigit<mod97_10_algorithm, size_expected, mod97_10_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
+ return boost::checks::compute_multicheckdigit<mod97_10_algorithm, mod97_10_checkdigit, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -209,10 +196,10 @@
\returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
*/
-template <typename check_range, typename checkdigits_iter>
-checkdigits_iter compute_mod97_10(const check_range& check_seq, checkdigits_iter mod97_checkdigits)
+template <typename check_range>
+std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq)
{
- return boost::checks::compute_multicheckdigit<mod97_10_algorithm, mod97_10_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
+ return boost::checks::compute_multicheckdigit<mod97_10_algorithm, mod97_10_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
Deleted: sandbox/SOC/2011/checks/boost/checks/translation_exception.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/translation_exception.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
+++ (empty file)
@@ -1,32 +0,0 @@
-// Boost checks/translation_exception.hpp header file
-// (C) Copyright Pierre Talbot 2011
-// Distributed under the Boost Software License, Version 1.0. (See
-// accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt
-// See http://www.boost.org for updates, documentation, and revision history.
-
-/*! \file
- \brief This file provides an exception class used when the translation of a value failed.
-*/
-
-#ifndef BOOST_CHECKS_translation_EXCEPTION_HPP
-#define BOOST_CHECKS_translation_EXCEPTION_HPP
-
-#ifdef _MSC_VER
- #pragma once
-#endif
-
-#include <exception>
-
-namespace boost{
- namespace checks{
-/*! \class translation_exception
- \brief This class provides support for translation failure. For example, sequence value into integer, or integer into check digit type.
-*/
- class translation_exception : public std::exception
- {
- };
-
-}} // namespace boost namespace checks
-
-#endif // BOOST_CHECKS_translation_EXCEPTION_HPP
\ No newline at end of file
Modified: sandbox/SOC/2011/checks/boost/checks/upc.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/upc.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/upc.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,5 +1,5 @@
// Boost checks/upc.hpp header file
-// (C) Copyright Pierre Talbot 2011
+// (C) Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
@@ -74,7 +74,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_upca(const check_range& check_seq)
+std::size_t compute_upca(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<upc_algorithm, UPCA_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
Modified: sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,5 +1,5 @@
// Boost checks/verhoeff.hpp header file ------------------------------------//
-// (C)Copyright Pierre Talbot 2011
+// (C)Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0.(See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
@@ -23,7 +23,6 @@
#include <boost/range/rend.hpp>
#include <boost/range/iterator_range.hpp>
-#include <boost/checks/translation_exception.hpp>
#include <boost/checks/weight.hpp>
#include <boost/checks/checkdigit.hpp>
#include <boost/checks/basic_checks.hpp>
@@ -103,19 +102,11 @@
\returns The Verhoeff check digit of checksum.
*/
- template <typename checkdigit>
- static checkdigit compute_checkdigit(std::size_t checksum)
+ static std::size_t compute_checkdigit(std::size_t checksum)
{
static const unsigned char inv[] = {0, 4, 3, 2, 1, 5, 6, 7, 8, 9};
- try
- {
- return boost::lexical_cast<checkdigit>(inv[checksum]);
- }
- catch(boost::bad_lexical_cast)
- {
- throw boost::checks::translation_exception();
- }
+ return inv[checksum];
}
};
@@ -171,7 +162,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <size_t size_expected, typename check_range>
-typename boost::range_value<check_range>::type compute_verhoeff(const check_range& check_seq)
+std::size_t compute_verhoeff(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<verhoeff_algorithm, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
@@ -190,7 +181,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_verhoeff(const check_range& check_seq)
+std::size_t compute_verhoeff(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<verhoeff_algorithm, boost::checks::basic_checkdigit>(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-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,5 +1,5 @@
// Boost checks/visa.hpp header file
-// (C)Copyright Pierre Talbot 2011
+// (C)Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0.(See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
@@ -65,7 +65,7 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::range_value<check_range>::type compute_visa(const check_range& check_seq)
+std::size_t compute_visa(const check_range& check_seq)
{
return boost::checks::compute_checkdigit<luhn_algorithm, VISA_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
Modified: sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp 2012-02-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,5 +1,5 @@
// Boost checks/weighted_sum.hpp header file
-// (C) Copyright Pierre Talbot 2011
+// (C) Copyright Pierre Talbot 2011 - 2012
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
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-12 11:34:29 EST (Sun, 12 Feb 2012)
@@ -1,6 +1,6 @@
//! \file test_checks.cpp
-// Copyright Pierre Talbot 2011.
+// Copyright Pierre Talbot 2011 - 2012.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
@@ -20,6 +20,7 @@
#include <iomanip>
#include <boost/test/unit_test.hpp> // Enhanced for unit_test framework autolink
+#include <boost/test/included/unit_test.hpp>
#include <boost/checks/luhn.hpp>
#include <boost/checks/verhoeff.hpp>
@@ -33,6 +34,8 @@
#include <boost/checks/mastercard.hpp>
#include <boost/checks/checks_fwd.hpp> // Forward declarations.
+#include <utility>
+
#include "alteration_test.hpp"
#include "transposition_test.hpp"
@@ -44,9 +47,6 @@
BOOST_AUTO_TEST_SUITE(use_cases_tests)
-// IIN : Issuer Identification Number.
-// MII : Major Industry Identifier.
-
BOOST_AUTO_TEST_CASE(visa_tests)
{
std::string visa_valid = "4417 1234 5678 9113";
@@ -54,12 +54,12 @@
std::string visa_big_size_failure = "44417 1234 5678 9113"; // An extra '4' digit.
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_EQUAL(boost::checks::check_visa(visa_low_size_failure), false);
+ BOOST_CHECK_EQUAL(boost::checks::check_visa(visa_big_size_failure), false);
std::string visa_valid_without_checkdigit = "4417 1234 5678 911";
-
- BOOST_CHECK_EQUAL(boost::checks::compute_visa(visa_valid_without_checkdigit), '3');
+ std::size_t valid_checkdigit = 3;
+ BOOST_CHECK_EQUAL(boost::checks::compute_visa(visa_valid_without_checkdigit), valid_checkdigit);
}
BOOST_AUTO_TEST_CASE(amex_tests)
@@ -69,12 +69,13 @@
std::string amex_big_size_failure = "33782 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_EQUAL(boost::checks::check_amex(amex_low_size_failure), false);
+ BOOST_CHECK_EQUAL(boost::checks::check_amex(amex_big_size_failure), false);
std::string amex_valid_without_checkdigit = "3782 822463 1000";
+ std::size_t valid_checkdigit = 5;
- BOOST_CHECK_EQUAL(boost::checks::compute_amex(amex_valid_without_checkdigit), '5');
+ BOOST_CHECK_EQUAL(boost::checks::compute_amex(amex_valid_without_checkdigit), valid_checkdigit);
}
BOOST_AUTO_TEST_CASE(mastercard_tests)
@@ -84,12 +85,13 @@
std::string mastercard_big_size_failure = "51505 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_EQUAL(boost::checks::check_mastercard(mastercard_low_size_failure), false);
+ BOOST_CHECK_EQUAL(boost::checks::check_mastercard(mastercard_big_size_failure), false);
std::string mastercard_valid_without_checkdigit = "5105 1051 0510 510";
-
- BOOST_CHECK_EQUAL(boost::checks::compute_mastercard(mastercard_valid_without_checkdigit), '0');
+ std::size_t valid_checkdigit = 0;
+
+ BOOST_CHECK_EQUAL(boost::checks::compute_mastercard(mastercard_valid_without_checkdigit), valid_checkdigit);
}
BOOST_AUTO_TEST_CASE(ean_tests)
@@ -99,22 +101,26 @@
std::string ean13_big_size_failure = "412983 130028";
BOOST_CHECK(boost::checks::check_ean13(ean13_valid));
- BOOST_CHECK_THROW(boost::checks::check_ean13(ean13_low_size_failure), std::invalid_argument);
- BOOST_CHECK_THROW(boost::checks::check_ean13(ean13_big_size_failure), std::invalid_argument);
+ BOOST_CHECK_EQUAL(boost::checks::check_ean13(ean13_low_size_failure), false);
+ BOOST_CHECK_EQUAL(boost::checks::check_ean13(ean13_big_size_failure), false);
std::string ean13_valid_without_checkdigit = "5 412983 13002";
- BOOST_CHECK_EQUAL(boost::checks::compute_ean13(ean13_valid_without_checkdigit), '8');
+ std::size_t valid_checkdigit = 8;
+
+ BOOST_CHECK_EQUAL(boost::checks::compute_ean13(ean13_valid_without_checkdigit), valid_checkdigit);
std::string ean8_valid = "5449 1472"; // Bottle of Coke.
std::string ean8_low_size_failure = "5449 472";
std::string ean8_big_size_failure = "05449 1472";
BOOST_CHECK(boost::checks::check_ean8(ean8_valid));
- BOOST_CHECK_THROW(boost::checks::check_ean8(ean8_low_size_failure), std::invalid_argument);
- BOOST_CHECK_THROW(boost::checks::check_ean8(ean8_big_size_failure), std::invalid_argument);
+ BOOST_CHECK_EQUAL(boost::checks::check_ean8(ean8_low_size_failure), false);
+ BOOST_CHECK_EQUAL(boost::checks::check_ean8(ean8_big_size_failure), false);
std::string ean8_valid_without_checkdigit = "5449 147";
- BOOST_CHECK_EQUAL(boost::checks::compute_ean8(ean8_valid_without_checkdigit), '2');
+ valid_checkdigit = 2;
+
+ BOOST_CHECK_EQUAL(boost::checks::compute_ean8(ean8_valid_without_checkdigit), valid_checkdigit);
}
BOOST_AUTO_TEST_CASE(upc_tests)
@@ -124,11 +130,13 @@
std::string upca_big_size_failure = "0036000291452";
BOOST_CHECK(boost::checks::check_upca(upca_valid));
- BOOST_CHECK_THROW(boost::checks::check_upca(upca_low_size_failure), std::invalid_argument);
- BOOST_CHECK_THROW(boost::checks::check_upca(upca_big_size_failure), std::invalid_argument);
+ BOOST_CHECK_EQUAL(boost::checks::check_upca(upca_low_size_failure), false);
+ BOOST_CHECK_EQUAL(boost::checks::check_upca(upca_big_size_failure), false);
std::string upca_valid_without_checkdigit = "03600029145";
- BOOST_CHECK_EQUAL(boost::checks::compute_upca(upca_valid_without_checkdigit), '2');
+ std::size_t valid_checkdigit = 2;
+
+ BOOST_CHECK_EQUAL(boost::checks::compute_upca(upca_valid_without_checkdigit), valid_checkdigit);
}
BOOST_AUTO_TEST_CASE(isbn_tests)
@@ -141,29 +149,33 @@
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_EQUAL(boost::checks::check_isbn13(isbn13_low_size_failure), false);
+ BOOST_CHECK_EQUAL(boost::checks::check_isbn13(isbn13_big_size_failure), false);
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::size_t valid_checkdigit = 4;
+
+ BOOST_CHECK_EQUAL(boost::checks::compute_isbn13(isbn13_valid_without_checkdigit), valid_checkdigit);
+ BOOST_CHECK_NE(boost::checks::compute_isbn13(isbn13_not_valid_without_checkdigit), valid_checkdigit);
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);
+ BOOST_CHECK_EQUAL(boost::checks::check_isbn10(isbn10_low_size_failure), false);
+ BOOST_CHECK_EQUAL(boost::checks::check_isbn10(isbn10_big_size_failure), false);
std::string isbn10_valid_without_checkdigit = "0-201-70073-";
- BOOST_CHECK_EQUAL(boost::checks::compute_isbn10(isbn10_valid_without_checkdigit), '5');
+ valid_checkdigit = 5;
+
+ BOOST_CHECK_EQUAL(boost::checks::compute_isbn10(isbn10_valid_without_checkdigit), valid_checkdigit);
}
BOOST_AUTO_TEST_CASE(mod97_10_tests)
{
- std::string mod97_10_valid = "510007547061111462"; // From a Belgium IBAN
+ std::string mod97_10_valid = "510007547061111462"; // From a Belgian IBAN
std::string mod97_10_not_valid = "511007547061111462";
std::string mod97_10_low_size_failure = "51007547061111462";
std::string mod97_10_big_size_failure = "5100007547061111462";
@@ -176,13 +188,14 @@
std::string mod97_10_valid_without_checkdigits = "5100075470611114";
std::string mod97_10_not_valid_without_checkdigits = "5110075470611114";
- std::string valid_check_digits = "00";
- boost::checks::compute_mod97_10(mod97_10_valid_without_checkdigits, valid_check_digits.begin());
- BOOST_CHECK_EQUAL(valid_check_digits, "62");
-
- std::string invalid_check_digits = "00";
- boost::checks::compute_mod97_10(mod97_10_not_valid_without_checkdigits, invalid_check_digits.begin());
- BOOST_CHECK_NE(invalid_check_digits, "62");
+ std::pair<std::size_t, std::size_t> checkdigits(6, 2);
+ std::pair<std::size_t, std::size_t> valid_check_digits = boost::checks::compute_mod97_10(mod97_10_valid_without_checkdigits);
+ BOOST_CHECK_EQUAL(valid_check_digits.first, checkdigits.first);
+ BOOST_CHECK_EQUAL(valid_check_digits.second, checkdigits.second);
+
+ std::pair<std::size_t, std::size_t> invalid_check_digits = boost::checks::compute_mod97_10(mod97_10_not_valid_without_checkdigits);
+ BOOST_CHECK_NE(invalid_check_digits.first, checkdigits.first);
+ BOOST_CHECK_NE(invalid_check_digits.second, checkdigits.second);
}
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