|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83066 - in sandbox/SOC/2011/checks: boost/checks libs/checks/doc libs/checks/test
From: pierre.talbot.6114_at_[hidden]
Date: 2013-02-21 12:19:51
Author: trademark
Date: 2013-02-21 12:19:50 EST (Thu, 21 Feb 2013)
New Revision: 83066
URL: http://svn.boost.org/trac/boost/changeset/83066
Log:
Add size checking policies code.
Add entry in the reference section.
Add test for check digit encoder.
Update tests for mod97-10.
Added:
sandbox/SOC/2011/checks/boost/checks/size_check.hpp (contents, props changed)
Text files modified:
sandbox/SOC/2011/checks/boost/checks/checksum.hpp | 2
sandbox/SOC/2011/checks/libs/checks/doc/reference.qbk | 18 ++++++++++++++++
sandbox/SOC/2011/checks/libs/checks/test/core_test.cpp | 45 +++++++++++++++++++++++++++++++++++++--
3 files changed, 61 insertions(+), 4 deletions(-)
Modified: sandbox/SOC/2011/checks/boost/checks/checksum.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/checksum.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/checksum.hpp 2013-02-21 12:19:50 EST (Thu, 21 Feb 2013)
@@ -64,7 +64,7 @@
static typename iterator<Range>::type end(Range &x)
{
return boost::end(x);
- }
+ }
};
struct no_size_policy
Added: sandbox/SOC/2011/checks/boost/checks/size_check.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/size_check.hpp 2013-02-21 12:19:50 EST (Thu, 21 Feb 2013)
@@ -0,0 +1,55 @@
+// Boost checks/size_check.hpp header file
+// (C) Copyright Pierre Talbot 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
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_CHECK_SIZE_CHECK_HPP
+#define BOOST_CHECK_SIZE_CHECK_HPP
+
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
+#include <exception>
+
+namespace boost {
+ namespace checks{
+
+class size_failure_exception : public std::exception
+{
+public:
+ virtual const char * what() const throw()
+ {
+ return "Unexpected size of the sequence.";
+ }
+};
+
+struct size_failure_error_code_policy
+{
+ static void fail(){}
+};
+
+template <class Exception = size_failure_exception>
+struct size_failure_exception_policy
+{
+ static void fail()
+ {
+ throw Exception;
+ }
+};
+
+template <size_t N, class SizeFailurePolicy = size_failure_error_code_policy>
+struct size_checking
+{
+ static const size_t size = N;
+ typedef SizeFailurePolicy size_failure_policy;
+};
+
+struct no_size_checking{};
+
+} // namespace checks
+} // namespace boost
+
+#endif // BOOST_CHECK_SIZE_CHECK_HPP
Modified: sandbox/SOC/2011/checks/libs/checks/doc/reference.qbk
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/doc/reference.qbk (original)
+++ sandbox/SOC/2011/checks/libs/checks/doc/reference.qbk 2013-02-21 12:19:50 EST (Thu, 21 Feb 2013)
@@ -380,6 +380,24 @@
[endsect][/section:checkdigit Check digit]
+[section:traversal_type no_size_checking]
+[endsect][/section:traversal_type no_size_checking]
+
+[section:traversal_type size_checking]
+[endsect][/section:traversal_type size_checking]
+
+[section:traversal_type size_failure_error_code_policy]
+[endsect][/section:traversal_type size_failure_error_code_policy]
+
+[section:traversal_type size_failure_exception_policy]
+[endsect][/section:traversal_type size_failure_exception_policy]
+
+[section:traversal_type size_failure_exception]
+[endsect][/section:traversal_type size_failure_exception]
+
+[section:traversal_type Traversal type]
+[endsect][/section:traversal_type Traversal type]
+
[section:traversal_type Traversal type]
[endsect][/section:traversal_type Traversal type]
Modified: sandbox/SOC/2011/checks/libs/checks/test/core_test.cpp
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/test/core_test.cpp (original)
+++ sandbox/SOC/2011/checks/libs/checks/test/core_test.cpp 2013-02-21 12:19:50 EST (Thu, 21 Feb 2013)
@@ -20,7 +20,7 @@
#include <boost/checks/checkdigit.hpp>
#include <boost/checks/modulus10.hpp>
#include <boost/checks/modulus11.hpp>
-#include <boost/checks/modulus97.hpp>
+#include <boost/checks/modulus97_10.hpp>
#include <boost/checks/type_adaptor.hpp>
BOOST_AUTO_TEST_SUITE(core_tests)
@@ -41,7 +41,7 @@
BOOST_AUTO_TEST_CASE(mod10_inv_checkdigit_test)
{
using namespace boost::checks;
- mod10_inv_checkdigit c;
+ mod10_inv_basic_checkdigit c;
char results_expected[] = {'0', '9', '8', '7', '6', '5', '4', '3', '2', '1'};
@@ -67,7 +67,7 @@
BOOST_AUTO_TEST_CASE(mod11_inv_checkdigit_test)
{
using namespace boost::checks;
- mod11_inv_checkdigit c;
+ mod11_inv_basic_checkdigit c;
char results_expected[] = {'0', 'X', '9', '8', '7', '6', '5', '4', '3', '2', '1'};
@@ -90,6 +90,45 @@
}
}
+BOOST_AUTO_TEST_CASE(checkdigit_encoder_test)
+{
+ using namespace boost::checks;
+ char c = '0';
+ int i = 0;
+
+ checkdigit_encoder<> encoder;
+
+ for(; i < 10; ++i, ++c)
+ {
+ BOOST_CHECK_EQUAL(encoder(i), c);
+ }
+ BOOST_CHECK_THROW(encoder(i), boost::bad_lexical_cast);
+
+ checkdigit_encoder<std::string> string_encoder;
+ for(i = 0; i < 100; ++i)
+ {
+ std::string res = boost::lexical_cast<std::string>(i);
+ BOOST_CHECK_EQUAL(string_encoder(i), res);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(checkdigitx_encoder_test)
+{
+ using namespace boost::checks;
+ char c = '0';
+ int i = 0;
+
+ checkdigitx_encoder encoder;
+
+ for(; i < 10; ++i, ++c)
+ {
+ BOOST_CHECK_EQUAL(encoder(i), c);
+ }
+ BOOST_CHECK_EQUAL(encoder(i), 'X');
+ ++i;
+ BOOST_CHECK_THROW(encoder(i), boost::bad_lexical_cast);
+}
+
BOOST_AUTO_TEST_CASE(type_adaptor_test)
{
using namespace boost::checks;
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