test_icl_interval.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2008-2009: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENCE.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. +-----------------------------------------------------------------------------*/
  8. #ifndef BOOST_ICL_TEST_ICL_INTERVAL_HPP_JOFA_100930
  9. #define BOOST_ICL_TEST_ICL_INTERVAL_HPP_JOFA_100930
  10. // NOTE: ordered_types is the largest class of types that is admissable as
  11. // domain parameters for intervals and interval containers.
  12. // bicremental_types is a smaller class of types used for testing instead of
  13. // ordered types, because they can be generated in a simple
  14. // way using the functions of test_value_maker.hpp.
  15. template <class IntervalT>
  16. void interval_ctor_4_ordered_types()
  17. {
  18. typedef typename domain_type_of<interval_traits<IntervalT> >::type T;
  19. typedef typename icl::size_type_of<T>::type SizeT;
  20. T t_0 = icl::identity_element<T>::value();
  21. T t_1 = icl::unit_element<T>::value();
  22. SizeT s_0 = icl::identity_element<SizeT>::value();
  23. SizeT s_1 = icl::unit_element<SizeT>::value();
  24. // Default ctor and emptieness
  25. BOOST_CHECK_EQUAL( icl::is_empty(IntervalT()), true );
  26. BOOST_CHECK_EQUAL( icl::cardinality(IntervalT()), s_0 );
  27. BOOST_CHECK_EQUAL( icl::size(IntervalT()), s_0 );
  28. BOOST_CHECK_EQUAL( IntervalT(), IntervalT() );
  29. BOOST_CHECK_EQUAL( IntervalT(), IntervalT(IntervalT().lower(), IntervalT().upper()) );
  30. BOOST_CHECK_EQUAL( IntervalT(), IntervalT(icl::lower(IntervalT()), icl::upper(IntervalT())) );
  31. BOOST_CHECK_EQUAL(icl::cardinality(IntervalT(t_0, t_1)) >= s_1, true);
  32. BOOST_CHECK_EQUAL(( icl::contains(IntervalT(t_0, t_1), t_0)
  33. || icl::contains(IntervalT(t_0, t_1), t_1)), true);
  34. BOOST_CHECK_EQUAL(IntervalT(t_0, t_1).lower(), t_0);
  35. BOOST_CHECK_EQUAL(IntervalT(t_0, t_1).upper(), t_1);
  36. BOOST_CHECK_EQUAL(lower(icl::construct<IntervalT>(t_0, t_1)), t_0);
  37. BOOST_CHECK_EQUAL(upper(icl::construct<IntervalT>(t_0, t_1)), t_1);
  38. }
  39. template <class IntervalT>
  40. void singelizable_interval_4_ordered_types()
  41. {
  42. // Singleton ctor and singleness
  43. // LAW: !is_asymmetric_continuous(IntervalT) => size(singleton(x))==1
  44. // LAW: This law applies to all discrete and to dynamic continuous intervals
  45. // LAW: No singletons can be constructed for static continuous right_open and left_open intervals
  46. typedef typename domain_type_of<interval_traits<IntervalT> >::type T;
  47. typedef typename icl::size_type_of<T>::type SizeT;
  48. T t_0 = icl::identity_element<T>::value();
  49. T t_1 = icl::unit_element<T>::value();
  50. SizeT s_1 = icl::unit_element<SizeT>::value();
  51. BOOST_CHECK( is_singelizable<IntervalT>::value );
  52. BOOST_CHECK_EQUAL( icl::cardinality(icl::singleton<IntervalT>(t_0)), s_1 );
  53. BOOST_CHECK_EQUAL( icl::size(icl::singleton<IntervalT>(t_0)), s_1 );
  54. BOOST_CHECK_EQUAL( icl::cardinality(icl::singleton<IntervalT>(t_1)), s_1 );
  55. BOOST_CHECK_EQUAL( icl::size(icl::singleton<IntervalT>(t_1)), s_1 );
  56. BOOST_CHECK_EQUAL( icl::contains(icl::singleton<IntervalT>(t_0), t_0), true );
  57. BOOST_CHECK_EQUAL( icl::contains(icl::singleton<IntervalT>(t_1), t_1), true );
  58. }
  59. template <class IntervalT>
  60. void singelizable_interval_4_bicremental_types()
  61. {
  62. typedef typename domain_type_of<interval_traits<IntervalT> >::type T;
  63. typedef typename icl::size_type_of<T>::type SizeT;
  64. //T t_0 = icl::identity_element<T>::value();
  65. SizeT s_1 = icl::unit_element<SizeT>::value();
  66. BOOST_CHECK( is_singelizable<IntervalT>::value );
  67. BOOST_CHECK_EQUAL( icl::cardinality(IntervalT(MK_v(3))), s_1 );
  68. BOOST_CHECK_EQUAL( icl::size(IntervalT(MK_v(4))), s_1 );
  69. BOOST_CHECK_EQUAL( icl::singleton<IntervalT>(MK_v(2)), icl::singleton<IntervalT>(MK_v(2)) );
  70. BOOST_CHECK_EQUAL( icl::contains(IntervalT(MK_v(1)), MK_v(1)), true );
  71. }
  72. template <class IntervalT>
  73. void coverable_asymmetric_interval_4_bicremental_types()
  74. {
  75. typedef typename domain_type_of<interval_traits<IntervalT> >::type T;
  76. //CL typedef typename icl::size_type_of<T>::type SizeT;
  77. typedef typename icl::difference_type_of<T>::type DiffT;
  78. //T t_0 = icl::identity_element<T>::value();
  79. //SizeT s_1 = icl::unit_element<SizeT>::value();
  80. DiffT d_1 = icl::unit_element<DiffT>::value();
  81. //JODO BOOST_CHECK( is_incremental_coverable<IntervalT>::value );
  82. BOOST_CHECK( has_difference<T>::value );
  83. BOOST_CHECK_EQUAL( icl::contains(icl::detail::unit_trail<IntervalT>(MK_v(4)), MK_v(4)), true );
  84. BOOST_CHECK_EQUAL( icl::length (icl::detail::unit_trail<IntervalT>(MK_v(3))), d_1 );
  85. BOOST_CHECK ( icl::touches (icl::detail::unit_trail<IntervalT>(MK_v(2)), icl::detail::unit_trail<IntervalT>(MK_v(3))) );
  86. }
  87. #endif // BOOST_ICL_TEST_ICL_INTERVAL_HPP_JOFA_100930