Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81010 - trunk/libs/test/test/test_datasets
From: gennadiy.rozental_at_[hidden]
Date: 2012-10-18 04:14:05


Author: rogeeff
Date: 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
New Revision: 81010
URL: http://svn.boost.org/trac/boost/changeset/81010

Log:
datasets unit test
Added:
   trunk/libs/test/test/test_datasets/
   trunk/libs/test/test/test_datasets/test_array.cpp (contents, props changed)
   trunk/libs/test/test/test_datasets/test_case_interface_test.cpp (contents, props changed)
   trunk/libs/test/test/test_datasets/test_collection.cpp (contents, props changed)
   trunk/libs/test/test/test_datasets/test_datasets.hpp (contents, props changed)
   trunk/libs/test/test/test_datasets/test_implicit.cpp (contents, props changed)
   trunk/libs/test/test/test_datasets/test_mono_grid.cpp (contents, props changed)
   trunk/libs/test/test/test_datasets/test_mono_join.cpp (contents, props changed)
   trunk/libs/test/test/test_datasets/test_mono_zip.cpp (contents, props changed)
   trunk/libs/test/test/test_datasets/test_random.cpp (contents, props changed)
   trunk/libs/test/test/test_datasets/test_singleton.cpp (contents, props changed)
   trunk/libs/test/test/test_datasets/test_xrange.cpp (contents, props changed)

