def test_intersect(self): a = PacBioBam.PositionInterval(2, 4) b = PacBioBam.PositionInterval(3, 5) c = PacBioBam.PositionInterval(6, 8) d = PacBioBam.PositionInterval(1, 7) e = PacBioBam.PositionInterval(5, 8) # 0123456789 # a -- # b -- # c -- # d ------ # e --- # self-intersection self.assertTrue(a.Intersects(a)) # intersection is commutative self.assertTrue(a.Intersects(b)) self.assertTrue(b.Intersects(a)) # covered implies intersection self.assertTrue(d.Covers(a)) self.assertTrue(a.Intersects(d)) self.assertTrue(d.Intersects(a)) # c.start > b.stop (obvious disjoint) self.assertFalse(b.Intersects(c)) # b.stop == e.start (intervals are right-open, so disjoint) self.assertFalse(b.Intersects(e))
def test_copy(self): interval1 = PacBioBam.PositionInterval(5, 8) interval2 = PacBioBam.PositionInterval(interval1) interval3 = interval1 self.assertEqual(interval1, interval1) self.assertEqual(interval1, interval2) self.assertEqual(interval1, interval3)
def test_modifiers(self): interval1 = PacBioBam.PositionInterval(5, 8) interval2 = PacBioBam.PositionInterval(interval1) interval2.Start(2) interval2.Stop(10) self.assertNotEqual(interval1, interval2) self.assertEqual(2, interval2.Start()) self.assertEqual(10, interval2.Stop())
def test_ctors(self): empty = PacBioBam.PositionInterval() single = PacBioBam.PositionInterval(4) normal = PacBioBam.PositionInterval(5, 8) self.assertEqual(0, empty.Start()) self.assertEqual(0, empty.Stop()) self.assertEqual(4, single.Start()) self.assertEqual(5, single.Stop()) self.assertEqual(5, normal.Start()) self.assertEqual(8, normal.Stop())
def test_length(self): a = PacBioBam.PositionInterval(2, 4) b = PacBioBam.PositionInterval(3, 5) c = PacBioBam.PositionInterval(6, 8) d = PacBioBam.PositionInterval(1, 7) e = PacBioBam.PositionInterval(5, 8) self.assertEqual(2, a.Length()) self.assertEqual(2, b.Length()) self.assertEqual(2, c.Length()) self.assertEqual(6, d.Length()) self.assertEqual(3, e.Length())
def test_equality(self): empty = PacBioBam.PositionInterval() empty2 = PacBioBam.PositionInterval() singleton = PacBioBam.PositionInterval(4) sameAsSingleton = PacBioBam.PositionInterval(4, 5) normal = PacBioBam.PositionInterval(5, 8) sameAsNormal = PacBioBam.PositionInterval(5, 8) different = PacBioBam.PositionInterval(20, 40) # self-equality self.assertEqual(empty, empty) self.assertEqual(singleton, singleton) self.assertEqual(normal, normal) self.assertEqual(different, different) # same values self.assertEqual(empty, empty2) self.assertEqual(singleton, sameAsSingleton) self.assertEqual(normal, sameAsNormal) # different values self.assertNotEqual(empty, singleton) self.assertNotEqual(empty, normal) self.assertNotEqual(empty, different) self.assertNotEqual(singleton, normal) self.assertNotEqual(normal, different)
def test_cover(self): a = PacBioBam.PositionInterval(2, 4) b = PacBioBam.PositionInterval(3, 5) c = PacBioBam.PositionInterval(6, 8) d = PacBioBam.PositionInterval(1, 7) e = PacBioBam.PositionInterval(5, 8) # 0123456789 # a -- # b -- # c -- # d ------ # e --- # self-cover self.assertTrue(a.Covers(a)) self.assertTrue(a.CoveredBy(a)) # basic covers/covered self.assertTrue(b.CoveredBy(d)) self.assertTrue(d.Covers(b)) self.assertNotEqual(b, d) self.assertFalse(b.Covers(d)) # completely disjoint self.assertFalse(b.Covers(c)) self.assertFalse(c.Covers(b)) self.assertFalse(b.CoveredBy(c)) self.assertFalse(c.CoveredBy(b)) # b.stop == e.start self.assertFalse(b.Covers(e)) self.assertFalse(b.CoveredBy(e)) # shared endpoint, start contained self.assertTrue(e.Covers(c)) self.assertTrue(c.CoveredBy(e))
def test_validity(self): a = PacBioBam.PositionInterval() # default ctor b = PacBioBam.PositionInterval(0, 0) # start == stop (zero) c = PacBioBam.PositionInterval(4, 4) # start == stop (nonzero) d = PacBioBam.PositionInterval(0, 1) # start < stop (start is zero) e = PacBioBam.PositionInterval(4, 5) # start < stop (start is nonzero) f = PacBioBam.PositionInterval(5, 4) # start > stop self.assertFalse(a.IsValid()) self.assertFalse(b.IsValid()) self.assertFalse(c.IsValid()) self.assertTrue(d.IsValid()) self.assertTrue(e.IsValid()) self.assertFalse(f.IsValid())