2016-05-02 18:31:59 +00:00
|
|
|
#include <gmock/gmock.h>
|
2017-09-10 20:17:17 +00:00
|
|
|
#include "time/ContinuousTimeline.h"
|
2016-05-02 18:31:59 +00:00
|
|
|
|
|
|
|
using namespace testing;
|
|
|
|
using std::vector;
|
|
|
|
using boost::optional;
|
|
|
|
using std::initializer_list;
|
|
|
|
|
|
|
|
TEST(ContinuousTimeline, constructors_initializeState) {
|
2016-08-09 20:31:16 +00:00
|
|
|
TimeRange range(-5_cs, 55_cs);
|
2016-05-02 18:31:59 +00:00
|
|
|
int defaultValue = -1;
|
|
|
|
auto args = {
|
2016-08-09 20:31:16 +00:00
|
|
|
Timed<int>(-10_cs, 30_cs, 1),
|
|
|
|
Timed<int>(10_cs, 40_cs, 2),
|
|
|
|
Timed<int>(50_cs, 60_cs, 3)
|
2016-05-02 18:31:59 +00:00
|
|
|
};
|
|
|
|
auto expected = {
|
2016-08-09 20:31:16 +00:00
|
|
|
Timed<int>(-5_cs, 10_cs, 1),
|
|
|
|
Timed<int>(10_cs, 40_cs, 2),
|
|
|
|
Timed<int>(40_cs, 50_cs, defaultValue),
|
|
|
|
Timed<int>(50_cs, 55_cs, 3)
|
2016-05-02 18:31:59 +00:00
|
|
|
};
|
|
|
|
EXPECT_THAT(
|
|
|
|
ContinuousTimeline<int>(range, defaultValue, args.begin(), args.end()),
|
|
|
|
ElementsAreArray(expected)
|
|
|
|
);
|
2016-12-01 19:23:41 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
ContinuousTimeline<int>(range, defaultValue, vector<Timed<int>>(args)),
|
|
|
|
ElementsAreArray(expected)
|
|
|
|
);
|
2016-05-02 18:31:59 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
ContinuousTimeline<int>(range, defaultValue, args),
|
|
|
|
ElementsAreArray(expected)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ContinuousTimeline, empty) {
|
2016-08-09 20:31:16 +00:00
|
|
|
ContinuousTimeline<int> empty(TimeRange(10_cs, 10_cs), -1);
|
2016-05-02 18:31:59 +00:00
|
|
|
EXPECT_TRUE(empty.empty());
|
|
|
|
EXPECT_THAT(empty, IsEmpty());
|
|
|
|
|
2016-08-09 20:31:16 +00:00
|
|
|
ContinuousTimeline<int> nonEmpty1(TimeRange(0_cs, 10_cs), -1);
|
2016-05-02 18:31:59 +00:00
|
|
|
EXPECT_FALSE(nonEmpty1.empty());
|
|
|
|
EXPECT_THAT(nonEmpty1, Not(IsEmpty()));
|
|
|
|
|
2016-08-09 20:31:16 +00:00
|
|
|
ContinuousTimeline<int> nonEmpty2(TimeRange(0_cs, 10_cs), -1, { Timed<int>(1_cs, 2_cs, 1) });
|
2016-05-02 18:31:59 +00:00
|
|
|
EXPECT_FALSE(nonEmpty2.empty());
|
|
|
|
EXPECT_THAT(nonEmpty2, Not(IsEmpty()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ContinuousTimeline, setAndClear) {
|
2016-08-09 20:31:16 +00:00
|
|
|
TimeRange range(0_cs, 10_cs);
|
2016-05-02 18:31:59 +00:00
|
|
|
int defaultValue = -1;
|
|
|
|
ContinuousTimeline<int> timeline(range, defaultValue);
|
|
|
|
|
|
|
|
// Out of range
|
2016-08-09 20:31:16 +00:00
|
|
|
timeline.set(-10_cs, -1_cs, 1);
|
|
|
|
timeline.set(TimeRange(-5_cs, -1_cs), 2);
|
|
|
|
timeline.set(Timed<int>(10_cs, 15_cs, 3));
|
2016-05-02 18:31:59 +00:00
|
|
|
|
|
|
|
// Overlapping
|
2016-08-09 20:31:16 +00:00
|
|
|
timeline.set(-2_cs, 3_cs, 4);
|
|
|
|
timeline.set(TimeRange(-1_cs, 1_cs), 5);
|
|
|
|
timeline.set(Timed<int>(8_cs, 12_cs, 6));
|
2016-05-02 18:31:59 +00:00
|
|
|
|
|
|
|
// Within
|
2016-08-09 20:31:16 +00:00
|
|
|
timeline.set(5_cs, 9_cs, 7);
|
|
|
|
timeline.set(TimeRange(6_cs, 7_cs), 8);
|
|
|
|
timeline.set(Timed<int>(7_cs, 8_cs, 9));
|
2016-05-02 18:31:59 +00:00
|
|
|
|
|
|
|
auto expected = {
|
2016-08-09 20:31:16 +00:00
|
|
|
Timed<int>(0_cs, 1_cs, 5),
|
|
|
|
Timed<int>(1_cs, 3_cs, 4),
|
|
|
|
Timed<int>(3_cs, 5_cs, defaultValue),
|
|
|
|
Timed<int>(5_cs, 6_cs, 7),
|
|
|
|
Timed<int>(6_cs, 7_cs, 8),
|
|
|
|
Timed<int>(7_cs, 8_cs, 9),
|
|
|
|
Timed<int>(8_cs, 9_cs, 7),
|
|
|
|
Timed<int>(9_cs, 10_cs, 6)
|
2016-05-02 18:31:59 +00:00
|
|
|
};
|
|
|
|
EXPECT_THAT(timeline, ElementsAreArray(expected));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ContinuousTimeline, shift) {
|
2016-08-09 20:31:16 +00:00
|
|
|
ContinuousTimeline<int> timeline(TimeRange(0_cs, 10_cs), -1, { { 1_cs, 2_cs, 1 },{ 2_cs, 5_cs, 2 },{ 7_cs, 9_cs, 3 } });
|
|
|
|
ContinuousTimeline<int> expected(TimeRange(2_cs, 12_cs), -1, { { 3_cs, 4_cs, 1 },{ 4_cs, 7_cs, 2 },{ 9_cs, 11_cs, 3 } });
|
|
|
|
timeline.shift(2_cs);
|
2016-05-02 18:31:59 +00:00
|
|
|
EXPECT_EQ(expected, timeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ContinuousTimeline, equality) {
|
|
|
|
vector<ContinuousTimeline<int>> timelines = {
|
2016-08-09 20:31:16 +00:00
|
|
|
ContinuousTimeline<int>(TimeRange(0_cs, 10_cs), -1),
|
|
|
|
ContinuousTimeline<int>(TimeRange(0_cs, 10_cs), 1),
|
|
|
|
ContinuousTimeline<int>(TimeRange(0_cs, 10_cs), -1, { { 1_cs, 2_cs, 1 } }),
|
|
|
|
ContinuousTimeline<int>(TimeRange(1_cs, 10_cs), -1, { { 1_cs, 2_cs, 1 } })
|
2016-05-02 18:31:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < timelines.size(); ++i) {
|
|
|
|
for (size_t j = 0; j < timelines.size(); ++j) {
|
|
|
|
if (i == j) {
|
|
|
|
EXPECT_EQ(timelines[i], ContinuousTimeline<int>(timelines[j])) << "i: " << i << ", j: " << j;
|
|
|
|
} else {
|
|
|
|
EXPECT_NE(timelines[i], timelines[j]) << "i: " << i << ", j: " << j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|