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
11 // NOTE: ordered_types is the largest class of types that is admissable as
12 // domain parameters for intervals and interval containers.
13 // bicremental_types is a smaller class of types used for testing instead of
14 // ordered types, because they can be generated in a simple
15 // way using the functions of test_value_maker.hpp.
16
17 template <class IntervalT>
interval_ctor_4_ordered_types()18 void interval_ctor_4_ordered_types()
19 {
20 typedef typename domain_type_of<interval_traits<IntervalT> >::type T;
21 typedef typename icl::size_type_of<T>::type SizeT;
22 T t_0 = icl::identity_element<T>::value();
23 T t_1 = icl::unit_element<T>::value();
24 SizeT s_0 = icl::identity_element<SizeT>::value();
25 SizeT s_1 = icl::unit_element<SizeT>::value();
26
27 // Default ctor and emptieness
28 BOOST_CHECK_EQUAL( icl::is_empty(IntervalT()), true );
29 BOOST_CHECK_EQUAL( icl::cardinality(IntervalT()), s_0 );
30 BOOST_CHECK_EQUAL( icl::size(IntervalT()), s_0 );
31
32 BOOST_CHECK_EQUAL( IntervalT(), IntervalT() );
33 BOOST_CHECK_EQUAL( IntervalT(), IntervalT(IntervalT().lower(), IntervalT().upper()) );
34 BOOST_CHECK_EQUAL( IntervalT(), IntervalT(icl::lower(IntervalT()), icl::upper(IntervalT())) );
35
36 BOOST_CHECK_EQUAL(icl::cardinality(IntervalT(t_0, t_1)) >= s_1, true);
37 BOOST_CHECK_EQUAL(( icl::contains(IntervalT(t_0, t_1), t_0)
38 || icl::contains(IntervalT(t_0, t_1), t_1)), true);
39
40 BOOST_CHECK_EQUAL(IntervalT(t_0, t_1).lower(), t_0);
41 BOOST_CHECK_EQUAL(IntervalT(t_0, t_1).upper(), t_1);
42 BOOST_CHECK_EQUAL(lower(icl::construct<IntervalT>(t_0, t_1)), t_0);
43 BOOST_CHECK_EQUAL(upper(icl::construct<IntervalT>(t_0, t_1)), t_1);
44 }
45
46
47 template <class IntervalT>
singelizable_interval_4_ordered_types()48 void singelizable_interval_4_ordered_types()
49 {
50 // Singleton ctor and singleness
51 // LAW: !is_asymmetric_continuous(IntervalT) => size(singleton(x))==1
52 // LAW: This law applies to all discrete and to dynamic continuous intervals
53 // LAW: No singletons can be constructed for static continuous right_open and left_open intervals
54 typedef typename domain_type_of<interval_traits<IntervalT> >::type T;
55 typedef typename icl::size_type_of<T>::type SizeT;
56 T t_0 = icl::identity_element<T>::value();
57 T t_1 = icl::unit_element<T>::value();
58 SizeT s_1 = icl::unit_element<SizeT>::value();
59
60 BOOST_CHECK( is_singelizable<IntervalT>::value );
61
62 BOOST_CHECK_EQUAL( icl::cardinality(icl::singleton<IntervalT>(t_0)), s_1 );
63 BOOST_CHECK_EQUAL( icl::size(icl::singleton<IntervalT>(t_0)), s_1 );
64 BOOST_CHECK_EQUAL( icl::cardinality(icl::singleton<IntervalT>(t_1)), s_1 );
65 BOOST_CHECK_EQUAL( icl::size(icl::singleton<IntervalT>(t_1)), s_1 );
66
67 BOOST_CHECK_EQUAL( icl::contains(icl::singleton<IntervalT>(t_0), t_0), true );
68 BOOST_CHECK_EQUAL( icl::contains(icl::singleton<IntervalT>(t_1), t_1), true );
69 }
70
71 template <class IntervalT>
singelizable_interval_4_bicremental_types()72 void singelizable_interval_4_bicremental_types()
73 {
74 typedef typename domain_type_of<interval_traits<IntervalT> >::type T;
75 typedef typename icl::size_type_of<T>::type SizeT;
76 //T t_0 = icl::identity_element<T>::value();
77 SizeT s_1 = icl::unit_element<SizeT>::value();
78
79 BOOST_CHECK( is_singelizable<IntervalT>::value );
80
81 BOOST_CHECK_EQUAL( icl::cardinality(IntervalT(MK_v(3))), s_1 );
82 BOOST_CHECK_EQUAL( icl::size(IntervalT(MK_v(4))), s_1 );
83 BOOST_CHECK_EQUAL( icl::singleton<IntervalT>(MK_v(2)), icl::singleton<IntervalT>(MK_v(2)) );
84 BOOST_CHECK_EQUAL( icl::contains(IntervalT(MK_v(1)), MK_v(1)), true );
85 }
86
87 template <class IntervalT>
coverable_asymmetric_interval_4_bicremental_types()88 void coverable_asymmetric_interval_4_bicremental_types()
89 {
90 typedef typename domain_type_of<interval_traits<IntervalT> >::type T;
91 //CL typedef typename icl::size_type_of<T>::type SizeT;
92 typedef typename icl::difference_type_of<T>::type DiffT;
93 //T t_0 = icl::identity_element<T>::value();
94 //SizeT s_1 = icl::unit_element<SizeT>::value();
95 DiffT d_1 = icl::unit_element<DiffT>::value();
96
97 //JODO BOOST_CHECK( is_incremental_coverable<IntervalT>::value );
98 BOOST_CHECK( has_difference<T>::value );
99
100 BOOST_CHECK_EQUAL( icl::contains(icl::detail::unit_trail<IntervalT>(MK_v(4)), MK_v(4)), true );
101 BOOST_CHECK_EQUAL( icl::length (icl::detail::unit_trail<IntervalT>(MK_v(3))), d_1 );
102 BOOST_CHECK ( icl::touches (icl::detail::unit_trail<IntervalT>(MK_v(2)), icl::detail::unit_trail<IntervalT>(MK_v(3))) );
103 }
104
105
106
107 #endif // BOOST_ICL_TEST_ICL_INTERVAL_HPP_JOFA_100930
108