diff --git a/doc/manual/manual/contractors/set/ctcinter.rst b/doc/manual/manual/contractors/set/ctcinter.rst index 248c63d8d..53e2b76a0 100644 --- a/doc/manual/manual/contractors/set/ctcinter.rst +++ b/doc/manual/manual/contractors/set/ctcinter.rst @@ -13,7 +13,7 @@ Basic usage ----------- The most common way to create an intersection contractor is to combine two existing -contractors with ``&``. +contractors using ``&`` or the ``CtcInter`` constructor. .. tabs:: @@ -23,7 +23,7 @@ contractors with ``&``. :language: py :start-after: [ctcinter-1-beg] :end-before: [ctcinter-1-end] - :dedent: 2 + :dedent: 4 .. group-tab:: C++ @@ -33,7 +33,8 @@ contractors with ``&``. :end-before: [ctcinter-1-end] :dedent: 2 -Once built, the contractor can be applied as any other box contractor. +| A ``CtcInter`` can also be built from a Python/C++ list of contractor objects. +| Once built, the contractor can be called as any other box contractor. .. tabs:: @@ -43,7 +44,7 @@ Once built, the contractor can be applied as any other box contractor. :language: py :start-after: [ctcinter-2-beg] :end-before: [ctcinter-2-end] - :dedent: 2 + :dedent: 4 .. group-tab:: C++ diff --git a/doc/manual/manual/contractors/set/src.cpp b/doc/manual/manual/contractors/set/src.cpp index c8ebe6546..14043e366 100644 --- a/doc/manual/manual/contractors/set/src.cpp +++ b/doc/manual/manual/contractors/set/src.cpp @@ -19,8 +19,10 @@ TEST_CASE("CtcInter - manual") CtcWrapper c1(IntervalVector({{-10,10},{-2,2}})); CtcWrapper c2(IntervalVector({{-12,2},{0,4}})); - auto c3 = c1 & c2; - // c3 is a CtcInter gathering the two contractors. + CtcInter c3(c1,c2); + // or... + auto c3bis = c1 & c2; + // c3 and c3bis are a CtcInter gathering the two contractors. // [ctcinter-1-end] // [ctcinter-2-beg] diff --git a/doc/manual/manual/contractors/set/src.py b/doc/manual/manual/contractors/set/src.py index b3329d1f3..d5d208b32 100644 --- a/doc/manual/manual/contractors/set/src.py +++ b/doc/manual/manual/contractors/set/src.py @@ -20,6 +20,8 @@ def tests_CtcInter_manual(test): c1 = CtcWrapper([[-10,10],[-2,2]]) c2 = CtcWrapper([[-12,2],[0,4]]) + c3 = CtcInter(c1,c2) + # or... c3 = c1 & c2 # c3 is a CtcInter gathering the two contractors. # [ctcinter-1-end] diff --git a/examples/13_qinter/main.py b/examples/13_qinter/main.py index b09102feb..39493c29f 100644 --- a/examples/13_qinter/main.py +++ b/examples/13_qinter/main.py @@ -23,6 +23,6 @@ def create_sep(b, d): q = 2 DefaultFigure.pave( [[-6,6],[-6,6]], - SepQInter(q, s1, s2, s3), + SepQInter(q, s1,s2,s3), 5e-2 ) \ No newline at end of file diff --git a/python/codac/core/__init__.py b/python/codac/core/__init__.py index 831311cc6..bc50feb09 100644 --- a/python/codac/core/__init__.py +++ b/python/codac/core/__init__.py @@ -456,4 +456,4 @@ def fixpoint(contract, *x): "draw_while_paving(..) is deprecated,\n " " please replace by DefaultFigure.pave(..) (or any Figure2D object)" ) -) +) \ No newline at end of file diff --git a/python/src/core/contractors/codac2_py_CtcInter.cpp b/python/src/core/contractors/codac2_py_CtcInter.cpp index 438f4b45c..925996d82 100644 --- a/python/src/core/contractors/codac2_py_CtcInter.cpp +++ b/python/src/core/contractors/codac2_py_CtcInter.cpp @@ -29,23 +29,33 @@ void export_CtcInter(py::module& m, py::class_,pyCtcInte "n"_a) .def(py::init( - [](const CtcBase& c) + [](py::args args) { - return std::make_unique>( - std::dynamic_pointer_cast>(c.copy())); - }), - CTCINTER_X_CTCINTER_CONST_C_REF, - "c"_a) + Collection> ctcs; - .def(py::init( - [](const CtcBase& c1, const CtcBase& c2) - { - return std::make_unique>( - std::dynamic_pointer_cast>(c1.copy()), - std::dynamic_pointer_cast>(c2.copy())); + auto add = [&ctcs](py::handle c) + { + ctcs.push_back( + c.cast&>().copy() + ); + }; + + // Backward compatibility: CtcInter([c1,c2,c3]) + if(args.size() == 1 && py::isinstance(args[0])) + { + for(const auto& c : args[0].cast()) + add(c); + } + else + { + // New syntax: CtcInter(c1,c2,c3) + for(const auto& c : args) + add(c); + } + + return std::make_unique>(ctcs); }), - CTCINTER_X_CTCINTER_CONST_C_REF_VARIADIC, - "c1"_a, "c2"_a) + CTCINTER_X_CTCINTER_INITIALIZER_LIST_C) .def("nb", &CtcInter::nb, SIZET_CTCINTER_X_NB_CONST) diff --git a/python/src/core/contractors/codac2_py_CtcQInter.cpp b/python/src/core/contractors/codac2_py_CtcQInter.cpp index 34f3913d5..a82e520a4 100644 --- a/python/src/core/contractors/codac2_py_CtcQInter.cpp +++ b/python/src/core/contractors/codac2_py_CtcQInter.cpp @@ -25,34 +25,35 @@ void export_CtcQInter(py::module& m, py::class_,pyCtcInt exported .def(py::init( - [](unsigned int q, const CtcBase& c) + [](Index q, py::args args) { - return std::make_unique(q, - std::dynamic_pointer_cast>(c.copy())); - }), - CTCQINTER_CTCQINTER_UNSIGNED_INT_CONST_C_REF, - "q"_a, "c"_a) + matlab::test_integer(q); + Collection> ctcs; - .def(py::init( - [](unsigned int q, const CtcBase& c1, const CtcBase& c2) - { - return std::make_unique(q, - std::dynamic_pointer_cast>(c1.copy()), - std::dynamic_pointer_cast>(c2.copy())); - }), - CTCQINTER_CTCQINTER_UNSIGNED_INT_CONST_C_REF_VARIADIC, - "q"_a, "c1"_a, "c2"_a) + auto add = [&ctcs](py::handle c) + { + ctcs.push_back( + c.cast&>().copy() + ); + }; - .def(py::init( - [](unsigned int q, const CtcBase& c1, const CtcBase& c2, const CtcBase& c3) - { - return std::make_unique(q, - std::dynamic_pointer_cast>(c1.copy()), - std::dynamic_pointer_cast>(c2.copy()), - std::dynamic_pointer_cast>(c3.copy())); + // Backward compatibility: CtcQInter(q, [c1,c2,c3]) + if(args.size() == 1 && py::isinstance(args[0])) + { + for(const auto& c : args[0].cast()) + add(c); + } + else + { + // New syntax: CtcQInter(q, c1,c2,c3) + for(const auto& c : args) + add(c); + } + + return std::make_unique(q, ctcs); }), - CTCQINTER_CTCQINTER_UNSIGNED_INT_CONST_C_REF_VARIADIC, - "q"_a, "c1"_a, "c2"_a, "c3"_a) + CTCQINTER_CTCQINTER_UNSIGNED_INT_CONST_C_REF, + "q"_a) .def("nb", &CtcQInter::nb, SIZET_CTCQINTER_NB_CONST) diff --git a/python/src/core/contractors/codac2_py_CtcUnion.cpp b/python/src/core/contractors/codac2_py_CtcUnion.cpp index d8b84dfe1..30252b7cf 100644 --- a/python/src/core/contractors/codac2_py_CtcUnion.cpp +++ b/python/src/core/contractors/codac2_py_CtcUnion.cpp @@ -29,23 +29,33 @@ void export_CtcUnion(py::module& m, py::class_,pyCtcInte "n"_a) .def(py::init( - [](const CtcBase& c) + [](py::args args) { - return std::make_unique>( - std::dynamic_pointer_cast>(c.copy())); - }), - CTCUNION_X_CTCUNION_CONST_C_REF, - "c"_a) + Collection> ctcs; - .def(py::init( - [](const CtcBase& c1, const CtcBase& c2) - { - return std::make_unique>( - std::dynamic_pointer_cast>(c1.copy()), - std::dynamic_pointer_cast>(c2.copy())); + auto add = [&ctcs](py::handle c) + { + ctcs.push_back( + c.cast&>().copy() + ); + }; + + // Backward compatibility: CtcUnion([c1,c2,c3]) + if(args.size() == 1 && py::isinstance(args[0])) + { + for(const auto& c : args[0].cast()) + add(c); + } + else + { + // New syntax: CtcUnion(c1,c2,c3) + for(const auto& c : args) + add(c); + } + + return std::make_unique>(ctcs); }), - CTCUNION_X_CTCUNION_CONST_C_REF_VARIADIC, - "c1"_a, "c2"_a) + CTCUNION_X_CTCUNION_INITIALIZER_LIST_C) .def("nb", &CtcUnion::nb, SIZET_CTCUNION_X_NB_CONST) diff --git a/python/src/core/separators/codac2_py_SepInter.cpp b/python/src/core/separators/codac2_py_SepInter.cpp index 4d2d2382d..22300d3c9 100644 --- a/python/src/core/separators/codac2_py_SepInter.cpp +++ b/python/src/core/separators/codac2_py_SepInter.cpp @@ -25,31 +25,33 @@ void export_SepInter(py::module& m, py::class_& pysep) exported .def(py::init( - [](const py::list& l) + [](py::args args) { - Collection l_copy; - for(const auto& li : l) - l_copy.push_back(li.cast().copy()); - return std::make_unique(l_copy); - }), - SEPINTER_SEPINTER_CONST_COLLECTION_T_REF, - "s"_a) + Collection seps; - .def(py::init( - [](const SepBase& s) - { - return std::make_unique(s.copy()); - }), - SEPINTER_SEPINTER_CONST_S_REF, - "s"_a) + auto add = [&seps](py::handle s) + { + seps.push_back( + s.cast().copy() + ); + }; - .def(py::init( - [](const SepBase& s1, const SepBase& s2) - { - return std::make_unique(s1.copy(),s2.copy()); + // Backward compatibility: SepInter([s1,s2,s3]) + if(args.size() == 1 && py::isinstance(args[0])) + { + for(const auto& s : args[0].cast()) + add(s); + } + else + { + // New syntax: SepInter(s1,s2,s3) + for(const auto& s : args) + add(s); + } + + return std::make_unique(seps); }), - SEPINTER_SEPINTER_CONST_S_REF_VARIADIC, - "s1"_a, "s2"_a) + SEPINTER_SEPINTER_CONST_COLLECTION_SEPBASE_REF) .def("nb", &SepInter::nb, SIZET_SEPINTER_NB_CONST) diff --git a/python/src/core/separators/codac2_py_SepQInter.cpp b/python/src/core/separators/codac2_py_SepQInter.cpp index 8b2a451e3..a4de946e1 100644 --- a/python/src/core/separators/codac2_py_SepQInter.cpp +++ b/python/src/core/separators/codac2_py_SepQInter.cpp @@ -25,28 +25,35 @@ void export_SepQInter(py::module& m, py::class_& pysep) exported .def(py::init( - [](unsigned int q, const SepBase& s) + [](Index q, py::args args) { - return std::make_unique(q,s.copy()); - }), - SEPQINTER_SEPQINTER_UNSIGNED_INT_CONST_S_REF, - "q"_a, "s"_a) + matlab::test_integer(q); + Collection seps; - .def(py::init( - [](unsigned int q, const SepBase& s1, const SepBase& s2) - { - return std::make_unique(q,s1.copy(),s2.copy()); - }), - SEPQINTER_SEPQINTER_UNSIGNED_INT_CONST_S_REF_VARIADIC, - "q"_a, "s1"_a, "s2"_a) + auto add = [&seps](py::handle s) + { + seps.push_back( + s.cast().copy() + ); + }; - .def(py::init( - [](unsigned int q, const SepBase& s1, const SepBase& s2, const SepBase& s3) - { - return std::make_unique(q,s1.copy(),s2.copy(),s3.copy()); + // Backward compatibility: SepQInter(q, [s1,s2,s3]) + if(args.size() == 1 && py::isinstance(args[0])) + { + for(const auto& s : args[0].cast()) + add(s); + } + else + { + // New syntax: SepQInter(q, s1,s2,s3) + for(const auto& s : args) + add(s); + } + + return std::make_unique(q, seps); }), - SEPQINTER_SEPQINTER_UNSIGNED_INT_CONST_S_REF_VARIADIC, - "q"_a, "s1"_a, "s2"_a, "s3"_a) + SEPQINTER_SEPQINTER_UNSIGNED_INT_CONST_COLLECTION_SEPBASE_REF, + "q"_a) .def("nb", &SepQInter::nb, SIZET_SEPQINTER_NB_CONST) diff --git a/python/src/core/separators/codac2_py_SepUnion.cpp b/python/src/core/separators/codac2_py_SepUnion.cpp index 29ea6ff70..30c9660ea 100644 --- a/python/src/core/separators/codac2_py_SepUnion.cpp +++ b/python/src/core/separators/codac2_py_SepUnion.cpp @@ -25,31 +25,33 @@ void export_SepUnion(py::module& m, py::class_& pysep) exported .def(py::init( - [](const py::list& l) + [](py::args args) { - Collection l_copy; - for(const auto& li : l) - l_copy.push_back(li.cast().copy()); - return std::make_unique(l_copy); - }), - SEPUNION_SEPUNION_CONST_COLLECTION_T_REF, - "s"_a) + Collection seps; - .def(py::init( - [](const SepBase& s) - { - return std::make_unique(s.copy()); - }), - SEPUNION_SEPUNION_CONST_S_REF, - "s"_a) + auto add = [&seps](py::handle s) + { + seps.push_back( + s.cast().copy() + ); + }; - .def(py::init( - [](const SepBase& s1, const SepBase& s2) - { - return std::make_unique(s1.copy(),s2.copy()); + // Backward compatibility: SepUnion([s1,s2,s3]) + if(args.size() == 1 && py::isinstance(args[0])) + { + for(const auto& s : args[0].cast()) + add(s); + } + else + { + // New syntax: SepUnion(s1,s2,s3) + for(const auto& s : args) + add(s); + } + + return std::make_unique(seps); }), - SEPUNION_SEPUNION_CONST_S_REF_VARIADIC, - "s1"_a, "s2"_a) + SEPUNION_SEPUNION_CONST_COLLECTION_SEPBASE_REF) .def("nb", &SepUnion::nb, SIZET_SEPUNION_NB_CONST) diff --git a/src/core/contractors/codac2_CtcInter.h b/src/core/contractors/codac2_CtcInter.h index f880de60a..8b0b5e9e5 100644 --- a/src/core/contractors/codac2_CtcInter.h +++ b/src/core/contractors/codac2_CtcInter.h @@ -111,7 +111,7 @@ namespace codac2 * * \param ctcs Collection of contractors sequentially. */ - CtcInter(const Collection>& ctcs) + CtcInter(const Collection>& ctcs) : Ctc,X...>(ctcs.front()->size()), _ctcs(ctcs) { for(const auto& ci : _ctcs) @@ -120,6 +120,19 @@ namespace codac2 } } + /** + * \brief Builds an intersection contractor from a std::initializer_list of contractors. + * + * All contractors must act on contracted objects of the same size. + * + * \param ctcs list of contractors. + */ + template + requires IsCtcBaseOrPtr + CtcInter(std::initializer_list ctcs) + : CtcInter(Collection>(ctcs)) + { } + /** * \brief Returns the number of stored contractors. * @@ -302,4 +315,11 @@ namespace codac2 // Template deduction guides CtcInter(Index) -> CtcInter; -} + + template + requires (IsCtcBaseOrPtr && ...) + CtcInter(const C&...) -> CtcInter; + + template + CtcInter(std::initializer_list) -> CtcInter; +} \ No newline at end of file diff --git a/src/core/contractors/codac2_CtcQInter.h b/src/core/contractors/codac2_CtcQInter.h index 9165c7b28..f626705cc 100644 --- a/src/core/contractors/codac2_CtcQInter.h +++ b/src/core/contractors/codac2_CtcQInter.h @@ -21,28 +21,39 @@ namespace codac2 { public: + CtcQInter(unsigned int q, const Collection>& c) + : Ctc([&c]() { + assert_release(!c.empty()); + Index n = size_of(c.front()); + for(const auto& s : c) { + assert_release(size_of(s) == n && "all contractors must be of same size"); + } + return n; + }()), _q(q), _ctcs(c) + { + assert_release(q <= c.size()); + } + explicit CtcQInter(unsigned int q, Index n, const Collection>& ctcs = {}) : Ctc(n), _q(q), _ctcs(ctcs) { + std::cout << "CtcQInter::CtcQInter(unsigned int q, Index n, ..) is deprecated." << std::endl; + std::cout << "Use CtcQInter::CtcQInter(unsigned int q, ..) instead." << std::endl; assert_release(n > 0); + assert_release(q <= ctcs.size()); } template requires (IsCtcBaseOrPtr && !std::is_same_v) CtcQInter(unsigned int q, const C& c) - : CtcQInter(q, size_of(c), {c}) - { - assert_release(q <= 1); - } + : CtcQInter(q, {c}) + { } template requires (IsCtcBaseOrPtr && ...) CtcQInter(unsigned int q, const C&... c) - : CtcQInter(q, size_first_item(c...), {c...}) - { - assert_release(all_same_size(c...)); - assert_release(q <= sizeof...(c)); - } + : CtcQInter(q, {c...}) + { } size_t nb() const; diff --git a/src/core/contractors/codac2_CtcUnion.h b/src/core/contractors/codac2_CtcUnion.h index 238934607..d7182c79f 100644 --- a/src/core/contractors/codac2_CtcUnion.h +++ b/src/core/contractors/codac2_CtcUnion.h @@ -43,6 +43,21 @@ namespace codac2 assert_release(all_same_size(c...)); } + CtcUnion(const Collection>& ctcs) + : Ctc,X...>(ctcs.front()->size()), _ctcs(ctcs) + { + for(const auto& ci : _ctcs) + { + assert_release(ci->size() == this->size()); + } + } + + template + requires IsCtcBaseOrPtr + CtcUnion(std::initializer_list ctcs) + : CtcUnion(Collection>(ctcs)) + { } + size_t nb() const { return _ctcs.size(); @@ -144,4 +159,11 @@ namespace codac2 // Template deduction guides CtcUnion(Index) -> CtcUnion; + + template + requires (IsCtcBaseOrPtr && ...) + CtcUnion(const C&...) -> CtcUnion; + + template + CtcUnion(std::initializer_list) -> CtcUnion; } \ No newline at end of file diff --git a/src/core/separators/codac2_SepInter.h b/src/core/separators/codac2_SepInter.h index 23f95617b..dcd4c76b3 100644 --- a/src/core/separators/codac2_SepInter.h +++ b/src/core/separators/codac2_SepInter.h @@ -20,10 +20,15 @@ namespace codac2 { public: - template - SepInter(const Collection& c) + template + requires IsSepBaseOrPtr + SepInter(std::initializer_list seps) + : SepInter(Collection(seps)) + { } + + SepInter(const Collection& c) : Sep([&c]() { - assert_release(!c.empty()); + assert_release(!c.empty()); return size_of(c.front()); }()), _seps(c) { } diff --git a/src/core/separators/codac2_SepQInter.h b/src/core/separators/codac2_SepQInter.h index 3abb0a8f6..342bd6a88 100644 --- a/src/core/separators/codac2_SepQInter.h +++ b/src/core/separators/codac2_SepQInter.h @@ -20,28 +20,38 @@ namespace codac2 { public: + SepQInter(unsigned int q, const Collection& c) + : Sep([&c]() { + assert_release(!c.empty()); + Index n = size_of(c.front()); + for(const auto& s : c) { + assert_release(size_of(s) == n && "all separators must be of same size"); + } + return n; + }()), _q(q), _seps(c) + { + assert_release(q <= c.size()); + } + explicit SepQInter(unsigned int q, Index n, const Collection& sep = {}) : Sep(n), _q(q), _seps(sep) { + std::cout << "SepQInter::SepQInter(unsigned int q, Index n, ..) is deprecated." << std::endl; + std::cout << "Use SepQInter::SepQInter(unsigned int q, ..) instead." << std::endl; assert_release(n > 0); } template requires (IsSepBaseOrPtr && !std::is_same_v) SepQInter(unsigned int q, const S& s) - : SepQInter(q, size_of(s), {s}) - { - assert_release(q <= 1); - } + : SepQInter(q, Collection({s})) + { } template requires (IsSepBaseOrPtr && ...) SepQInter(unsigned int q, const S&... s) - : SepQInter(q, size_first_item(s...), {s...}) - { - assert_release(all_same_size(s...)); - assert_release(q <= sizeof...(s)); - } + : SepQInter(q, Collection({s...})) + { } size_t nb() const; diff --git a/src/core/separators/codac2_SepUnion.h b/src/core/separators/codac2_SepUnion.h index e39461e07..8ea1bac2a 100644 --- a/src/core/separators/codac2_SepUnion.h +++ b/src/core/separators/codac2_SepUnion.h @@ -20,10 +20,15 @@ namespace codac2 { public: - template - SepUnion(const Collection& c) + template + requires IsSepBaseOrPtr + SepUnion(std::initializer_list seps) + : SepUnion(Collection(seps)) + { } + + SepUnion(const Collection& c) : Sep([&c]() { - assert_release(!c.empty()); + assert_release(!c.empty()); return size_of(c.front()); }()), _seps(c) { } diff --git a/src/core/tools/codac2_Collection.h b/src/core/tools/codac2_Collection.h index 12b139732..effd9fae8 100644 --- a/src/core/tools/codac2_Collection.h +++ b/src/core/tools/codac2_Collection.h @@ -35,6 +35,14 @@ namespace codac2 : std::list>(init) { } + template + requires std::is_base_of_v + Collection(std::initializer_list x) + { + for(const auto& xi : x) + this->push_back(xi); + } + Collection(const Collection& c) : std::list>() { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4ea53368d..dff12a6f4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,7 +40,9 @@ list(APPEND SRC_TESTS # listing files without extension core/contractors/codac2_tests_CtcLazy core/contractors/codac2_tests_CtcLohner core/contractors/codac2_tests_CtcPolygon + core/contractors/codac2_tests_CtcQInter core/contractors/codac2_tests_CtcSegment + core/contractors/codac2_tests_CtcUnion core/contractors/codac2_tests_CtcVisible core/contractors/codac2_tests_linear_ctc ../doc/manual/manual/contractors/geometric/src @@ -92,10 +94,13 @@ list(APPEND SRC_TESTS # listing files without extension core/separators/codac2_tests_SepCartProd core/separators/codac2_tests_SepCtcBoundary + core/separators/codac2_tests_SepInter core/separators/codac2_tests_SepInverse core/separators/codac2_tests_SepPolygon core/separators/codac2_tests_SepProj + core/separators/codac2_tests_SepQInter core/separators/codac2_tests_SepTransform + core/separators/codac2_tests_SepUnion core/separators/codac2_tests_SepVisible core/tools/codac2_tests_Approx diff --git a/tests/core/contractors/codac2_tests_CtcInter.cpp b/tests/core/contractors/codac2_tests_CtcInter.cpp index 5ad0870a8..ce6d526d1 100644 --- a/tests/core/contractors/codac2_tests_CtcInter.cpp +++ b/tests/core/contractors/codac2_tests_CtcInter.cpp @@ -9,6 +9,7 @@ #include #include +#include #include using namespace std; @@ -38,5 +39,12 @@ TEST_CASE("CtcInter") x = IntervalVector({{0,0},{0,0}}); c3.contract(x); CHECK(x == IntervalVector({{0,0},{0,0}})); + + auto c3_ = c1 | c2; + + // Testing constructors + CtcInter test_construct_1(c1,c2); + CtcInter test_construct_2({c1,c2}); // works if c1,c2 of same types + CtcInter test_construct_3(c1,c2,c3_); // different types } } \ No newline at end of file diff --git a/tests/core/contractors/codac2_tests_CtcInter.py b/tests/core/contractors/codac2_tests_CtcInter.py index 371c380f5..c196689fb 100644 --- a/tests/core/contractors/codac2_tests_CtcInter.py +++ b/tests/core/contractors/codac2_tests_CtcInter.py @@ -34,6 +34,18 @@ def test_CtcInter(self): x = IntervalVector([[0,0],[0,0]]) x = c3.contract(x) self.assertTrue(x == IntervalVector.zero(2)) + + # Testing constructors + test_construct_1 = CtcInter(c1,c2) + self.assertTrue(test_construct_1.nb() == 2) + test_construct_2 = CtcInter(c1,c2,c3) # different types + self.assertTrue(test_construct_2.nb() == 3) + + # Testing constructors (lists) + test_construct_1 = CtcInter([c1,c2]) + self.assertTrue(test_construct_1.nb() == 2) + test_construct_2 = CtcInter([c1,c2,c3]) # different types + self.assertTrue(test_construct_2.nb() == 3) if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/tests/core/contractors/codac2_tests_CtcQInter.cpp b/tests/core/contractors/codac2_tests_CtcQInter.cpp new file mode 100644 index 000000000..9d9249d70 --- /dev/null +++ b/tests/core/contractors/codac2_tests_CtcQInter.cpp @@ -0,0 +1,32 @@ +/** + * Codac tests + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2024 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#include +#include +#include +#include + +using namespace std; +using namespace codac2; + +TEST_CASE("CtcQInter") +{ + { + CtcWrapper c1(IntervalVector({{-10,10},{-2,2}})); + CtcWrapper c2(IntervalVector({{-12,2},{0,4}})); + + CtcInter c3({c1,c2}); + + // Testing constructors + CtcQInter c4(1, {c1,c2}); // works if c1,c2 of same types + CtcQInter c5(1, c1,c2,c3); // different types + CHECK(c4.nb() == 2); + CHECK(c5.nb() == 3); + } +} \ No newline at end of file diff --git a/tests/core/contractors/codac2_tests_CtcQInter.py b/tests/core/contractors/codac2_tests_CtcQInter.py new file mode 100644 index 000000000..db71badac --- /dev/null +++ b/tests/core/contractors/codac2_tests_CtcQInter.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +# Codac tests +# ---------------------------------------------------------------------------- +# \date 2024 +# \author Simon Rohou +# \copyright Copyright 2024 Codac Team +# \license GNU Lesser General Public License (LGPL) + +import unittest +from codac import * + +class TestCtcQInter(unittest.TestCase): + + def test_CtcQInter(self): + + c1 = CtcWrapper([[-10,10],[-2,2]]) + c2 = CtcWrapper([[-12,2],[0,4]]) + + c3 = c1 & c2 + + # Testing constructors + test_construct_1 = CtcQInter(1, c1,c2) + self.assertTrue(test_construct_1.nb() == 2) + test_construct_2 = CtcQInter(1, c1,c2,c3) # different types + self.assertTrue(test_construct_2.nb() == 3) + + # Testing constructors (lists) + test_construct_1 = CtcQInter(1, [c1,c2]) + self.assertTrue(test_construct_1.nb() == 2) + test_construct_2 = CtcQInter(1, [c1,c2,c3]) # different types + self.assertTrue(test_construct_2.nb() == 3) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/core/contractors/codac2_tests_CtcUnion.cpp b/tests/core/contractors/codac2_tests_CtcUnion.cpp new file mode 100644 index 000000000..9dc202d6e --- /dev/null +++ b/tests/core/contractors/codac2_tests_CtcUnion.cpp @@ -0,0 +1,31 @@ +/** + * Codac tests + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2024 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#include +#include +#include +#include + +using namespace std; +using namespace codac2; + +TEST_CASE("CtcUnion") +{ + { + CtcWrapper c1(IntervalVector({{-10,10},{-2,2}})); + CtcWrapper c2(IntervalVector({{-12,2},{0,4}})); + + auto c3 = c1 & c2; + + // Testing constructors + CtcUnion test_construct_1(c1,c2); + CtcUnion test_construct_2({c1,c2}); // works if c1,c2 of same types + CtcUnion test_construct_3(c1,c2,c3); // different types + } +} \ No newline at end of file diff --git a/tests/core/contractors/codac2_tests_CtcUnion.py b/tests/core/contractors/codac2_tests_CtcUnion.py new file mode 100644 index 000000000..bd1b7e0ad --- /dev/null +++ b/tests/core/contractors/codac2_tests_CtcUnion.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +# Codac tests +# ---------------------------------------------------------------------------- +# \date 2024 +# \author Simon Rohou +# \copyright Copyright 2024 Codac Team +# \license GNU Lesser General Public License (LGPL) + +import unittest +from codac import * + +class TestCtcUnion(unittest.TestCase): + + def test_CtcUnion(self): + + c1 = CtcWrapper([[-10,10],[-2,2]]) + c2 = CtcWrapper([[-12,2],[0,4]]) + + c3 = c1 & c2 + + # Testing constructors + test_construct_1 = CtcUnion(c1,c2) + self.assertTrue(test_construct_1.nb() == 2) + test_construct_2 = CtcUnion(c1,c2,c3) # different types + self.assertTrue(test_construct_2.nb() == 3) + + # Testing constructors (lists) + test_construct_1 = CtcUnion([c1,c2]) + self.assertTrue(test_construct_1.nb() == 2) + test_construct_2 = CtcUnion([c1,c2,c3]) # different types + self.assertTrue(test_construct_2.nb() == 3) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/core/separators/codac2_tests_SepInter.cpp b/tests/core/separators/codac2_tests_SepInter.cpp new file mode 100644 index 000000000..6caf35224 --- /dev/null +++ b/tests/core/separators/codac2_tests_SepInter.cpp @@ -0,0 +1,31 @@ +/** + * Codac tests + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2024 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#include +#include +#include +#include + +using namespace std; +using namespace codac2; + +TEST_CASE("SepInter") +{ + VectorVar v(1); + SepInverse s1(AnalyticFunction({v}, v), IntervalVector({{-1,1}})); + SepInverse s2(AnalyticFunction({v}, v), IntervalVector({{5,6}})); + + SepUnion s3(s1,s2); + + // Testing constructors + SepInter s4({s1,s2}); // works if c1,c2 of same types + SepInter s5(s1,s2,s3); // different types + CHECK(s4.nb() == 2); + CHECK(s5.nb() == 3); +} \ No newline at end of file diff --git a/tests/core/separators/codac2_tests_SepInter.py b/tests/core/separators/codac2_tests_SepInter.py new file mode 100644 index 000000000..1a3a7ab15 --- /dev/null +++ b/tests/core/separators/codac2_tests_SepInter.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +# Codac tests +# ---------------------------------------------------------------------------- +# \date 2024 +# \author Simon Rohou +# \copyright Copyright 2024 Codac Team +# \license GNU Lesser General Public License (LGPL) + +import unittest +from codac import * + +class TestSepInter(unittest.TestCase): + + def test_SepInter_box(self): + + v = VectorVar(1) + s1 = SepInverse(AnalyticFunction([v], v), IntervalVector([[-1,1]])) + s2 = SepInverse(AnalyticFunction([v], v), IntervalVector([[5,6]])) + + s3 = SepInter(s1,s2) + + # Testing constructors + s4 = SepInter(s1,s2) + s5 = SepInter(s1,s2,s3) # different types + self.assertTrue(s4.nb() == 2) + self.assertTrue(s5.nb() == 3) + + # Testing constructors (lists) + s4 = SepInter([s1,s2]) + s5 = SepInter([s1,s2,s3]) # different types + self.assertTrue(s4.nb() == 2) + self.assertTrue(s5.nb() == 3) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/core/separators/codac2_tests_SepQInter.cpp b/tests/core/separators/codac2_tests_SepQInter.cpp new file mode 100644 index 000000000..0ebf12bc0 --- /dev/null +++ b/tests/core/separators/codac2_tests_SepQInter.cpp @@ -0,0 +1,31 @@ +/** + * Codac tests + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2024 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#include +#include +#include +#include + +using namespace std; +using namespace codac2; + +TEST_CASE("SepQInter") +{ + VectorVar v(1); + SepInverse s1(AnalyticFunction({v}, v), IntervalVector({{-1,1}})); + SepInverse s2(AnalyticFunction({v}, v), IntervalVector({{5,6}})); + + SepInter s3(s1,s2); + + // Testing constructors + SepQInter s4(1, {s1,s2}); // works if c1,c2 of same types + SepQInter s5(1, s1,s2,s3); // different types + CHECK(s4.nb() == 2); + CHECK(s5.nb() == 3); +} \ No newline at end of file diff --git a/tests/core/separators/codac2_tests_SepQInter.py b/tests/core/separators/codac2_tests_SepQInter.py new file mode 100644 index 000000000..c4b72ef20 --- /dev/null +++ b/tests/core/separators/codac2_tests_SepQInter.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +# Codac tests +# ---------------------------------------------------------------------------- +# \date 2024 +# \author Simon Rohou +# \copyright Copyright 2024 Codac Team +# \license GNU Lesser General Public License (LGPL) + +import unittest +from codac import * + +class TestSepQInter(unittest.TestCase): + + def test_SepQInter_box(self): + + v = VectorVar(1) + s1 = SepInverse(AnalyticFunction([v], v), IntervalVector([[-1,1]])) + s2 = SepInverse(AnalyticFunction([v], v), IntervalVector([[5,6]])) + + s3 = SepInter(s1,s2) + + # Testing constructors + s4 = SepQInter(1, s1,s2) + s5 = SepQInter(1, s1,s2,s3) # different types + self.assertTrue(s4.nb() == 2) + self.assertTrue(s5.nb() == 3) + + # Testing constructors (lists) + s4 = SepQInter(1, [s1,s2]) + s5 = SepQInter(1, [s1,s2,s3]) # different types + self.assertTrue(s4.nb() == 2) + self.assertTrue(s5.nb() == 3) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/core/separators/codac2_tests_SepUnion.cpp b/tests/core/separators/codac2_tests_SepUnion.cpp new file mode 100644 index 000000000..e186e91dd --- /dev/null +++ b/tests/core/separators/codac2_tests_SepUnion.cpp @@ -0,0 +1,31 @@ +/** + * Codac tests + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2024 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#include +#include +#include +#include + +using namespace std; +using namespace codac2; + +TEST_CASE("SepUnion") +{ + VectorVar v(1); + SepInverse s1(AnalyticFunction({v}, v), IntervalVector({{-1,1}})); + SepInverse s2(AnalyticFunction({v}, v), IntervalVector({{5,6}})); + + SepInter s3(s1,s2); + + // Testing constructors + SepUnion s4({s1,s2}); // works if c1,c2 of same types + SepUnion s5(s1,s2,s3); // different types + CHECK(s4.nb() == 2); + CHECK(s5.nb() == 3); +} \ No newline at end of file diff --git a/tests/core/separators/codac2_tests_SepUnion.py b/tests/core/separators/codac2_tests_SepUnion.py new file mode 100644 index 000000000..ba6dbe5c2 --- /dev/null +++ b/tests/core/separators/codac2_tests_SepUnion.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +# Codac tests +# ---------------------------------------------------------------------------- +# \date 2024 +# \author Simon Rohou +# \copyright Copyright 2024 Codac Team +# \license GNU Lesser General Public License (LGPL) + +import unittest +from codac import * + +class TestSepUnion(unittest.TestCase): + + def test_SepUnion_box(self): + + v = VectorVar(1) + s1 = SepInverse(AnalyticFunction([v], v), IntervalVector([[-1,1]])) + s2 = SepInverse(AnalyticFunction([v], v), IntervalVector([[5,6]])) + + s3 = SepInter(s1,s2) + + # Testing constructors + s4 = SepUnion(s1,s2) + s5 = SepUnion(s1,s2,s3) # different types + self.assertTrue(s4.nb() == 2) + self.assertTrue(s5.nb() == 3) + + # Testing constructors (lists) + s4 = SepUnion([s1,s2]) + s5 = SepUnion([s1,s2,s3]) # different types + self.assertTrue(s4.nb() == 2) + self.assertTrue(s5.nb() == 3) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file