From 36099ad1706f1aa91d71f8191265c4843612157e Mon Sep 17 00:00:00 2001 From: Vishwa Shah Date: Thu, 13 Oct 2022 18:06:25 -0700 Subject: [PATCH 1/8] feat: Add intersection and union methods for Interval class --- .../Objects/Interval.cpp | 2 + .../Mathematics/Objects/Interval.tpp | 58 ++++++++++++++--- .../Mathematics/Objects/Interval.test.cpp | 63 ++++++++++++++----- 3 files changed, 97 insertions(+), 26 deletions(-) diff --git a/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp b/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp index d61fc500..064a3a5d 100755 --- a/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp +++ b/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp @@ -39,6 +39,8 @@ inline void OpenSpaceToolkitMathematicsPy_Objects_Interval ( .def("intersects", &Interval::intersects) .def("contains_real", +[] (const Interval& anInterval, const Real& aReal) -> bool { return anInterval.contains(aReal) ; }) .def("contains_interval", +[] (const Interval& anInterval, const Interval& anOtherInterval) -> bool { return anInterval.contains(anOtherInterval) ; }) + .def("get_intersection_with", &Interval::getIntersectionWith) + .def("get_union_with", &Interval::getUnionWith) .def("get_lower_bound", &Interval::getLowerBound) .def("get_upper_bound", &Interval::getUpperBound) diff --git a/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp b/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp index 42aa5433..c9c34d35 100644 --- a/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp +++ b/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp @@ -233,17 +233,55 @@ T Interval::getUpperBound ( ) } -// template -// Interval Interval::getIntersectionWith ( const Interval& anInterval ) const -// { -// return Interval::Undefined() ; // [TBI] -// } + template +Interval Interval::getIntersectionWith ( const Interval& anInterval ) const +{ + if (!this->isDefined()) + { + throw ostk::core::error::runtime::Undefined("Interval") ; + } -// template -// Interval Interval::getUnionWith ( const Interval& anInterval ) const -// { -// return Interval::Undefined() ; // [TBI] -// } + if (!anInterval.isDefined()) + { + throw ostk::core::error::runtime::Undefined("Interval") ; + } + + if (anInterval.getType() != type_) + { + throw ostk::core::error::runtime::Wrong("Different types of interval") ; + } + + const T lowerBound = std::max(lowerBound_, anInterval.getLowerBound()) ; + const T upperBound = std::min(upperBound_, anInterval.getUpperBound()) ; + + return Interval(lowerBound, upperBound, type_) ; + +} + + template +Interval Interval::getUnionWith ( const Interval& anInterval ) const +{ + if (!this->isDefined()) + { + throw ostk::core::error::runtime::Undefined("Interval") ; + } + + if (!anInterval.isDefined()) + { + throw ostk::core::error::runtime::Undefined("Interval") ; + } + + if (anInterval.getType() != type_) + { + throw ostk::core::error::runtime::Wrong("Different types of interval") ; + } + + const T lowerBound = std::min(lowerBound_, anInterval.getLowerBound()) ; + const T upperBound = std::max(upperBound_, anInterval.getUpperBound()) ; + + return Interval(lowerBound, upperBound, type_) ; + +} template template diff --git a/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp b/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp index 6c5c5a49..d134de9d 100644 --- a/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp +++ b/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp @@ -9,6 +9,8 @@ #include #include +#include +#include #include @@ -792,35 +794,64 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUpperBound) } -// TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetIntersectionWith) -// { +TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetIntersectionWith) +{ -// using ostk::core::types::Real ; + using ostk::core::types::Real ; + using ostk::core::ctnr::Array ; + using ostk::core::ctnr::Tuple ; -// using ostk::math::obj::Interval ; + using ostk::math::obj::Interval ; -// { + Array, Interval, Interval>> testCases = + { + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 7.0, Interval::Type::Closed), Interval(5.0, 7.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-15.0, 25.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-5.0, 7.0, Interval::Type::Closed), Interval(0.0, 7.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(5.0, 10.0, Interval::Type::Closed)}, -// FAIL() ; + } ; -// } + for (const auto& testCase : testCases) + { -// } + Interval anInterval = std::get<0>(testCase) ; + Interval anotherInterval = std::get<1>(testCase) ; + Interval truthInterval = std::get<2>(testCase) ; -// TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUnionWith) -// { + EXPECT_EQ(anInterval.getIntersectionWith(anotherInterval), truthInterval) ; + } +} -// using ostk::core::types::Real ; +TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUnionWith) +{ -// using ostk::math::obj::Interval ; + using ostk::core::types::Real ; + using ostk::core::ctnr::Array ; + using ostk::core::ctnr::Tuple ; -// { + using ostk::math::obj::Interval ; -// FAIL() ; + Array, Interval, Interval>> testCases = + { + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 7.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-15.0, 25.0, Interval::Type::Closed), Interval(-15.0, 25.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-5.0, 7.0, Interval::Type::Closed), Interval(-5.0, 10.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(0.0, 15.0, Interval::Type::Closed)}, -// } + } ; -// } + for (const auto& testCase : testCases) + { + + Interval anInterval = std::get<0>(testCase) ; + Interval anotherInterval = std::get<1>(testCase) ; + Interval truthInterval = std::get<2>(testCase) ; + + EXPECT_EQ(anInterval.getUnionWith(anotherInterval), truthInterval) ; + } + +} // TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GenerateArrayWithStep) // { From 20b9f7a6f02e985bc01b5d32dc9aab9547c46515 Mon Sep 17 00:00:00 2001 From: Vishwa Shah Date: Thu, 13 Oct 2022 18:12:53 -0700 Subject: [PATCH 2/8] feat: Add tests for python bindings --- bindings/python/test/objects/test_interval.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bindings/python/test/objects/test_interval.py b/bindings/python/test/objects/test_interval.py index 96ba27fa..defe7519 100644 --- a/bindings/python/test/objects/test_interval.py +++ b/bindings/python/test/objects/test_interval.py @@ -396,4 +396,37 @@ def test_real_interval_to_string (): assert interval_halfopenleft.to_string() == ']-4.3099999999999996, 3.0]' assert interval_halfopenright.to_string() == '[-4.3099999999999996, 3.0[' + +def test_real_interval_get_intersection_with (): + + test_cases = [ + (RealInterval(0.0, 10.0, Type.Closed),RealInterval(5.0, 7.0, Type.Closed), RealInterval(5.0, 7.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.Closed),RealInterval(-15.0, 25.0, Type.Closed), RealInterval(0.0, 10.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.Closed),RealInterval(-5.0, 7.0, Type.Closed), RealInterval(0.0, 7.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.Closed),RealInterval(5.0, 15.0, Type.Closed), RealInterval(5.0, 10.0, Type.Closed)), + ] + + for test_case in test_cases: + first_interval = test_case[0] + second_interval = test_case[1] + expected_interval = test_case[2] + + assert first_interval.get_intersection_with(second_interval) == expected_interval + +def test_real_interval_get_union_with (): + + test_cases = [ + (RealInterval(0.0, 10.0, Type.Closed), RealInterval(5.0, 7.0, Type.Closed), RealInterval(0.0, 10.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.Closed), RealInterval(-15.0, 25.0, Type.Closed), RealInterval(-15.0, 25.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.Closed), RealInterval(-5.0, 7.0, Type.Closed), RealInterval(-5.0, 10.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.Closed), RealInterval(5.0, 15.0, Type.Closed), RealInterval(0.0, 15.0, Type.Closed)), + ] + + for test_case in test_cases: + first_interval = test_case[0] + second_interval = test_case[1] + expected_interval = test_case[2] + + assert first_interval.get_union_with(second_interval) == expected_interval + ################################################################################################################################################################ From e9e61c8f7e1a51d1752b1e2b3ce149fc97eb8294 Mon Sep 17 00:00:00 2001 From: Vishwa Shah Date: Fri, 14 Oct 2022 11:21:56 -0700 Subject: [PATCH 3/8] feat: Address edge cases --- .../Mathematics/Objects/Interval.tpp | 15 +++ .../Mathematics/Objects/Interval.test.cpp | 110 ++++++++++++++---- 2 files changed, 103 insertions(+), 22 deletions(-) diff --git a/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp b/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp index c9c34d35..ce77379f 100644 --- a/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp +++ b/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp @@ -254,6 +254,11 @@ Interval Interval::getIntersectionWith ( const T lowerBound = std::max(lowerBound_, anInterval.getLowerBound()) ; const T upperBound = std::min(upperBound_, anInterval.getUpperBound()) ; + if (lowerBound > upperBound) + { + return Interval::Undefined() ; + } + return Interval(lowerBound, upperBound, type_) ; } @@ -276,9 +281,19 @@ Interval Interval::getUnionWith ( throw ostk::core::error::runtime::Wrong("Different types of interval") ; } + if (!this->intersects(anInterval)) + { + return Interval::Undefined() ; + } + const T lowerBound = std::min(lowerBound_, anInterval.getLowerBound()) ; const T upperBound = std::max(upperBound_, anInterval.getUpperBound()) ; + if (lowerBound > upperBound) + { + return Interval::Undefined() ; + } + return Interval(lowerBound, upperBound, type_) ; } diff --git a/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp b/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp index d134de9d..c95bb11f 100644 --- a/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp +++ b/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp @@ -800,26 +800,57 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetIntersectionWith) using ostk::core::types::Real ; using ostk::core::ctnr::Array ; using ostk::core::ctnr::Tuple ; + using ostk::core::types::String ; using ostk::math::obj::Interval ; + { + + Array, Interval, Interval>> testCases = + { + {Interval(0.0, 10.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight), Interval(0.0, 10.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Open), Interval(-5.0, 7.0, Interval::Type::Open), Interval(0.0, 7.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(5.0, 10.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(10.0, 15.0, Interval::Type::Closed), Interval(10.0, 10.0, Interval::Type::Closed)} + } ; - Array, Interval, Interval>> testCases = + for (const auto& testCase : testCases) { - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 7.0, Interval::Type::Closed), Interval(5.0, 7.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-15.0, 25.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-5.0, 7.0, Interval::Type::Closed), Interval(0.0, 7.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(5.0, 10.0, Interval::Type::Closed)}, - } ; + const Interval anInterval = std::get<0>(testCase) ; + const Interval anotherInterval = std::get<1>(testCase) ; + const Interval expectedInterval = std::get<2>(testCase) ; + + EXPECT_EQ(anInterval.getIntersectionWith(anotherInterval), expectedInterval); + } + } - for (const auto& testCase : testCases) { + Array, Interval>> undefinedTestCases = + { + + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(15.0, 20.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-10.0, -5.0, Interval::Type::Closed)}, + + } ; + + for (const auto& testCase : undefinedTestCases) + { + const Interval anInterval = std::get<0>(testCase) ; + const Interval anotherInterval = std::get<1>(testCase) ; - Interval anInterval = std::get<0>(testCase) ; - Interval anotherInterval = std::get<1>(testCase) ; - Interval truthInterval = std::get<2>(testCase) ; + EXPECT_TRUE(!anInterval.getIntersectionWith(anotherInterval).isDefined()) ; + + } + } + + { + + const Interval anInterval = Interval(0.0, 10.0, Interval::Type::Closed) ; + const Interval anotherInterval = Interval(0.0, 10.0, Interval::Type::Open) ; + + EXPECT_ANY_THROW(anInterval.getIntersectionWith(anotherInterval)) ; - EXPECT_EQ(anInterval.getIntersectionWith(anotherInterval), truthInterval) ; } } @@ -829,28 +860,63 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUnionWith) using ostk::core::types::Real ; using ostk::core::ctnr::Array ; using ostk::core::ctnr::Tuple ; + using ostk::core::types::String ; using ostk::math::obj::Interval ; + + { - Array, Interval, Interval>> testCases = + Array, Interval, Interval>> testCases = + { + {Interval(0.0, 10.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft), Interval(0.0, 10.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Open), Interval(-5.0, 7.0, Interval::Type::Open), Interval(-5.0, 10.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(0.0, 15.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed)}, + } ; + + for (const auto& testCase : testCases) { - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 7.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-15.0, 25.0, Interval::Type::Closed), Interval(-15.0, 25.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-5.0, 7.0, Interval::Type::Closed), Interval(-5.0, 10.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(0.0, 15.0, Interval::Type::Closed)}, - } ; + const Interval anInterval = std::get<0>(testCase) ; + const Interval anotherInterval = std::get<1>(testCase) ; + const Interval expectedInterval = std::get<2>(testCase) ; + + EXPECT_EQ(anInterval.getUnionWith(anotherInterval), expectedInterval); + } + + } - for (const auto& testCase : testCases) { - Interval anInterval = std::get<0>(testCase) ; - Interval anotherInterval = std::get<1>(testCase) ; - Interval truthInterval = std::get<2>(testCase) ; + Array, Interval>> testCases = + { + + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(15.0, 20.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-10.0, -5.0, Interval::Type::Closed)}, + + } ; + + for (const auto& testCase : testCases) + { + const Interval anInterval = std::get<0>(testCase) ; + const Interval anotherInterval = std::get<1>(testCase) ; + + EXPECT_TRUE(!anInterval.getUnionWith(anotherInterval).isDefined()) ; + + } - EXPECT_EQ(anInterval.getUnionWith(anotherInterval), truthInterval) ; } + { + + const Interval anInterval = Interval(0.0, 10.0, Interval::Type::Closed) ; + const Interval anotherInterval = Interval(5.0, 15.0, Interval::Type::Open) ; + + EXPECT_ANY_THROW(anInterval.getUnionWith(anotherInterval)) ; + + } + } // TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GenerateArrayWithStep) From 8b4e0b86a85e6c865a08c0b3c2ab77513616ea12 Mon Sep 17 00:00:00 2001 From: Vishwa Shah Date: Fri, 14 Oct 2022 11:41:59 -0700 Subject: [PATCH 4/8] feat: Address Remy's comments --- .../Objects/Interval.cpp | 12 +- bindings/python/test/objects/test_interval.py | 642 +++++++++--------- .../Mathematics/Objects/Interval.tpp | 2 + .../Mathematics/Objects/Interval.test.cpp | 13 +- 4 files changed, 337 insertions(+), 332 deletions(-) diff --git a/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp b/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp index 064a3a5d..aa025d0d 100755 --- a/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp +++ b/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp @@ -36,11 +36,11 @@ inline void OpenSpaceToolkitMathematicsPy_Objects_Interval ( .def("is_defined", &Interval::isDefined) .def("is_degenerate", &Interval::isDegenerate) - .def("intersects", &Interval::intersects) - .def("contains_real", +[] (const Interval& anInterval, const Real& aReal) -> bool { return anInterval.contains(aReal) ; }) - .def("contains_interval", +[] (const Interval& anInterval, const Interval& anOtherInterval) -> bool { return anInterval.contains(anOtherInterval) ; }) - .def("get_intersection_with", &Interval::getIntersectionWith) - .def("get_union_with", &Interval::getUnionWith) + .def("intersects", &Interval::intersects, arg("interval")) + .def("contains_real", +[] (const Interval& anInterval, const Real& aReal) -> bool { return anInterval.contains(aReal) ; }, arg("real")) + .def("contains_interval", +[] (const Interval& anInterval, const Interval& anOtherInterval) -> bool { return anInterval.contains(anOtherInterval) ; }, arg("interval")) + .def("get_intersection_with", &Interval::getIntersectionWith, arg("interval")) + .def("get_union_with", &Interval::getUnionWith, arg("interval")) .def("get_lower_bound", &Interval::getLowerBound) .def("get_upper_bound", &Interval::getUpperBound) @@ -48,7 +48,7 @@ inline void OpenSpaceToolkitMathematicsPy_Objects_Interval ( // Define static methods .def_static("undefined", &Interval::Undefined) - .def_static("closed", &Interval::Closed) + .def_static("closed", &Interval::Closed, arg("lower bound"), arg("upper bound")) ; // Add other interval types diff --git a/bindings/python/test/objects/test_interval.py b/bindings/python/test/objects/test_interval.py index defe7519..53896f94 100644 --- a/bindings/python/test/objects/test_interval.py +++ b/bindings/python/test/objects/test_interval.py @@ -20,413 +20,415 @@ ################################################################################################################################################################ -def test_real_interval_type (): +class TestInterval: - enum_members = Type.__members__ + def test_real_interval_type (self): - assert list(enum_members.keys()) == ['Undefined', 'Closed', 'Open', 'HalfOpenLeft', 'HalfOpenRight'] - assert list(enum_members.values()) == [Type.Undefined, Type.Closed, Type.Open, Type.HalfOpenLeft, Type.HalfOpenRight] + enum_members = Type.__members__ -def test_real_interval_default_constructor (): + assert list(enum_members.keys()) == ['Undefined', 'Closed', 'Open', 'HalfOpenLeft', 'HalfOpenRight'] + assert list(enum_members.values()) == [Type.Undefined, Type.Closed, Type.Open, Type.HalfOpenLeft, Type.HalfOpenRight] - # Input types for RealInterval - interval_1 = RealInterval(-4.31, 1.0, Type.Open) - interval_2 = RealInterval(-2.0, -1.0, Type.Closed) - interval_3 = RealInterval(3.5, 4567.35566, Type.HalfOpenRight) - interval_4 = RealInterval(1.45, 1.45, Type.Open) - interval_5 = RealInterval(1.45, 1.45, Type.Closed) + def test_real_interval_default_constructor (self): - assert isinstance(interval_1, RealInterval) - assert isinstance(interval_2, RealInterval) - assert isinstance(interval_3, RealInterval) - assert isinstance(interval_4, RealInterval) - assert isinstance(interval_5, RealInterval) - assert interval_1 is not None - assert interval_2 is not None - assert interval_3 is not None - assert interval_4 is not None - assert interval_5 is not None + # Input types for RealInterval + interval_1 = RealInterval(-4.31, 1.0, Type.Open) + interval_2 = RealInterval(-2.0, -1.0, Type.Closed) + interval_3 = RealInterval(3.5, 4567.35566, Type.HalfOpenRight) + interval_4 = RealInterval(1.45, 1.45, Type.Open) + interval_5 = RealInterval(1.45, 1.45, Type.Closed) - with pytest.raises(TypeError): + assert isinstance(interval_1, RealInterval) + assert isinstance(interval_2, RealInterval) + assert isinstance(interval_3, RealInterval) + assert isinstance(interval_4, RealInterval) + assert isinstance(interval_5, RealInterval) + assert interval_1 is not None + assert interval_2 is not None + assert interval_3 is not None + assert interval_4 is not None + assert interval_5 is not None - interval = RealInterval(3.0, 1, Type.Closed) + with pytest.raises(TypeError): - interval_6 = RealInterval(Real(-4.31), Real(1.0), Type.Open) - interval_7 = RealInterval(Real(-2.0), Real(-1.0), Type.Closed) - interval_8 = RealInterval(Real(3.5), Real(4567.35566), Type.HalfOpenRight) - interval_9 = RealInterval(Real(1.45), Real(1.45), Type.Open) - interval_10 = RealInterval(Real(1.45), Real(1.45), Type.Closed) + interval = RealInterval(3.0, 1, Type.Closed) - assert isinstance(interval_6, RealInterval) - assert isinstance(interval_7, RealInterval) - assert isinstance(interval_8, RealInterval) - assert isinstance(interval_9, RealInterval) - assert isinstance(interval_10, RealInterval) - assert interval_6 is not None - assert interval_7 is not None - assert interval_8 is not None - assert interval_9 is not None - assert interval_10 is not None + interval_6 = RealInterval(Real(-4.31), Real(1.0), Type.Open) + interval_7 = RealInterval(Real(-2.0), Real(-1.0), Type.Closed) + interval_8 = RealInterval(Real(3.5), Real(4567.35566), Type.HalfOpenRight) + interval_9 = RealInterval(Real(1.45), Real(1.45), Type.Open) + interval_10 = RealInterval(Real(1.45), Real(1.45), Type.Closed) - # Interval Bounds - a = -4.31 - b = 3.0 + assert isinstance(interval_6, RealInterval) + assert isinstance(interval_7, RealInterval) + assert isinstance(interval_8, RealInterval) + assert isinstance(interval_9, RealInterval) + assert isinstance(interval_10, RealInterval) + assert interval_6 is not None + assert interval_7 is not None + assert interval_8 is not None + assert interval_9 is not None + assert interval_10 is not None - # Types of RealInterval - interval_undefined = RealInterval(a, b, Type.Undefined) - interval_closed = RealInterval(a, b, Type.Closed) - interval_open = RealInterval(a, b, Type.Open) - interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) - interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) + # Interval Bounds + a = -4.31 + b = 3.0 - assert isinstance(interval_undefined, RealInterval) - assert isinstance(interval_closed, RealInterval) - assert isinstance(interval_open, RealInterval) - assert isinstance(interval_halfopenleft, RealInterval) - assert isinstance(interval_halfopenright, RealInterval) + # Types of RealInterval + interval_undefined = RealInterval(a, b, Type.Undefined) + interval_closed = RealInterval(a, b, Type.Closed) + interval_open = RealInterval(a, b, Type.Open) + interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) + interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) - # Unvalid interval definition + assert isinstance(interval_undefined, RealInterval) + assert isinstance(interval_closed, RealInterval) + assert isinstance(interval_open, RealInterval) + assert isinstance(interval_halfopenleft, RealInterval) + assert isinstance(interval_halfopenright, RealInterval) - with pytest.raises(RuntimeError): + # Unvalid interval definition - invalid_interval_1 = RealInterval(4.8, 3.5, Type.Open) + with pytest.raises(RuntimeError): - with pytest.raises(RuntimeError): + invalid_interval_1 = RealInterval(4.8, 3.5, Type.Open) - invalid_interval_2 = RealInterval(4.8, 3.5, Type.Closed) + with pytest.raises(RuntimeError): - with pytest.raises(RuntimeError): + invalid_interval_2 = RealInterval(4.8, 3.5, Type.Closed) - invalid_interval_3 = RealInterval(4.8, 3.5, Type.HalfOpenLeft) + with pytest.raises(RuntimeError): - with pytest.raises(RuntimeError): + invalid_interval_3 = RealInterval(4.8, 3.5, Type.HalfOpenLeft) - invalid_interval_4 = RealInterval(4.8, 3.5, Type.HalfOpenRight) + with pytest.raises(RuntimeError): -def test_real_interval_undefined_constructor (): + invalid_interval_4 = RealInterval(4.8, 3.5, Type.HalfOpenRight) - undefined_interval = RealInterval.undefined() + def test_real_interval_undefined_constructor (self): - assert isinstance(undefined_interval, RealInterval) - assert undefined_interval is not None - assert undefined_interval.is_defined() is False + undefined_interval = RealInterval.undefined() -def test_real_interval_closed_constructor (): + assert isinstance(undefined_interval, RealInterval) + assert undefined_interval is not None + assert undefined_interval.is_defined() is False - a = -3.1 - b = 45.6 + def test_real_interval_closed_constructor (self): - closed_interval = RealInterval.closed(a, b) + a = -3.1 + b = 45.6 - assert isinstance(closed_interval, RealInterval) - assert closed_interval is not None - assert closed_interval.is_defined() - assert closed_interval.get_lower_bound() == a - assert closed_interval.get_upper_bound() == b + closed_interval = RealInterval.closed(a, b) -def test_real_interval_is_defined (): + assert isinstance(closed_interval, RealInterval) + assert closed_interval is not None + assert closed_interval.is_defined() + assert closed_interval.get_lower_bound() == a + assert closed_interval.get_upper_bound() == b - # Interval Bounds - a = -4.31 - b = 3.0 - - # Types of RealInterval - interval_undefined = RealInterval(a, b, Type.Undefined) - interval_closed = RealInterval(a, b, Type.Closed) - interval_open = RealInterval(a, b, Type.Open) - interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) - interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) + def test_real_interval_is_defined (self): - assert interval_undefined.is_defined() is False - assert interval_closed.is_defined() is True - assert interval_open.is_defined() is True - assert interval_halfopenleft.is_defined() is True - assert interval_halfopenright.is_defined() is True - assert RealInterval.undefined().is_defined() is False + # Interval Bounds + a = -4.31 + b = 3.0 + + # Types of RealInterval + interval_undefined = RealInterval(a, b, Type.Undefined) + interval_closed = RealInterval(a, b, Type.Closed) + interval_open = RealInterval(a, b, Type.Open) + interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) + interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) -# def test_real_interval_is_degenerate (): + assert interval_undefined.is_defined() is False + assert interval_closed.is_defined() is True + assert interval_open.is_defined() is True + assert interval_halfopenleft.is_defined() is True + assert interval_halfopenright.is_defined() is True + assert RealInterval.undefined().is_defined() is False -def test_real_interval_intersects (): + # def test_real_interval_is_degenerate (): - # Interval Bounds - a = -4.31 - b = 3.0 + def test_real_interval_intersects (self): - # Types of RealInterval - interval_undefined = RealInterval(a, b, Type.Undefined) - interval_closed = RealInterval(a, b, Type.Closed) - interval_open = RealInterval(a, b, Type.Open) - interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) - interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) + # Interval Bounds + a = -4.31 + b = 3.0 - # Define Test Intervals - interval_left = RealInterval(-5.0, -4.5, Type.Closed) - interval_intersects_left = RealInterval(-5.0, -4.26, Type.Closed) - interval_right = RealInterval(4.56, 4.67, Type.Closed) - interval_intersects_right = RealInterval(2.78, 46.09, Type.Closed) - interval_between = RealInterval(-3.4, 2.45, Type.Closed) - interval_bigger = RealInterval(-45.0, 34.12, Type.Closed) + # Types of RealInterval + interval_undefined = RealInterval(a, b, Type.Undefined) + interval_closed = RealInterval(a, b, Type.Closed) + interval_open = RealInterval(a, b, Type.Open) + interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) + interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) - # Add test cases with contained intervals not Type.Closed... - # Add test cases with open intervals and half open intervals... + # Define Test Intervals + interval_left = RealInterval(-5.0, -4.5, Type.Closed) + interval_intersects_left = RealInterval(-5.0, -4.26, Type.Closed) + interval_right = RealInterval(4.56, 4.67, Type.Closed) + interval_intersects_right = RealInterval(2.78, 46.09, Type.Closed) + interval_between = RealInterval(-3.4, 2.45, Type.Closed) + interval_bigger = RealInterval(-45.0, 34.12, Type.Closed) - # Test intersects on undefined + # Add test cases with contained intervals not Type.Closed... + # Add test cases with open intervals and half open intervals... - # with pytest.raises(RuntimeError): + # Test intersects on undefined - # interval_undefined.intersects + # with pytest.raises(RuntimeError): - # Test intersects on closed + # interval_undefined.intersects - assert interval_closed.intersects(interval_left) is False - assert interval_closed.intersects(interval_intersects_left) is True - assert interval_closed.intersects(interval_right) is False - assert interval_closed.intersects(interval_intersects_right) is True - assert interval_closed.intersects(interval_between) is True - assert interval_closed.intersects(interval_bigger) is True + # Test intersects on closed - # Test intersects on open + assert interval_closed.intersects(interval_left) is False + assert interval_closed.intersects(interval_intersects_left) is True + assert interval_closed.intersects(interval_right) is False + assert interval_closed.intersects(interval_intersects_right) is True + assert interval_closed.intersects(interval_between) is True + assert interval_closed.intersects(interval_bigger) is True - assert interval_open.intersects(interval_left) is False - assert interval_open.intersects(interval_intersects_left) is True - assert interval_open.intersects(interval_right) is False - assert interval_open.intersects(interval_intersects_right) is True - assert interval_open.intersects(interval_between) is True - assert interval_open.intersects(interval_bigger) is True + # Test intersects on open - # Test intersects on halfopenleft + assert interval_open.intersects(interval_left) is False + assert interval_open.intersects(interval_intersects_left) is True + assert interval_open.intersects(interval_right) is False + assert interval_open.intersects(interval_intersects_right) is True + assert interval_open.intersects(interval_between) is True + assert interval_open.intersects(interval_bigger) is True - assert interval_halfopenleft.intersects(interval_left) is False - assert interval_halfopenleft.intersects(interval_intersects_left) is True - assert interval_halfopenleft.intersects(interval_right) is False - assert interval_halfopenleft.intersects(interval_intersects_right) is True - assert interval_halfopenleft.intersects(interval_between) is True - assert interval_halfopenleft.intersects(interval_bigger) is True + # Test intersects on halfopenleft - # Test intersects on halfopenright + assert interval_halfopenleft.intersects(interval_left) is False + assert interval_halfopenleft.intersects(interval_intersects_left) is True + assert interval_halfopenleft.intersects(interval_right) is False + assert interval_halfopenleft.intersects(interval_intersects_right) is True + assert interval_halfopenleft.intersects(interval_between) is True + assert interval_halfopenleft.intersects(interval_bigger) is True - assert interval_halfopenright.intersects(interval_left) is False - assert interval_halfopenright.intersects(interval_intersects_left) is True - assert interval_halfopenright.intersects(interval_right) is False - assert interval_halfopenright.intersects(interval_intersects_right) is True - assert interval_halfopenright.intersects(interval_between) is True - assert interval_halfopenright.intersects(interval_bigger) is True - -def test_real_interval_contains_real (): - - # Interval Bounds - a = -4.31 - b = 3.0 - - # Types of RealInterval - interval_undefined = RealInterval(a, b, Type.Undefined) - interval_closed = RealInterval(a, b, Type.Closed) - interval_open = RealInterval(a, b, Type.Open) - interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) - interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) - - # Define Reals - real_left = -5.43 - real_right = 3.1 - real_leftbound = a - real_rightbound = b - real_between_1 = 2.3 - real_between_2 = 2.999999999 - - # Test contains_real on undefined - - with pytest.raises(RuntimeError): - - interval_undefined.contains_real(real_left) - - # Test contains_real on closed - - assert interval_closed.contains_real(real_left) is False - assert interval_closed.contains_real(real_right) is False - assert interval_closed.contains_real(real_leftbound) is True - assert interval_closed.contains_real(real_rightbound) is True - assert interval_closed.contains_real(real_between_1) is True - assert interval_closed.contains_real(real_between_2) is True - - # Test contains_real on open - - assert interval_open.contains_real(real_left) is False - assert interval_open.contains_real(real_right) is False - assert interval_open.contains_real(real_leftbound) is False - assert interval_open.contains_real(real_rightbound) is False - assert interval_open.contains_real(real_between_1) is True - assert interval_open.contains_real(real_between_2) is True - - # Test contains_real on halfopenleft + # Test intersects on halfopenright - assert interval_halfopenleft.contains_real(real_left) is False - assert interval_halfopenleft.contains_real(real_right) is False - assert interval_halfopenleft.contains_real(real_leftbound) is False - assert interval_halfopenleft.contains_real(real_rightbound) is True - assert interval_halfopenleft.contains_real(real_between_1) is True - assert interval_halfopenleft.contains_real(real_between_2) is True + assert interval_halfopenright.intersects(interval_left) is False + assert interval_halfopenright.intersects(interval_intersects_left) is True + assert interval_halfopenright.intersects(interval_right) is False + assert interval_halfopenright.intersects(interval_intersects_right) is True + assert interval_halfopenright.intersects(interval_between) is True + assert interval_halfopenright.intersects(interval_bigger) is True + + def test_real_interval_contains_real (self): + + # Interval Bounds + a = -4.31 + b = 3.0 + + # Types of RealInterval + interval_undefined = RealInterval(a, b, Type.Undefined) + interval_closed = RealInterval(a, b, Type.Closed) + interval_open = RealInterval(a, b, Type.Open) + interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) + interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) + + # Define Reals + real_left = -5.43 + real_right = 3.1 + real_leftbound = a + real_rightbound = b + real_between_1 = 2.3 + real_between_2 = 2.999999999 + + # Test contains_real on undefined + + with pytest.raises(RuntimeError): + + interval_undefined.contains_real(real_left) + + # Test contains_real on closed + + assert interval_closed.contains_real(real_left) is False + assert interval_closed.contains_real(real_right) is False + assert interval_closed.contains_real(real_leftbound) is True + assert interval_closed.contains_real(real_rightbound) is True + assert interval_closed.contains_real(real_between_1) is True + assert interval_closed.contains_real(real_between_2) is True + + # Test contains_real on open + + assert interval_open.contains_real(real_left) is False + assert interval_open.contains_real(real_right) is False + assert interval_open.contains_real(real_leftbound) is False + assert interval_open.contains_real(real_rightbound) is False + assert interval_open.contains_real(real_between_1) is True + assert interval_open.contains_real(real_between_2) is True + + # Test contains_real on halfopenleft - # Test contains_real on halfopenright + assert interval_halfopenleft.contains_real(real_left) is False + assert interval_halfopenleft.contains_real(real_right) is False + assert interval_halfopenleft.contains_real(real_leftbound) is False + assert interval_halfopenleft.contains_real(real_rightbound) is True + assert interval_halfopenleft.contains_real(real_between_1) is True + assert interval_halfopenleft.contains_real(real_between_2) is True - assert interval_halfopenright.contains_real(real_left) is False - assert interval_halfopenright.contains_real(real_right) is False - assert interval_halfopenright.contains_real(real_leftbound) is True - assert interval_halfopenright.contains_real(real_rightbound) is False - assert interval_halfopenright.contains_real(real_between_1) is True - assert interval_halfopenright.contains_real(real_between_2) is True + # Test contains_real on halfopenright -def test_real_interval_contains_interval (): - - # Interval Bounds - a = -4.31 - b = 3.0 - - # Types of RealInterval - interval_undefined = RealInterval(a, b, Type.Undefined) - interval_closed = RealInterval(a, b, Type.Closed) - interval_open = RealInterval(a, b, Type.Open) - interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) - interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) - - # Define Test Intervals - interval_left = RealInterval(-5.0, -4.5, Type.Closed) - interval_intersects_left = RealInterval(-5.0, -4.56, Type.Closed) - interval_right = RealInterval(4.56, 4.67, Type.Closed) - interval_intersects_right = RealInterval(2.78, 46.09, Type.Closed) - interval_between = RealInterval(-3.4, 2.45, Type.Closed) - interval_bigger = RealInterval(-45.0, 34.12, Type.Closed) + assert interval_halfopenright.contains_real(real_left) is False + assert interval_halfopenright.contains_real(real_right) is False + assert interval_halfopenright.contains_real(real_leftbound) is True + assert interval_halfopenright.contains_real(real_rightbound) is False + assert interval_halfopenright.contains_real(real_between_1) is True + assert interval_halfopenright.contains_real(real_between_2) is True - # Add test cases with contained intervals not Type.Closed... + def test_real_interval_contains_interval (self): + + # Interval Bounds + a = -4.31 + b = 3.0 + + # Types of RealInterval + interval_undefined = RealInterval(a, b, Type.Undefined) + interval_closed = RealInterval(a, b, Type.Closed) + interval_open = RealInterval(a, b, Type.Open) + interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) + interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) + + # Define Test Intervals + interval_left = RealInterval(-5.0, -4.5, Type.Closed) + interval_intersects_left = RealInterval(-5.0, -4.56, Type.Closed) + interval_right = RealInterval(4.56, 4.67, Type.Closed) + interval_intersects_right = RealInterval(2.78, 46.09, Type.Closed) + interval_between = RealInterval(-3.4, 2.45, Type.Closed) + interval_bigger = RealInterval(-45.0, 34.12, Type.Closed) - # Test contains_interval on undefined + # Add test cases with contained intervals not Type.Closed... - with pytest.raises(RuntimeError): + # Test contains_interval on undefined - interval_undefined.contains_interval(interval_left) + with pytest.raises(RuntimeError): - # Test contains_interval on closed + interval_undefined.contains_interval(interval_left) - assert interval_closed.contains_interval(interval_left) is False - assert interval_closed.contains_interval(interval_intersects_left) is False - assert interval_closed.contains_interval(interval_right) is False - assert interval_closed.contains_interval(interval_intersects_right) is False - assert interval_closed.contains_interval(interval_between) is True - assert interval_closed.contains_interval(interval_bigger) is False + # Test contains_interval on closed - # Test contains_interval on open + assert interval_closed.contains_interval(interval_left) is False + assert interval_closed.contains_interval(interval_intersects_left) is False + assert interval_closed.contains_interval(interval_right) is False + assert interval_closed.contains_interval(interval_intersects_right) is False + assert interval_closed.contains_interval(interval_between) is True + assert interval_closed.contains_interval(interval_bigger) is False - assert interval_open.contains_interval(interval_left) is False - assert interval_open.contains_interval(interval_intersects_left) is False - assert interval_open.contains_interval(interval_right) is False - assert interval_open.contains_interval(interval_intersects_right) is False - assert interval_open.contains_interval(interval_between) is True - assert interval_open.contains_interval(interval_bigger) is False + # Test contains_interval on open - # Test contains_interval on halfopenleft + assert interval_open.contains_interval(interval_left) is False + assert interval_open.contains_interval(interval_intersects_left) is False + assert interval_open.contains_interval(interval_right) is False + assert interval_open.contains_interval(interval_intersects_right) is False + assert interval_open.contains_interval(interval_between) is True + assert interval_open.contains_interval(interval_bigger) is False - assert interval_halfopenleft.contains_interval(interval_left) is False - assert interval_halfopenleft.contains_interval(interval_intersects_left) is False - assert interval_halfopenleft.contains_interval(interval_right) is False - assert interval_halfopenleft.contains_interval(interval_intersects_right) is False - assert interval_halfopenleft.contains_interval(interval_between) is True - assert interval_halfopenleft.contains_interval(interval_bigger) is False + # Test contains_interval on halfopenleft - # Test contains_interval on halfopenright + assert interval_halfopenleft.contains_interval(interval_left) is False + assert interval_halfopenleft.contains_interval(interval_intersects_left) is False + assert interval_halfopenleft.contains_interval(interval_right) is False + assert interval_halfopenleft.contains_interval(interval_intersects_right) is False + assert interval_halfopenleft.contains_interval(interval_between) is True + assert interval_halfopenleft.contains_interval(interval_bigger) is False - assert interval_halfopenright.contains_interval(interval_left) is False - assert interval_halfopenright.contains_interval(interval_intersects_left) is False - assert interval_halfopenright.contains_interval(interval_right) is False - assert interval_halfopenright.contains_interval(interval_intersects_right) is False - assert interval_halfopenright.contains_interval(interval_between) is True - assert interval_halfopenright.contains_interval(interval_bigger) is False + # Test contains_interval on halfopenright -def test_real_interval_get_bounds (): + assert interval_halfopenright.contains_interval(interval_left) is False + assert interval_halfopenright.contains_interval(interval_intersects_left) is False + assert interval_halfopenright.contains_interval(interval_right) is False + assert interval_halfopenright.contains_interval(interval_intersects_right) is False + assert interval_halfopenright.contains_interval(interval_between) is True + assert interval_halfopenright.contains_interval(interval_bigger) is False - # Interval Bounds - a = -4.31 - b = 3.0 + def test_real_interval_get_bounds (self): - # Types of RealInterval - interval_undefined = RealInterval(a, b, Type.Undefined) - interval_closed = RealInterval(a, b, Type.Closed) - interval_open = RealInterval(a, b, Type.Open) - interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) - interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) + # Interval Bounds + a = -4.31 + b = 3.0 - # get_lower_bound - with pytest.raises(RuntimeError): + # Types of RealInterval + interval_undefined = RealInterval(a, b, Type.Undefined) + interval_closed = RealInterval(a, b, Type.Closed) + interval_open = RealInterval(a, b, Type.Open) + interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) + interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) - interval_undefined.get_lower_bound() + # get_lower_bound + with pytest.raises(RuntimeError): - assert interval_closed.get_lower_bound() == a - assert interval_open.get_lower_bound() == a - assert interval_halfopenleft.get_lower_bound() == a - assert interval_halfopenright.get_lower_bound() == a + interval_undefined.get_lower_bound() - # get_upper_bound - with pytest.raises(RuntimeError): + assert interval_closed.get_lower_bound() == a + assert interval_open.get_lower_bound() == a + assert interval_halfopenleft.get_lower_bound() == a + assert interval_halfopenright.get_lower_bound() == a - interval_undefined.get_upper_bound() + # get_upper_bound + with pytest.raises(RuntimeError): - assert interval_closed.get_upper_bound() == b - assert interval_open.get_upper_bound() == b - assert interval_halfopenleft.get_upper_bound() == b - assert interval_halfopenright.get_upper_bound() == b + interval_undefined.get_upper_bound() -def test_real_interval_to_string (): + assert interval_closed.get_upper_bound() == b + assert interval_open.get_upper_bound() == b + assert interval_halfopenleft.get_upper_bound() == b + assert interval_halfopenright.get_upper_bound() == b - # Interval Bounds - a = -4.31 - b = 3.0 + def test_real_interval_to_string (self): - # Types of RealInterval - interval_undefined = RealInterval(a, b, Type.Undefined) - interval_closed = RealInterval(a, b, Type.Closed) - interval_open = RealInterval(a, b, Type.Open) - interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) - interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) + # Interval Bounds + a = -4.31 + b = 3.0 - with pytest.raises(RuntimeError): + # Types of RealInterval + interval_undefined = RealInterval(a, b, Type.Undefined) + interval_closed = RealInterval(a, b, Type.Closed) + interval_open = RealInterval(a, b, Type.Open) + interval_halfopenleft = RealInterval(a, b, Type.HalfOpenLeft) + interval_halfopenright = RealInterval(a, b, Type.HalfOpenRight) - interval_undefined.to_string() + with pytest.raises(RuntimeError): - assert isinstance(interval_closed.to_string(), String) - assert interval_closed.to_string() == '[-4.3099999999999996, 3.0]' - assert interval_open.to_string() == ']-4.3099999999999996, 3.0[' - assert interval_halfopenleft.to_string() == ']-4.3099999999999996, 3.0]' - assert interval_halfopenright.to_string() == '[-4.3099999999999996, 3.0[' + interval_undefined.to_string() + assert isinstance(interval_closed.to_string(), String) + assert interval_closed.to_string() == '[-4.3099999999999996, 3.0]' + assert interval_open.to_string() == ']-4.3099999999999996, 3.0[' + assert interval_halfopenleft.to_string() == ']-4.3099999999999996, 3.0]' + assert interval_halfopenright.to_string() == '[-4.3099999999999996, 3.0[' -def test_real_interval_get_intersection_with (): - test_cases = [ - (RealInterval(0.0, 10.0, Type.Closed),RealInterval(5.0, 7.0, Type.Closed), RealInterval(5.0, 7.0, Type.Closed)), - (RealInterval(0.0, 10.0, Type.Closed),RealInterval(-15.0, 25.0, Type.Closed), RealInterval(0.0, 10.0, Type.Closed)), - (RealInterval(0.0, 10.0, Type.Closed),RealInterval(-5.0, 7.0, Type.Closed), RealInterval(0.0, 7.0, Type.Closed)), - (RealInterval(0.0, 10.0, Type.Closed),RealInterval(5.0, 15.0, Type.Closed), RealInterval(5.0, 10.0, Type.Closed)), - ] + def test_real_interval_get_intersection_with (self): - for test_case in test_cases: - first_interval = test_case[0] - second_interval = test_case[1] - expected_interval = test_case[2] + test_cases = [ + (RealInterval(0.0, 10.0, Type.HalfOpenLeft), RealInterval(5.0, 7.0, Type.HalfOpenLeft), RealInterval(5.0, 7.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.HalfOpenRight), RealInterval(-15.0, 25.0, Type.HalfOpenRight), RealInterval(0.0, 10.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.Closed), RealInterval(-5.0, 7.0, Type.Closed), RealInterval(0.0, 7.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.Closed), RealInterval(5.0, 15.0, Type.Closed), RealInterval(5.0, 10.0, Type.Closed)), + ] - assert first_interval.get_intersection_with(second_interval) == expected_interval + for test_case in test_cases: + first_interval = test_case[0] + second_interval = test_case[1] + expected_interval = test_case[2] -def test_real_interval_get_union_with (): + assert first_interval.get_intersection_with(second_interval) == expected_interval - test_cases = [ - (RealInterval(0.0, 10.0, Type.Closed), RealInterval(5.0, 7.0, Type.Closed), RealInterval(0.0, 10.0, Type.Closed)), - (RealInterval(0.0, 10.0, Type.Closed), RealInterval(-15.0, 25.0, Type.Closed), RealInterval(-15.0, 25.0, Type.Closed)), - (RealInterval(0.0, 10.0, Type.Closed), RealInterval(-5.0, 7.0, Type.Closed), RealInterval(-5.0, 10.0, Type.Closed)), - (RealInterval(0.0, 10.0, Type.Closed), RealInterval(5.0, 15.0, Type.Closed), RealInterval(0.0, 15.0, Type.Closed)), - ] + def test_real_interval_get_union_with (self): - for test_case in test_cases: - first_interval = test_case[0] - second_interval = test_case[1] - expected_interval = test_case[2] + test_cases = [ + (RealInterval(0.0, 10.0, Type.HalfOpenLeft), RealInterval(5.0, 7.0, Type.HalfOpenLeft), RealInterval(0.0, 10.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.HalfOpenRight), RealInterval(-15.0, 25.0, Type.HalfOpenRight), RealInterval(-15.0, 25.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.Open), RealInterval(-5.0, 7.0, Type.Open), RealInterval(-5.0, 10.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.Closed), RealInterval(5.0, 15.0, Type.Closed), RealInterval(0.0, 15.0, Type.Closed)), + ] - assert first_interval.get_union_with(second_interval) == expected_interval + for test_case in test_cases: + first_interval = test_case[0] + second_interval = test_case[1] + expected_interval = test_case[2] + + assert first_interval.get_union_with(second_interval) == expected_interval ################################################################################################################################################################ diff --git a/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp b/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp index ce77379f..a10ce099 100644 --- a/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp +++ b/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp @@ -236,6 +236,7 @@ T Interval::getUpperBound ( ) template Interval Interval::getIntersectionWith ( const Interval& anInterval ) const { + if (!this->isDefined()) { throw ostk::core::error::runtime::Undefined("Interval") ; @@ -266,6 +267,7 @@ Interval Interval::getIntersectionWith ( template Interval Interval::getUnionWith ( const Interval& anInterval ) const { + if (!this->isDefined()) { throw ostk::core::error::runtime::Undefined("Interval") ; diff --git a/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp b/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp index c95bb11f..d154d358 100644 --- a/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp +++ b/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp @@ -807,9 +807,9 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetIntersectionWith) Array, Interval, Interval>> testCases = { - {Interval(0.0, 10.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight), Interval(0.0, 10.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Open), Interval(-5.0, 7.0, Interval::Type::Open), Interval(0.0, 7.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft)}, + {Interval(0.0, 10.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight), Interval(0.0, 10.0, Interval::Type::HalfOpenRight)}, + {Interval(0.0, 10.0, Interval::Type::Open), Interval(-5.0, 7.0, Interval::Type::Open), Interval(0.0, 7.0, Interval::Type::Open)}, {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(5.0, 10.0, Interval::Type::Closed)}, {Interval(0.0, 10.0, Interval::Type::Closed), Interval(10.0, 15.0, Interval::Type::Closed), Interval(10.0, 10.0, Interval::Type::Closed)} } ; @@ -852,6 +852,7 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetIntersectionWith) EXPECT_ANY_THROW(anInterval.getIntersectionWith(anotherInterval)) ; } + } TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUnionWith) @@ -868,9 +869,9 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUnionWith) Array, Interval, Interval>> testCases = { - {Interval(0.0, 10.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft), Interval(0.0, 10.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Open), Interval(-5.0, 7.0, Interval::Type::Open), Interval(-5.0, 10.0, Interval::Type::Closed)}, + {Interval(0.0, 10.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft), Interval(0.0, 10.0, Interval::Type::HalfOpenLeft)}, + {Interval(0.0, 10.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight)}, + {Interval(0.0, 10.0, Interval::Type::Open), Interval(-5.0, 7.0, Interval::Type::Open), Interval(-5.0, 10.0, Interval::Type::Open)}, {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(0.0, 15.0, Interval::Type::Closed)}, {Interval(0.0, 10.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed)}, } ; From 5bdb803dd6512efe21b7309b587fbb987f859108 Mon Sep 17 00:00:00 2001 From: Vishwa Shah Date: Fri, 14 Oct 2022 11:55:10 -0700 Subject: [PATCH 5/8] feat: Fix python tests --- bindings/python/test/objects/test_interval.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bindings/python/test/objects/test_interval.py b/bindings/python/test/objects/test_interval.py index 53896f94..bd40ed0c 100644 --- a/bindings/python/test/objects/test_interval.py +++ b/bindings/python/test/objects/test_interval.py @@ -402,9 +402,9 @@ def test_real_interval_to_string (self): def test_real_interval_get_intersection_with (self): test_cases = [ - (RealInterval(0.0, 10.0, Type.HalfOpenLeft), RealInterval(5.0, 7.0, Type.HalfOpenLeft), RealInterval(5.0, 7.0, Type.Closed)), - (RealInterval(0.0, 10.0, Type.HalfOpenRight), RealInterval(-15.0, 25.0, Type.HalfOpenRight), RealInterval(0.0, 10.0, Type.Closed)), - (RealInterval(0.0, 10.0, Type.Closed), RealInterval(-5.0, 7.0, Type.Closed), RealInterval(0.0, 7.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.HalfOpenLeft), RealInterval(5.0, 7.0, Type.HalfOpenLeft), RealInterval(5.0, 7.0, Type.HalfOpenLeft)), + (RealInterval(0.0, 10.0, Type.HalfOpenRight), RealInterval(-15.0, 25.0, Type.HalfOpenRight), RealInterval(0.0, 10.0, Type.HalfOpenRight)), + (RealInterval(0.0, 10.0, Type.Open), RealInterval(-5.0, 7.0, Type.Open), RealInterval(0.0, 7.0, Type.Open)), (RealInterval(0.0, 10.0, Type.Closed), RealInterval(5.0, 15.0, Type.Closed), RealInterval(5.0, 10.0, Type.Closed)), ] @@ -418,9 +418,9 @@ def test_real_interval_get_intersection_with (self): def test_real_interval_get_union_with (self): test_cases = [ - (RealInterval(0.0, 10.0, Type.HalfOpenLeft), RealInterval(5.0, 7.0, Type.HalfOpenLeft), RealInterval(0.0, 10.0, Type.Closed)), - (RealInterval(0.0, 10.0, Type.HalfOpenRight), RealInterval(-15.0, 25.0, Type.HalfOpenRight), RealInterval(-15.0, 25.0, Type.Closed)), - (RealInterval(0.0, 10.0, Type.Open), RealInterval(-5.0, 7.0, Type.Open), RealInterval(-5.0, 10.0, Type.Closed)), + (RealInterval(0.0, 10.0, Type.HalfOpenLeft), RealInterval(5.0, 7.0, Type.HalfOpenLeft), RealInterval(0.0, 10.0, Type.HalfOpenLeft)), + (RealInterval(0.0, 10.0, Type.HalfOpenRight), RealInterval(-15.0, 25.0, Type.HalfOpenRight), RealInterval(-15.0, 25.0, Type.HalfOpenRight)), + (RealInterval(0.0, 10.0, Type.Open), RealInterval(-5.0, 7.0, Type.Open), RealInterval(-5.0, 10.0, Type.Open)), (RealInterval(0.0, 10.0, Type.Closed), RealInterval(5.0, 15.0, Type.Closed), RealInterval(0.0, 15.0, Type.Closed)), ] From 959bb4f0ecbc995179fd6321981cb0f3aaff1175 Mon Sep 17 00:00:00 2001 From: Remy Derollez Date: Mon, 17 Oct 2022 14:24:16 +0000 Subject: [PATCH 6/8] chore: add args doc to constructor --- .../src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp b/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp index aa025d0d..7101c1dd 100755 --- a/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp +++ b/bindings/python/src/OpenSpaceToolkitMathematicsPy/Objects/Interval.cpp @@ -25,7 +25,7 @@ inline void OpenSpaceToolkitMathematicsPy_Objects_Interval ( class_> real_interval(aModule, "RealInterval") ; // Define constructor - real_interval.def(init::Type&>()) + real_interval.def(init::Type&>(), arg("lower_bound"), arg("upper_bound"), arg("type")) // Define methods .def(self == self) @@ -48,7 +48,7 @@ inline void OpenSpaceToolkitMathematicsPy_Objects_Interval ( // Define static methods .def_static("undefined", &Interval::Undefined) - .def_static("closed", &Interval::Closed, arg("lower bound"), arg("upper bound")) + .def_static("closed", &Interval::Closed, arg("lower_bound"), arg("upper_bound")) ; // Add other interval types From f3d13b80b2ff952997b1f3652c7a9faeff2e928f Mon Sep 17 00:00:00 2001 From: Remy Derollez Date: Mon, 17 Oct 2022 14:24:54 +0000 Subject: [PATCH 7/8] style: minor adjustments --- bindings/python/test/objects/test_interval.py | 1 - .../Mathematics/Objects/Interval.test.cpp | 69 ++++++++++--------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/bindings/python/test/objects/test_interval.py b/bindings/python/test/objects/test_interval.py index bd40ed0c..7ae57604 100644 --- a/bindings/python/test/objects/test_interval.py +++ b/bindings/python/test/objects/test_interval.py @@ -398,7 +398,6 @@ def test_real_interval_to_string (self): assert interval_halfopenleft.to_string() == ']-4.3099999999999996, 3.0]' assert interval_halfopenright.to_string() == '[-4.3099999999999996, 3.0[' - def test_real_interval_get_intersection_with (self): test_cases = [ diff --git a/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp b/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp index d154d358..b5c89bca 100644 --- a/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp +++ b/test/OpenSpaceToolkit/Mathematics/Objects/Interval.test.cpp @@ -8,9 +8,10 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include -#include + #include #include +#include #include @@ -797,22 +798,23 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUpperBound) TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetIntersectionWith) { + using ostk::core::types::String ; using ostk::core::types::Real ; using ostk::core::ctnr::Array ; using ostk::core::ctnr::Tuple ; - using ostk::core::types::String ; using ostk::math::obj::Interval ; + { Array, Interval, Interval>> testCases = - { - {Interval(0.0, 10.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft)}, - {Interval(0.0, 10.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight), Interval(0.0, 10.0, Interval::Type::HalfOpenRight)}, - {Interval(0.0, 10.0, Interval::Type::Open), Interval(-5.0, 7.0, Interval::Type::Open), Interval(0.0, 7.0, Interval::Type::Open)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(5.0, 10.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(10.0, 15.0, Interval::Type::Closed), Interval(10.0, 10.0, Interval::Type::Closed)} - } ; + { + { Interval(0.0, 10.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft) }, + { Interval(0.0, 10.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight), Interval(0.0, 10.0, Interval::Type::HalfOpenRight) }, + { Interval(0.0, 10.0, Interval::Type::Open), Interval(-5.0, 7.0, Interval::Type::Open), Interval(0.0, 7.0, Interval::Type::Open) }, + { Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(5.0, 10.0, Interval::Type::Closed) }, + { Interval(0.0, 10.0, Interval::Type::Closed), Interval(10.0, 15.0, Interval::Type::Closed), Interval(10.0, 10.0, Interval::Type::Closed) } + } ; for (const auto& testCase : testCases) { @@ -822,26 +824,29 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetIntersectionWith) const Interval expectedInterval = std::get<2>(testCase) ; EXPECT_EQ(anInterval.getIntersectionWith(anotherInterval), expectedInterval); + } + } { - Array, Interval>> undefinedTestCases = - { - - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(15.0, 20.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-10.0, -5.0, Interval::Type::Closed)}, - } ; + Array, Interval>> undefinedTestCases = + { + { Interval(0.0, 10.0, Interval::Type::Closed), Interval(15.0, 20.0, Interval::Type::Closed) }, + { Interval(0.0, 10.0, Interval::Type::Closed), Interval(-10.0, -5.0, Interval::Type::Closed) }, + } ; for (const auto& testCase : undefinedTestCases) { + const Interval anInterval = std::get<0>(testCase) ; const Interval anotherInterval = std::get<1>(testCase) ; EXPECT_TRUE(!anInterval.getIntersectionWith(anotherInterval).isDefined()) ; } + } { @@ -858,23 +863,23 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetIntersectionWith) TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUnionWith) { + using ostk::core::types::String ; using ostk::core::types::Real ; using ostk::core::ctnr::Array ; using ostk::core::ctnr::Tuple ; - using ostk::core::types::String ; using ostk::math::obj::Interval ; - + { Array, Interval, Interval>> testCases = - { - {Interval(0.0, 10.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft), Interval(0.0, 10.0, Interval::Type::HalfOpenLeft)}, - {Interval(0.0, 10.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight)}, - {Interval(0.0, 10.0, Interval::Type::Open), Interval(-5.0, 7.0, Interval::Type::Open), Interval(-5.0, 10.0, Interval::Type::Open)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(0.0, 15.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed)}, - } ; + { + { Interval(0.0, 10.0, Interval::Type::HalfOpenLeft), Interval(5.0, 7.0, Interval::Type::HalfOpenLeft), Interval(0.0, 10.0, Interval::Type::HalfOpenLeft) }, + { Interval(0.0, 10.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight), Interval(-15.0, 25.0, Interval::Type::HalfOpenRight) }, + { Interval(0.0, 10.0, Interval::Type::Open), Interval(-5.0, 7.0, Interval::Type::Open), Interval(-5.0, 10.0, Interval::Type::Open) }, + { Interval(0.0, 10.0, Interval::Type::Closed), Interval(5.0, 15.0, Interval::Type::Closed), Interval(0.0, 15.0, Interval::Type::Closed) }, + { Interval(0.0, 10.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed), Interval(0.0, 10.0, Interval::Type::Closed) } + } ; for (const auto& testCase : testCases) { @@ -883,7 +888,8 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUnionWith) const Interval anotherInterval = std::get<1>(testCase) ; const Interval expectedInterval = std::get<2>(testCase) ; - EXPECT_EQ(anInterval.getUnionWith(anotherInterval), expectedInterval); + EXPECT_EQ(anInterval.getUnionWith(anotherInterval), expectedInterval) ; + } } @@ -891,21 +897,22 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUnionWith) { Array, Interval>> testCases = - { + { - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(15.0, 20.0, Interval::Type::Closed)}, - {Interval(0.0, 10.0, Interval::Type::Closed), Interval(-10.0, -5.0, Interval::Type::Closed)}, + { Interval(0.0, 10.0, Interval::Type::Closed), Interval(15.0, 20.0, Interval::Type::Closed) }, + { Interval(0.0, 10.0, Interval::Type::Closed), Interval(-10.0, -5.0, Interval::Type::Closed) }, - } ; + } ; for (const auto& testCase : testCases) { + const Interval anInterval = std::get<0>(testCase) ; const Interval anotherInterval = std::get<1>(testCase) ; EXPECT_TRUE(!anInterval.getUnionWith(anotherInterval).isDefined()) ; - } + } } @@ -917,7 +924,7 @@ TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GetUnionWith) EXPECT_ANY_THROW(anInterval.getUnionWith(anotherInterval)) ; } - + } // TEST (OpenSpaceToolkit_Mathematics_Objects_Interval, GenerateArrayWithStep) From ca3ed0752c20d3efe57f4f3aa3622f89c9cec72d Mon Sep 17 00:00:00 2001 From: Remy Derollez Date: Mon, 17 Oct 2022 14:25:32 +0000 Subject: [PATCH 8/8] chore: leverage specific TBI runtime error for future impl --- src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp b/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp index a10ce099..71ba5dfd 100644 --- a/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp +++ b/src/OpenSpaceToolkit/Mathematics/Objects/Interval.tpp @@ -249,7 +249,7 @@ Interval Interval::getIntersectionWith ( if (anInterval.getType() != type_) { - throw ostk::core::error::runtime::Wrong("Different types of interval") ; + throw ostk::core::error::runtime::ToBeImplemented("Intersection between different Interval::Type of interval.") ; } const T lowerBound = std::max(lowerBound_, anInterval.getLowerBound()) ; @@ -280,7 +280,7 @@ Interval Interval::getUnionWith ( if (anInterval.getType() != type_) { - throw ostk::core::error::runtime::Wrong("Different types of interval") ; + throw ostk::core::error::runtime::ToBeImplemented("Union between different Interval::Type of interval.") ; } if (!this->intersects(anInterval))