unit test
Unuit test とは
http://ja.wikipedia.org/wiki/%E5%8D%98%E4%BD%93%E3%83%86%E3%82%B9%E3%83%88
RackUnit: Unit Testing
http://docs.racket-lang.org/rackunit/index.html?q=unit%20test&q=test
boost test
http://www.kmonos.net/alang/boost/classes/test.html
#include <boost/test/minimal.hpp> bool is_leap_year(int year){ return year%4 == 0 && year%100 != 0 || year%400 == 0; } template<typename T, typename U> struct is_same{ static const bool value = false; }; template<typename T> struct is_same<T, T>{ static const bool value = true; }; int test_main(int argc, char* argv[]){ BOOST_CHECK( is_leap_year(2004) == true ); BOOST_CHECK( is_leap_year(2010) == false ); BOOST_CHECK(( is_same<int, int>::value == true )); BOOST_CHECK(( is_same<int, char>::value == false )); return 0; }
エラーを試しに入れてみてどんなメッセージが表示されるか試す
例
BOOST_CHECK( is_leap_year(2011) == true );//error BOOST_CHECK(( is_same<int, char>::value == true ));//error
static test example
https://github.com/niitsuma/scm2cpp.hpp
のテスト例
typedef boost::mpl::if_<boost::mpl::true_,char,long>::type t1; typedef boost::mpl::if_<boost::mpl::false_,char,long>::type t2; BOOST_MPL_ASSERT(( boost::is_same<t1, char> )); BOOST_MPL_ASSERT(( boost::is_same<t2, long> )); BOOST_MPL_ASSERT(( boost::is_same<char , char > )); //BOOST_MPL_ASSERT(( boost::is_same<char , char &> )); #if 0 BOOST_MPL_ASSERT(( boost::is_same<scm2cpp::to_subst_type<char>::type::type , char> )); BOOST_MPL_ASSERT(( boost::is_same<scm2cpp::to_subst_type<char[]>::type::type , char(&)[]> )); BOOST_MPL_ASSERT(( boost::is_same<scm2cpp::to_subst_type<std::vector<double> >::type::type , std::vector<double> &> )); #else BOOST_MPL_ASSERT(( boost::is_same<scm2cpp::to_subst_type<char>::type , char> )); BOOST_MPL_ASSERT(( boost::is_same<scm2cpp::to_subst_type<char[]>::type , char(&)[]> )); BOOST_MPL_ASSERT(( boost::is_same<scm2cpp::to_subst_type<std::vector<double> >::type , std::vector<double> &> )); #endif BOOST_MPL_ASSERT((boost::is_same< scm2cpp::uniform_sequence_to_boost_ptr_sequence_view<std::list<double> >::type ,boost::ptr_list<double, boost::view_clone_allocator> > )); #if 0 BOOST_MPL_ASSERT((boost::is_same< scm2cpp::is_uniform_sequence<std::list<double> > ,boost::mpl::true_> )); #endif BOOST_MPL_ASSERT((scm2cpp::is_uniform_sequence<std::list<double> > )) ; //BOOST_MPL_ASSERT((scm2cpp::is_uniform_sequence<std::pair<double,double> > )) ;
http://stackoverflow.com/questions/193471/which-is-better-boost-mpl-assert-or-boost-static-assert