Added: trunk/libs/test/test/test_datasets/test_array.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_array.cpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,65 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : tests C array based dataset
+// ***************************************************************************
+
+// Boost.Test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/monomorphic/array.hpp>
+namespace data=boost::unit_test::data;
+
+#include "test_datasets.hpp"
+
+BOOST_AUTO_TEST_CASE( test_array )
+{
+ int arr1[] = {1,2,3};
+ BOOST_CHECKA( data::make( arr1 ).size() == 3 );
+ double const arr2[] = {7.4,3.2};
+ BOOST_CHECKA( data::make( arr2 ).size() == 2 );
+
+ int arr3[] = {7,11,13,17};
+ int* ptr3 = arr3;
+ data::for_each_sample( data::make( arr3 ), check_arg_type<int>() );
+
+ int c = 0;
+ data::for_each_sample( data::make( arr3 ), [&c,ptr3](int i) {
+ BOOST_CHECKA( i == ptr3[c++] );
+ });
+
+ invocation_count ic;
+
+ ic.m_value = 0;
+ data::for_each_sample( data::make( arr3 ), ic );
+ BOOST_CHECKA( ic.m_value == 4 );
+
+ ic.m_value = 0;
+ data::for_each_sample( data::make( arr3 ), ic, 2 );
+ BOOST_CHECKA( ic.m_value == 2 );
+
+ ic.m_value = 0;
+ data::for_each_sample( data::make( arr3 ), ic, 0 );
+ BOOST_CHECKA( ic.m_value == 0 );
+
+ copy_count::value() = 0;
+ copy_count arr4[] = { copy_count(), copy_count() };
+ data::for_each_sample( data::make( arr4 ), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ copy_count const arr5[] = { copy_count(), copy_count() };
+ data::for_each_sample( data::make( arr5 ), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+}
+
+//____________________________________________________________________________//
+
+// EOF

Added: trunk/libs/test/test/test_datasets/test_case_interface_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_case_interface_test.cpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,97 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : tests singleton dataset
+// ***************************************************************************
+
+// Boost.Test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/test_case.hpp>
+#include <boost/test/data/monomorphic.hpp>
+namespace data=boost::unit_test::data;
+
+#include "test_datasets.hpp"
+
+//____________________________________________________________________________//
+
+int samples1[] = {1,2,3};
+int index1 = 0;
+
+BOOST_DATA_TEST_CASE( test_case_interface_01, samples1 )
+{
+ BOOST_CHECKA( sample == samples1[index1++] );
+}
+
+//____________________________________________________________________________//
+
+char const* samples2[] = {"qwerty","asdfg"};
+int index2 = 0;
+
+BOOST_DATA_TEST_CASE( test_case_interface_02, samples2 )
+{
+ BOOST_CHECKA( sample == samples2[index2++] );
+}
+
+//____________________________________________________________________________//
+
+int samples3[] = {7,9};
+int index3 = 0;
+
+BOOST_DATA_TEST_CASE( test_case_interface_03, data::make(samples1)+samples3 )
+{
+ if( index3 < 3 )
+ BOOST_CHECKA( sample == samples1[index3] );
+ else
+ BOOST_CHECKA( sample == samples3[index3-3] );
+
+ ++index3;
+}
+
+//____________________________________________________________________________//
+
+int index4 = 0;
+
+BOOST_DATA_TEST_CASE_N( 2, test_case_interface_04, data::make(samples2)^samples3 )
+{
+ BOOST_CHECKA( sample0 == samples2[index4] );
+ BOOST_CHECKA( sample1 == samples3[index4] );
+
+ ++index4;
+}
+
+//____________________________________________________________________________//
+
+int index5 = 0;
+
+BOOST_DATA_TEST_CASE_N( 2, test_case_interface_05, data::make(samples1) * samples2 )
+{
+ BOOST_CHECKA( sample0 == samples1[index5/2] );
+ BOOST_CHECKA( sample1 == samples2[index5%2] );
+
+ ++index5;
+}
+
+//____________________________________________________________________________//
+
+int index6 = 0;
+
+BOOST_DATA_TEST_CASE_N( 3, test_case_interface_06, data::make(samples1) * samples2 * samples3 )
+{
+ BOOST_CHECKA( sample0 == samples1[index6/4] );
+ BOOST_CHECKA( sample1 == samples2[(index6/2)%2] );
+ BOOST_CHECKA( sample2 == samples3[index6%2] );
+
+ ++index6;
+}
+
+//____________________________________________________________________________//
+
+// EOF

Added: trunk/libs/test/test/test_datasets/test_collection.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_collection.cpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,98 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : tests stl collection based dataset
+// ***************************************************************************
+
+// Boost.Test
+#include <boost/test/data/monomorphic/collection.hpp>
+
+#include <boost/test/unit_test.hpp>
+namespace data=boost::unit_test::data;
+
+#include "test_datasets.hpp"
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_collection )
+{
+ BOOST_CHECKA( data::make( std::vector<int>() ).size() == 0 );
+ BOOST_CHECKA( data::make( std::vector<int>( 3 ) ).size() == 3 );
+ BOOST_CHECKA( data::make( std::list<double>() ).size() == 0 );
+ BOOST_CHECKA( data::make( std::list<double>( 2 ) ).size() == 2 );
+
+ data::for_each_sample( data::make( std::vector<int>( 3 ) ), check_arg_type<int>() );
+ data::for_each_sample( data::make( std::list<double>( 2 ) ), check_arg_type<double>() );
+
+ invocation_count ic;
+
+ ic.m_value = 0;
+ data::for_each_sample( data::make( std::vector<int>( 3 ) ), ic );
+ BOOST_CHECKA( ic.m_value == 3 );
+
+ ic.m_value = 0;
+ data::for_each_sample( data::make( std::list<double>( 2 ) ), ic, 4 );
+ BOOST_CHECKA( ic.m_value == 2 );
+
+ ic.m_value = 0;
+ data::for_each_sample( data::make( std::vector<int>( 3 ) ), ic, 1 );
+ BOOST_CHECKA( ic.m_value == 1 );
+
+ std::vector<int> samples1;
+ samples1.push_back(5);
+ samples1.push_back(567);
+ samples1.push_back(13);
+
+ int c = 0;
+ data::for_each_sample( data::make( samples1 ), [&c,samples1](int i) {
+ BOOST_CHECKA( i == samples1[c++] );
+ });
+
+ std::list<char const*> samples2;
+ samples2.push_back("sd");
+ samples2.push_back("bg");
+ samples2.push_back( "we3eq3" );
+
+ auto it = samples2.begin();
+ data::for_each_sample( data::make( samples2 ), [&it](char const* str ) {
+ BOOST_CHECKA( str == *it++ );
+ });
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( std::vector<copy_count>( 2 ) ), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ std::vector<copy_count> samples3( 2 );
+ data::for_each_sample( data::make( samples3 ), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ std::vector<copy_count> const samples4( 2 );
+ data::for_each_sample( data::make( samples4 ), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ auto ds1 = data::make( make_copy_count_collection() );
+ BOOST_CHECKA( ds1.size() == 3 );
+ data::for_each_sample( ds1, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ auto ds2 = data::make( make_copy_count_const_collection() );
+ BOOST_CHECKA( ds2.size() == 3 );
+ data::for_each_sample( ds2, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 3 ); // !! ?? no const rvalue rev constructor for std::list
+}
+
+//____________________________________________________________________________//
+
+// EOF

Added: trunk/libs/test/test/test_datasets/test_datasets.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_datasets.hpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,168 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : datasets test helpers
+// ***************************************************************************
+
+#ifndef BOOST_TEST_TEST_DATASETS_HPP_120511ER
+#define BOOST_TEST_TEST_DATASETS_HPP_120511ER
+
+// Boost
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+
+#include <iostream>
+#include <vector>
+#include <list>
+
+class copy_count {
+public:
+ copy_count() {}
+ copy_count( copy_count const& ) { value()++; }
+ copy_count( copy_count&& ) {}
+ copy_count( copy_count const&& ) {}
+// ~copy_count() { std::cout << "~copy_count" << std::endl; }
+
+ static int& value() { static int s_value; return s_value; };
+
+ static copy_count make() { return std::move( copy_count() ); }
+ static copy_count const make_const() { return std::move( copy_count() ); }
+
+};
+
+//____________________________________________________________________________//
+
+template<typename T>
+struct check_arg_type {
+ template<typename S>
+ void operator()( S const& ) const
+ {
+ BOOST_CHECK_MESSAGE( (boost::is_same<S,T>::value), "Sample type does not match expected" );
+ }
+};
+
+//____________________________________________________________________________//
+
+template<typename T1, typename T2>
+struct check_arg_type<std::tuple<T1,T2>> {
+ template<typename S1, typename S2>
+ void operator()( S1 const&, S2 const& ) const
+ {
+ BOOST_CHECK_MESSAGE( (boost::is_same<S1,T1>::value), "S1 type does not match expected" );
+ BOOST_CHECK_MESSAGE( (boost::is_same<S2,T2>::value), "S2 type does not match expected" );
+ }
+};
+
+//____________________________________________________________________________//
+
+template<typename T1, typename T2, typename T3>
+struct check_arg_type<std::tuple<T1,T2,T3>> {
+ template<typename S1, typename S2, typename S3>
+ void operator()( S1 const&, S2 const&, S3 const& ) const
+ {
+ BOOST_CHECK_MESSAGE( (boost::is_same<S1,T1>::value), "S1 type does not match expected" );
+ BOOST_CHECK_MESSAGE( (boost::is_same<S2,T2>::value), "S2 type does not match expected" );
+ BOOST_CHECK_MESSAGE( (boost::is_same<S3,T3>::value), "S3 type does not match expected" );
+ }
+};
+
+//____________________________________________________________________________//
+
+template<typename T>
+struct check_arg_type_like {
+ template<typename S>
+ void operator()( S const& ) const
+ {
+ BOOST_CHECK_MESSAGE( (boost::is_convertible<S,T>::value), "Sample type does not match expected" );
+ }
+};
+
+//____________________________________________________________________________//
+
+template<typename T1, typename T2>
+struct check_arg_type_like<std::tuple<T1,T2>> {
+ template<typename S1, typename S2>
+ void operator()( S1 const&, S2 const& ) const
+ {
+ BOOST_CHECK_MESSAGE( (boost::is_convertible<S1,T1>::value), "S1 type does not match expected" );
+ BOOST_CHECK_MESSAGE( (boost::is_convertible<S2,T2>::value), "S2 type does not match expected" );
+ }
+};
+
+//____________________________________________________________________________//
+
+template<typename T1, typename T2, typename T3>
+struct check_arg_type_like<std::tuple<T1,T2,T3>> {
+ template<typename S1, typename S2, typename S3>
+ void operator()( S1 const&, S2 const&, S3 const& ) const
+ {
+ BOOST_CHECK_MESSAGE( (boost::is_convertible<S1,T1>::value), "S1 type does not match expected" );
+ BOOST_CHECK_MESSAGE( (boost::is_convertible<S2,T2>::value), "S2 type does not match expected" );
+ BOOST_CHECK_MESSAGE( (boost::is_convertible<S3,T3>::value), "S3 type does not match expected" );
+ }
+};
+
+//____________________________________________________________________________//
+
+struct invocation_count {
+ invocation_count() : m_value( 0 ) {}
+
+ template<typename S>
+ void operator()( S const& ) const
+ {
+ m_value++;
+ }
+ template<typename S1,typename S2>
+ void operator()( S1 const&, S2 const& ) const
+ {
+ m_value++;
+ }
+ template<typename S1,typename S2,typename S3>
+ void operator()( S1 const&, S2 const&, S3 const& ) const
+ {
+ m_value++;
+ }
+
+ mutable int m_value;
+
+private:
+ invocation_count(invocation_count const&);
+};
+
+//____________________________________________________________________________//
+
+struct print_sample {
+ template<typename T>
+ void operator()( T const& sample ) const
+ {
+ std::cout << "S has type: " << typeid(T).name() << " and value " << sample << std::endl;
+ }
+};
+
+//____________________________________________________________________________//
+
+inline std::vector<copy_count>
+make_copy_count_collection()
+{
+ return std::move( std::vector<copy_count>( 3 ) );
+}
+
+//____________________________________________________________________________//
+
+inline std::list<copy_count> const
+make_copy_count_const_collection()
+{
+ return std::move( std::list<copy_count>( 3 ) );
+}
+
+//____________________________________________________________________________//
+
+#endif // BOOST_TEST_TEST_DATASETS_HPP_120511ER

Added: trunk/libs/test/test/test_datasets/test_implicit.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_implicit.cpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,85 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : tests implicit interfaces
+// ***************************************************************************
+
+// Boost.Test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/monomorphic/singleton.hpp>
+#include <boost/test/data/monomorphic/collection.hpp>
+#include <boost/test/data/monomorphic/array.hpp>
+#include <boost/test/data/monomorphic/join.hpp>
+#include <boost/test/data/monomorphic/zip.hpp>
+namespace data=boost::unit_test::data;
+
+#include "test_datasets.hpp"
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_implicit_for_each )
+{
+ data::for_each_sample( 2, check_arg_type<int>() );
+
+ data::for_each_sample( "ch", check_arg_type<char const*>() );
+ data::for_each_sample( 2., check_arg_type<double>() );
+ data::for_each_sample( std::vector<int>( 3 ), check_arg_type<int>() );
+ data::for_each_sample( std::list<double>( 2 ), check_arg_type<double>() );
+ invocation_count ic;
+
+ ic.m_value = 0;
+ data::for_each_sample( std::vector<int>( 3 ), ic );
+ BOOST_CHECKA( ic.m_value == 3 );
+
+ ic.m_value = 0;
+ data::for_each_sample( std::list<double>( 2 ), ic, 1 );
+ BOOST_CHECKA( ic.m_value == 1 );
+
+ copy_count::value() = 0;
+ std::vector<copy_count> samples1( 2 );
+ data::for_each_sample( samples1, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ copy_count samples2[] = { copy_count(), copy_count() };
+ data::for_each_sample( samples2, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+}
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_implicit_join )
+{
+#if 0
+ auto ds = data::make( 5 );
+ BOOST_CHECKA( (1 + ds).size() == 2 );
+ BOOST_CHECKA( (ds + 1).size() == 2 );
+
+ BOOST_CHECKA( (1 + data::make( 5 )).size() == 2 );
+ BOOST_CHECKA( (data::make( 5 ) + 1).size() == 2 );
+#endif
+}
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_implicit_zip )
+{
+ auto ds = data::make( 5 );
+ BOOST_CHECKA( (1 ^ ds).size() == 1 );
+ BOOST_CHECKA( (ds ^ 1).size() == 1 );
+
+ BOOST_CHECKA( (1 ^ data::make( 5 )).size() == 1 );
+ BOOST_CHECKA( (data::make( 5 ) ^ 1).size() == 1 );
+}
+
+//____________________________________________________________________________//
+
+// EOF

Added: trunk/libs/test/test/test_datasets/test_mono_grid.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_mono_grid.cpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,143 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : tests monomorphic join
+// ***************************************************************************
+
+// Boost.Test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/monomorphic/grid.hpp>
+#include <boost/test/data/monomorphic/singleton.hpp>
+#include <boost/test/data/monomorphic/array.hpp>
+#include <boost/test/data/monomorphic/collection.hpp>
+namespace data=boost::unit_test::data;
+
+#include "test_datasets.hpp"
+
+BOOST_AUTO_TEST_CASE( test_mono_grid )
+{
+ BOOST_CHECKA( (data::make( 1 ) * data::make( 5 )).size() == 1 );
+ BOOST_CHECKA( (data::make( std::vector<int>(2) ) * data::make( std::list<float>(2) )).size() == 4 );
+ BOOST_CHECKA( (data::make( std::vector<int>(2) ) * data::make( 5. )).size() == 2 );
+ BOOST_CHECKA( (data::make( std::vector<int>(3) ) * data::make( std::list<int>(1) )).size() == 3 );
+
+ BOOST_CHECKA( (data::make( std::vector<int>(3) ) * data::make( std::list<std::string>(3) ) * data::make( 5 )).size() == 9 );
+ BOOST_CHECKA( (data::make( std::vector<int>(1) ) * data::make( std::list<int>(3) ) * data::make( 5 )).size() == 3 );
+
+
+ int arr1[] = {1,2};
+ char const* arr2[] = {"a","b"};
+ int* exp1 = arr1;
+ char const** exp2 = arr2;
+ int c = 0;
+ invocation_count ic;
+
+ auto samples1 = data::make( arr1 ) * data::make( arr2 );
+
+ BOOST_CHECKA( samples1.size() == 4 );
+
+ ic.m_value = 0;
+ data::for_each_sample( samples1, ic );
+ BOOST_CHECKA( ic.m_value == 4 );
+
+ data::for_each_sample( samples1, check_arg_type_like<std::tuple<int,char const*>>() );
+
+ c = 0;
+ data::for_each_sample( samples1, [&c,exp1,exp2](int i,char const* s) {
+ BOOST_CHECKA( i == exp1[c/2] );
+ BOOST_CHECKA( s == exp2[c%2] );
+ ++c;
+ });
+
+ std::vector<double> vec1;
+ vec1.push_back(2.1);
+ vec1.push_back(3.2);
+ vec1.push_back(4.7);
+ int arr3[] = {4,2,1};
+
+ auto samples2 = data::make( vec1 ) * data::make( "qqq" ) * data::make( arr3 );
+
+ BOOST_CHECKA( samples2.size() == 9 );
+
+ ic.m_value = 0;
+ data::for_each_sample( samples2, ic );
+ BOOST_CHECKA( ic.m_value == 9 );
+
+ data::for_each_sample( samples2, check_arg_type_like<std::tuple<double,char const*,int>>() );
+
+ c = 0;
+ int* exp3 = arr3;
+
+ data::for_each_sample( samples2, [&c,&vec1,exp3](double a1,char const* a2,int a3) {
+ BOOST_CHECKA( a1 == vec1[c/3] );
+ BOOST_CHECK_EQUAL( a2, "qqq" );
+ BOOST_CHECKA( a3 == exp3[c%3] );
+ ++c;
+ });
+
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) * data::make( copy_count() ), check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) * data::make( copy_count() ) * data::make( copy_count() ),
+ check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) * (data::make( copy_count() ) * data::make( copy_count() )),
+ check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ auto ds1 = data::make( copy_count() );
+ auto const ds2 = data::make( copy_count() );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 * ds1, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds2 * ds2, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 * ds2, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ auto zp1 = ds1 * data::make( copy_count() );
+ BOOST_CHECKA( zp1.size() == 1 );
+ data::for_each_sample( zp1, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) * ds1, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 * ds2 * ds1, check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 * (ds1 * ds2), check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ auto ds3 = data::make( make_copy_count_collection() ) * data::make( make_copy_count_collection() );
+ BOOST_CHECKA( ds3.size() == 9 );
+ data::for_each_sample( ds3, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+}
+
+//____________________________________________________________________________//
+
+// EOF

Added: trunk/libs/test/test/test_datasets/test_mono_join.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_mono_join.cpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,138 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : tests monomorphic join
+// ***************************************************************************
+
+// Boost.Test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/monomorphic/join.hpp>
+#include <boost/test/data/monomorphic/singleton.hpp>
+#include <boost/test/data/monomorphic/array.hpp>
+#include <boost/test/data/monomorphic/collection.hpp>
+namespace data=boost::unit_test::data;
+
+#include "test_datasets.hpp"
+
+BOOST_AUTO_TEST_CASE( test_mono_join )
+{
+ BOOST_CHECKA( (data::make( 1 ) + data::make( 5 )).size() == 2 );
+ BOOST_CHECKA( (data::make( std::vector<int>(2) ) + data::make( std::list<int>(3) )).size() == 5 );
+
+ int arr1[] = {1,2};
+ int arr2[] = {7,19};
+ BOOST_CHECKA( (data::make( arr1 ) + data::make( arr2 )).size() == 4 );
+
+ BOOST_CHECKA( (data::make( 1 ) + data::make( 5 ) + data::make( 19 )).size() == 3 );
+
+ BOOST_CHECKA( (data::make( std::vector<int>(2) ) + data::make( 1 ) + data::make( arr2 ) + data::make( 17 )).size() == 6 );
+
+ int expected[] = {1,2,5,7,19,37};
+ int* exp = expected;
+ int c = 0;
+ invocation_count ic;
+
+ auto samples1 = data::make( std::vector<int>(arr1,arr1+2) ) + data::make( 5 ) + data::make( arr2 ) + data::make( 37 );
+
+ ic.m_value = 0;
+ data::for_each_sample( samples1, ic );
+ BOOST_CHECKA( ic.m_value == 6 );
+
+ c = 0;
+ data::for_each_sample( samples1, [&c,exp](int i) {
+ BOOST_CHECKA( i == exp[c++] );
+ });
+
+ auto samples2 = data::make( std::vector<int>(arr1,arr1+2) ) + (data::make( 5 ) + (data::make( arr2 ) + data::make( 37 )));
+
+ ic.m_value = 0;
+ data::for_each_sample( samples2, ic );
+ BOOST_CHECKA( ic.m_value == 6 );
+
+ c = 0;
+ data::for_each_sample( samples2, [&c,exp](int i) {
+ BOOST_CHECKA( i == exp[c++] );
+ });
+
+ auto samples3 = (data::make( std::vector<int>(arr1,arr1+2) ) + data::make( 5 )) + (data::make( arr2 ) + data::make( 37 ));
+
+ ic.m_value = 0;
+ data::for_each_sample( samples3, ic );
+ BOOST_CHECKA( ic.m_value == 6 );
+
+ c = 0;
+ data::for_each_sample( samples3, [&c,exp](int i) {
+ BOOST_CHECKA( i == exp[c++] );
+ });
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) + data::make( copy_count() ), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) + data::make( copy_count() ) + data::make( copy_count() ), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) + (data::make( copy_count() ) + data::make( copy_count() )), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( (data::make( copy_count() ) + data::make( copy_count() )) +
+ (data::make( copy_count() ) + data::make( copy_count() )), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ auto ds1 = data::make( copy_count() );
+ auto const ds2 = data::make( copy_count() );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 + ds1, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds2 + ds2, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 + ds2, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ auto jn1 = ds1 + data::make( copy_count() );
+ data::for_each_sample( jn1, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) + ds1, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 + ds2 + ds1, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 + (ds1 + ds2), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( (ds1 + ds1) + (ds2 + ds2), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ auto ds3 = data::make( make_copy_count_collection() ) + data::make( make_copy_count_collection() );
+ BOOST_CHECKA( ds3.size() == 6 );
+ data::for_each_sample( ds3, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+}
+
+//____________________________________________________________________________//
+
+// EOF

Added: trunk/libs/test/test/test_datasets/test_mono_zip.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_mono_zip.cpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,141 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : tests monomorphic join
+// ***************************************************************************
+
+// Boost.Test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/monomorphic/zip.hpp>
+#include <boost/test/data/monomorphic/singleton.hpp>
+#include <boost/test/data/monomorphic/array.hpp>
+#include <boost/test/data/monomorphic/collection.hpp>
+namespace data=boost::unit_test::data;
+
+#include "test_datasets.hpp"
+
+BOOST_AUTO_TEST_CASE( test_mono_zip )
+{
+ BOOST_CHECKA( (data::make( 1 ) ^ data::make( 5 )).size() == 1 );
+ BOOST_CHECKA( (data::make( std::vector<int>(2) ) ^ data::make( std::list<float>(2) )).size() == 2 );
+ BOOST_CHECKA( (data::make( std::vector<int>(2) ) ^ data::make( 5. )).size() == 2 );
+ BOOST_CHECKA( (data::make( std::vector<int>(3) ) ^ data::make( std::list<int>(1) )).size() == 3 );
+
+ BOOST_CHECKA( (data::make( std::vector<int>(3) ) ^ data::make( std::list<std::string>(3) ) ^ data::make( 5 )).size() == 3 );
+ BOOST_CHECKA( (data::make( std::vector<int>(1) ) ^ data::make( std::list<int>(3) ) ^ data::make( 5 )).size() == 3 );
+
+ int arr1[] = {1,2};
+ char const* arr2[] = {"a","b"};
+ int* exp1 = arr1;
+ char const** exp2 = arr2;
+ int c = 0;
+ invocation_count ic;
+
+ auto samples1 = data::make( arr1 ) ^ data::make( arr2 );
+
+ BOOST_CHECKA( samples1.size() == 2 );
+
+ ic.m_value = 0;
+ data::for_each_sample( samples1, ic );
+ BOOST_CHECKA( ic.m_value == 2 );
+
+ data::for_each_sample( samples1, check_arg_type_like<std::tuple<int,char const*>>() );
+
+ c = 0;
+ data::for_each_sample( samples1, [&c,exp1,exp2](int i,char const* s) {
+ BOOST_CHECKA( i == exp1[c] );
+ BOOST_CHECKA( s == exp2[c] );
+ ++c;
+ });
+
+ std::vector<double> vec1;
+ vec1.push_back(2.1);
+ vec1.push_back(3.2);
+ vec1.push_back(4.7);
+ int arr3[] = {4,2,1};
+
+ auto samples2 = data::make( vec1 ) ^ data::make( "qqq" ) ^ data::make( arr3 );
+
+ BOOST_CHECKA( samples2.size() == 3 );
+
+ ic.m_value = 0;
+ data::for_each_sample( samples2, ic );
+ BOOST_CHECKA( ic.m_value == 3 );
+
+ data::for_each_sample( samples2, check_arg_type_like<std::tuple<double,char const*,int>>() );
+
+ c = 0;
+ int* exp3 = arr3;
+
+ data::for_each_sample( samples2, [&c,&vec1,exp3](double a1,char const* a2,int a3) {
+ BOOST_CHECKA( a1 == vec1[c] );
+ BOOST_CHECK_EQUAL( a2, "qqq" );
+ BOOST_CHECKA( a3 == exp3[c] );
+ ++c;
+ });
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) ^ data::make( copy_count() ), check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) ^ data::make( copy_count() ) ^ data::make( copy_count() ),
+ check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) ^ (data::make( copy_count() ) ^ data::make( copy_count() )),
+ check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ auto ds1 = data::make( copy_count() );
+ auto const ds2 = data::make( copy_count() );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 ^ ds1, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds2 ^ ds2, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 ^ ds2, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ auto zp1 = ds1 ^ data::make( copy_count() );
+ BOOST_CHECKA( zp1.size() == 1 );
+ data::for_each_sample( zp1, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ) ^ ds1, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 ^ ds2 ^ ds1, check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ data::for_each_sample( ds1 ^ (ds1 ^ ds2), check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ auto ds3 = data::make( make_copy_count_collection() ) ^ data::make( make_copy_count_collection() );
+ BOOST_CHECKA( ds3.size() == 3 );
+ data::for_each_sample( ds3, check_arg_type<std::tuple<copy_count,copy_count>>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+}
+
+//____________________________________________________________________________//
+
+// EOF

Added: trunk/libs/test/test/test_datasets/test_random.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_random.cpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,134 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : tests singleton dataset
+// ***************************************************************************
+
+// Boost.Test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/monomorphic/generators/random.hpp>
+#include <boost/test/data/monomorphic/zip.hpp>
+#include <boost/test/data/monomorphic/array.hpp>
+#include <boost/test/data/monomorphic/grid.hpp>
+namespace data=boost::unit_test::data;
+
+#include "test_datasets.hpp"
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_default )
+{
+ BOOST_CHECKA( data::random().size() == data::BOOST_TEST_DS_INFINITE_SIZE );
+
+ auto ds = data::random();
+
+ BOOST_CHECK_THROW( data::for_each_sample( ds, [](double ) {}), std::logic_error );
+
+ invocation_count ic;
+
+ ic.m_value = 0;
+ data::for_each_sample( ds, ic, 10 );
+ BOOST_CHECKA( ic.m_value == 10 );
+
+ ic.m_value = 0;
+ int arr[] = {1,2,3,4,5};
+ data::for_each_sample( ds^arr, ic );
+ BOOST_CHECKA( ic.m_value == 5 );
+
+ BOOST_CHECK_THROW( ds * arr, std::logic_error );
+ BOOST_CHECK_THROW( arr * ds, std::logic_error );
+}
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_uniform_range )
+{
+ auto ds1 = data::random(1,5);
+
+ data::for_each_sample( ds1, [](int s) {
+ BOOST_CHECKA(s>=1);
+ BOOST_CHECKA(s<=5);
+ }, 10);
+
+ auto ds2 = data::random(1.,2.);
+
+ data::for_each_sample( ds2, [](double s) {
+ BOOST_CHECKA(s>=1.);
+ BOOST_CHECKA(s<=2.);
+ }, 100);
+}
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_parameterized_init )
+{
+ auto ds1 = data::random(data::distribution = std::normal_distribution<>(5.,2));
+ typedef decltype(ds1) DS1;
+
+ BOOST_CHECKA(( std::is_same<DS1::generator_type::distr_type,
+ std::normal_distribution<>>::value ));
+ BOOST_CHECKA(( std::is_same<DS1::generator_type::data_type,double>::value ));
+ BOOST_CHECKA(( std::is_same<DS1::generator_type::engine_type,
+ std::default_random_engine>::value ));
+
+ auto ds2 = data::random(data::distribution = std::discrete_distribution<>());
+ typedef decltype(ds2) DS2;
+
+ BOOST_CHECKA(( std::is_same<DS2::generator_type::distr_type,
+ std::discrete_distribution<>>::value ));
+ BOOST_CHECKA(( std::is_same<DS2::generator_type::data_type,int>::value ));
+ BOOST_CHECKA(( std::is_same<DS2::generator_type::engine_type,
+ std::default_random_engine>::value ));
+
+ auto ds3 = data::random(data::engine = std::minstd_rand());
+ typedef decltype(ds3) DS3;
+
+ BOOST_CHECKA(( std::is_same<DS3::generator_type::distr_type,
+ std::uniform_real_distribution<>>::value ));
+ BOOST_CHECKA(( std::is_same<DS3::generator_type::data_type,double>::value ));
+ BOOST_CHECKA(( std::is_same<DS3::generator_type::engine_type,
+ std::minstd_rand>::value ));
+
+ auto ds4 = data::random(data::seed = 100UL);
+ typedef decltype(ds4) DS4;
+
+ BOOST_CHECKA(( std::is_same<DS4::generator_type::distr_type,
+ std::uniform_real_distribution<>>::value ));
+ BOOST_CHECKA(( std::is_same<DS4::generator_type::data_type,double>::value ));
+ BOOST_CHECKA(( std::is_same<DS4::generator_type::engine_type,
+ std::default_random_engine>::value ));
+
+ auto ds5 = data::random(data::seed = 100UL);
+
+ std::list<double> vals;
+ data::for_each_sample( ds4, [&vals](double s) {
+ vals.push_back( s );
+ }, 10);
+ data::for_each_sample( ds5, [&vals](double s) {
+ BOOST_CHECKA( vals.front() == s );
+ vals.pop_front();
+ }, 10);
+
+ auto ds6 = data::random(( data::engine = std::minstd_rand(),
+ data::distribution = std::normal_distribution<>(5.,2),
+ data::seed = 20UL ));
+ typedef decltype(ds6) DS6;
+
+ BOOST_CHECKA(( std::is_same<DS6::generator_type::distr_type,
+ std::normal_distribution<>>::value ));
+ BOOST_CHECKA(( std::is_same<DS6::generator_type::data_type,double>::value ));
+ BOOST_CHECKA(( std::is_same<DS6::generator_type::engine_type,
+ std::minstd_rand>::value ));
+}
+
+//____________________________________________________________________________//
+
+// EOF

