示例#1
0
    void testIntersect()
    {
        SequenceInterval int1("foo", 1, 100);
        SequenceInterval int2("foo", 80, 1000);

        SequenceInterval int3(int1);
        SequenceInterval int4(int2);

        SequenceInterval int5(int1);
        SequenceInterval int6("foo", 101, 1000);

        SequenceInterval int7("foo", 200, 1000);

        CPPUNIT_ASSERT(int1.intersects(int2));

        Interval int12 = int1.intersect(int2);
        CPPUNIT_ASSERT_EQUAL(80, int12.getStart());
        CPPUNIT_ASSERT_EQUAL(100, int12.getEnd());

        int3 += int4;
        CPPUNIT_ASSERT_EQUAL(1, int3.getStart());
        CPPUNIT_ASSERT_EQUAL(1000, int3.getEnd());

        Interval tint = int3 + int4;
        CPPUNIT_ASSERT_EQUAL(1, tint.getStart());
        CPPUNIT_ASSERT_EQUAL(1000, tint.getEnd());

        int5 += int6;
        CPPUNIT_ASSERT_EQUAL(1, int5.getStart());
        CPPUNIT_ASSERT_EQUAL(1000, int5.getEnd());

        CPPUNIT_ASSERT(int1.intersects(int7, 100));
    }
示例#2
0
bool Interval::intersects(Interval & interval) {
    return !(_end - 1 < interval.getStart() ||
             interval.getEnd() - 1  < _start);
}