Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73787 - sandbox/SOC/2011/checks/libs/checks/test
From: pierre.talbot.6114_at_[hidden]
Date: 2011-08-15 15:15:13


Author: trademark
Date: 2011-08-15 15:15:13 EDT (Mon, 15 Aug 2011)
New Revision: 73787
URL: http://svn.boost.org/trac/boost/changeset/73787

Log:
A generic transposition function that returns the number of transpostions that failed.
Added:
   sandbox/SOC/2011/checks/libs/checks/test/transposition_test.hpp (contents, props changed)

Added: sandbox/SOC/2011/checks/libs/checks/test/transposition_test.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/libs/checks/test/transposition_test.hpp 2011-08-15 15:15:13 EDT (Mon, 15 Aug 2011)
@@ -0,0 +1,43 @@
+//! \file transposition_test.hpp
+
+// Copyright Pierre Talbot 2011.
+
+// Use, modification and distribution are subject to 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)
+
+
+#ifndef BOOST_CHECK_TEST_TRANSPOSITION_HPP
+#define BOOST_CHECK_TEST_TRANSPOSITION_HPP
+
+template <typename functor>
+unsigned int transposition( const functor &compute_checkdigit )
+{
+ unsigned int transposition_failures = 0 ;
+
+ std::string sequence = "00" ;
+ std::string transpose_seq = "00" ;
+
+ for(int i=0; i <= 9; ++i )
+ {
+ for(int j=0; j <= 9; ++j)
+ {
+ if(i != j)
+ {
+ sequence[0] = i | '0' ;
+ sequence[1] = j | '0' ;
+
+ transpose_seq[0] = sequence[1] ;
+ transpose_seq[1] = sequence[0] ;
+
+ if( compute_checkdigit( sequence ) ==
+ compute_checkdigit( transpose_seq) )
+ ++transposition_failures ;
+ }
+ }
+ }
+ return transposition_failures ;
+}
+
+#endif // BOOST_CHECK_TEST_TRANSPOSITION_HPP
\ No newline at end of file


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