RepetitiveInterval: fix comparison
Change-Id: Ibbe5bae6da038b6a8097dc0db692ed5627dfd439
Refs: #3533
diff --git a/src/repetitive-interval.cpp b/src/repetitive-interval.cpp
index 2a441b5..a8104d1 100644
--- a/src/repetitive-interval.cpp
+++ b/src/repetitive-interval.cpp
@@ -258,17 +258,30 @@
{
if (m_startDate < interval.getStartDate())
return true;
+ else if (m_startDate > interval.getStartDate())
+ return false;
+
if (m_endDate < interval.getEndDate())
return true;
+ else if (m_endDate > interval.getEndDate())
+ return false;
+
if (m_intervalStartHour < interval.getIntervalStartHour())
return true;
+ else if (m_intervalStartHour > interval.getIntervalStartHour())
+ return false;
+
if (m_intervalEndHour < interval.getIntervalEndHour())
return true;
+ else if (m_intervalEndHour > interval.getIntervalEndHour())
+ return false;
+
if (m_nRepeats < interval.getNRepeats())
return true;
- if (static_cast<size_t>(m_unit) < static_cast<size_t>(interval.getRepeatUnit()))
- return true;
- return false;
+ else if (m_nRepeats > interval.getNRepeats())
+ return false;
+
+ return (static_cast<size_t>(m_unit) < static_cast<size_t>(interval.getRepeatUnit()));
}
} // namespace gep
diff --git a/tests/unit-tests/repetitive-interval.t.cpp b/tests/unit-tests/repetitive-interval.t.cpp
index 65ac8ae..51abdf8 100644
--- a/tests/unit-tests/repetitive-interval.t.cpp
+++ b/tests/unit-tests/repetitive-interval.t.cpp
@@ -200,6 +200,50 @@
BOOST_CHECK(repetitiveInterval3.getRepeatUnit() == RepetitiveInterval::RepeatUnit::DAY);
}
+static bool
+check(const RepetitiveInterval& small, const RepetitiveInterval& big)
+{
+ return (small < big && !(big < small));
+}
+
+BOOST_AUTO_TEST_CASE(Comparison)
+{
+ BOOST_CHECK(check(RepetitiveInterval(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY),
+ RepetitiveInterval(from_iso_string("20150826T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY)));
+
+ BOOST_CHECK(check(RepetitiveInterval(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY),
+ RepetitiveInterval(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 6, 10, 2, RepetitiveInterval::RepeatUnit::DAY)));
+
+ BOOST_CHECK(check(RepetitiveInterval(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY),
+ RepetitiveInterval(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 11, 2, RepetitiveInterval::RepeatUnit::DAY)));
+
+ BOOST_CHECK(check(RepetitiveInterval(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY),
+ RepetitiveInterval(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 10, 3, RepetitiveInterval::RepeatUnit::DAY)));
+
+ BOOST_CHECK(check(RepetitiveInterval(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY),
+ RepetitiveInterval(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::MONTH)));
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
diff --git a/tests/unit-tests/schedule.t.cpp b/tests/unit-tests/schedule.t.cpp
index 0fb6c3f..61a974a 100644
--- a/tests/unit-tests/schedule.t.cpp
+++ b/tests/unit-tests/schedule.t.cpp
@@ -200,11 +200,11 @@
0x87, 0x0f,
0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x38, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
0x88, 0x01,
- 0x05,
+ 0x06,
0x89, 0x01,
- 0x0a,
+ 0x08,
0x8a, 0x01,
- 0x02,
+ 0x01,
0x8b, 0x01,
0x01,
/////
@@ -214,11 +214,11 @@
0x87, 0x0f,
0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x38, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
0x88, 0x01,
- 0x06,
+ 0x05,
0x89, 0x01,
- 0x08,
+ 0x0a,
0x8a, 0x01,
- 0x01,
+ 0x02,
0x8b, 0x01,
0x01,
/////