Added: trunk/libs/test/test/test_datasets/test_singleton.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_singleton.cpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,80 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : tests singleton dataset
+// ***************************************************************************
+
+// Boost.Test
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/monomorphic/singleton.hpp>
+namespace data=boost::unit_test::data;
+
+#include "test_datasets.hpp"
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_singleton )
+{
+ BOOST_CHECKA( data::make( 1 ).size() == 1 );
+ BOOST_CHECKA( data::make( 2.3 ).size() == 1 );
+ BOOST_CHECKA( data::make( "1" ).size() == 1 );
+
+ data::for_each_sample( data::make( 2 ), check_arg_type<int>() );
+ data::for_each_sample( data::make( "ch" ), check_arg_type<char const*>() );
+ data::for_each_sample( data::make( 2. ), check_arg_type<double>() );
+
+ invocation_count ic;
+
+ ic.m_value = 0;
+ data::for_each_sample( data::make( 2 ), ic );
+ BOOST_CHECKA( ic.m_value == 1 );
+
+ ic.m_value = 0;
+ data::for_each_sample( data::make( 2 ), ic, 2 );
+ BOOST_CHECKA( ic.m_value == 1 );
+
+ ic.m_value = 0;
+ data::for_each_sample( data::make( 2 ), ic, 0 );
+ BOOST_CHECKA( ic.m_value == 0 );
+
+ data::for_each_sample( data::make( 2 ), [] (int s) {
+ BOOST_CHECKA( s == 2 );
+ });
+
+ copy_count::value() = 0;
+ data::for_each_sample( data::make( copy_count() ), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ copy_count cc1;
+ data::for_each_sample( data::make( cc1 ), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ copy_count const cc2;
+ data::for_each_sample( data::make( cc2 ), check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ auto ds1 = data::make( copy_count::make() );
+ data::for_each_sample( ds1, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+
+ copy_count::value() = 0;
+ auto ds2 = data::make( copy_count::make_const() );
+ data::for_each_sample( ds2, check_arg_type<copy_count>() );
+ BOOST_CHECKA( copy_count::value() == 0 );
+}
+
+//____________________________________________________________________________//
+
+// EOF

Added: trunk/libs/test/test/test_datasets/test_xrange.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_datasets/test_xrange.cpp 2012-10-18 04:13:59 EDT (Thu, 18 Oct 2012)
@@ -0,0 +1,85 @@
+// (C) Copyright Gennadiy Rozental 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/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision$
+//
+// Description : tests singleton dataset
+// ***************************************************************************
+
+// Boost.Test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/monomorphic/generators/xrange.hpp>
+#include <boost/test/data/monomorphic/join.hpp>
+namespace data=boost::unit_test::data;
+namespace mono=boost::unit_test::data::monomorphic;
+
+#include "test_datasets.hpp"
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_single_range )
+{
+ BOOST_CHECKA( data::xrange( 5 ).size() == 5 );
+ BOOST_CHECKA( data::xrange( 3. ).size() == 3 );
+ BOOST_CHECK_THROW( data::xrange( -5 ), std::logic_error );
+ BOOST_CHECK_THROW( data::xrange( 0 ), std::logic_error );
+
+ BOOST_CHECKA( data::xrange( 1, 5 ).size() == 4 );
+ BOOST_CHECKA( data::xrange( -5, 0 ).size() == 5 );
+ BOOST_CHECKA( data::xrange( 1., 7.5 ).size() == 7 );
+ BOOST_CHECK_THROW( data::xrange( 0, 0 ), std::logic_error );
+ BOOST_CHECK_THROW( data::xrange( 3, 1 ), std::logic_error );
+
+ BOOST_CHECKA( data::xrange( 3, 9, 2 ).size() == 3 );
+ BOOST_CHECKA( data::xrange( 5, 0, -1 ).size() == 5 );
+ BOOST_CHECKA( data::xrange( 1, 10, 2 ).size() == 5 );
+ BOOST_CHECKA( data::xrange( 1, 10, 3 ).size() == 3 );
+ BOOST_CHECKA( data::xrange( 1, 10, 8 ).size() == 2 );
+ BOOST_CHECKA( data::xrange( 0., 3., 0.4 ).size() == 8 );
+ BOOST_CHECKA( data::xrange( 1e-6, 2.e-6, 1e-9 ).size() == 1000 );
+
+ BOOST_CHECKA( data::xrange<int>(( mono::begin = 9, mono::end = 15 )).size() == 6 );
+ BOOST_CHECKA( data::xrange<double>(( mono::step = 0.5, mono::end = 3 )).size() == 6 );
+
+ int c = 0;
+
+ data::for_each_sample( data::xrange( 3 ), [&c](int a) {
+ BOOST_CHECKA( a == c++ );
+ });
+
+ c = 1;
+ data::for_each_sample( data::xrange( 1, 10, 2 ), [&c](int a) {
+ BOOST_CHECKA( a == c );
+ c += 2;
+ });
+}
+
+BOOST_AUTO_TEST_CASE( test_range_join )
+{
+ auto ds = data::xrange( 1, 4 ) + data::xrange( 7, 11 );
+
+ BOOST_CHECKA( ds.size() == 7 );
+
+ invocation_count ic;
+ ic.m_value = 0;
+ data::for_each_sample( ds, ic );
+ BOOST_CHECKA( ic.m_value == 7 );
+
+ int arr[] = {1,2,3,7,8,9,10};
+ int* exp = arr;
+ int c = 0;
+
+ data::for_each_sample( ds, [&c,exp](int a) {
+ BOOST_CHECKA( a == exp[c++] );
+ });
+}
+
+//____________________________________________________________________________//
+
+// EOF


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