本文整理汇总了C++中IntervalSet::intervalCount方法的典型用法代码示例。如果您正苦于以下问题:C++ IntervalSet::intervalCount方法的具体用法?C++ IntervalSet::intervalCount怎么用?C++ IntervalSet::intervalCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IntervalSet
的用法示例。
在下文中一共展示了IntervalSet::intervalCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(IntervalTest, Intersection)
{
IntervalSet<int> set;
set += (Bound<int>::closed(1), Bound<int>::closed(3));
EXPECT_TRUE(set.contains(1));
EXPECT_EQ(1u, set.intervalCount());
EXPECT_EQ(3u, set.size());
set &= (Bound<int>::open(1), Bound<int>::open(5));
EXPECT_FALSE(set.contains(1));
EXPECT_EQ(1u, set.intervalCount());
EXPECT_EQ(2u, set.size());
IntervalSet<int> set2;
set2 += 6;
set &= set2;
EXPECT_TRUE(set.empty());
EXPECT_EQ(0u, set.intervalCount());
}
示例2: foreach
TEST(IntervalTest, IntervalIteration)
{
IntervalSet<int> set;
set += (Bound<int>::closed(0), Bound<int>::closed(1));
set += (Bound<int>::open(2), Bound<int>::open(4));
set += (Bound<int>::closed(5), Bound<int>::open(7));
set += (Bound<int>::open(7), Bound<int>::closed(9));
EXPECT_EQ(4u, set.intervalCount());
int index = 0;
foreach (const Interval<int>& interval, set) {
if (index == 0) {
EXPECT_EQ(0, interval.lower());
EXPECT_EQ(2, interval.upper());
} else if (index == 1) {
EXPECT_EQ(3, interval.lower());
EXPECT_EQ(4, interval.upper());
} else if (index == 2) {
EXPECT_EQ(5, interval.lower());
EXPECT_EQ(7, interval.upper());
} else if (index == 3) {
EXPECT_EQ(8, interval.lower());
EXPECT_EQ(10, interval.upper());
}
index++;
}
}