@Test(dataProvider = "intervalsSameContig") public void testOverlap(final List<Locatable> input, final Interval query, final List<Locatable> expected) throws Exception { final OverlapDetector<Locatable> targetDetector = OverlapDetector.create(input); final Set<Locatable> actual = targetDetector.getOverlaps(query); Assert.assertEquals(actual, new HashSet<>(expected)); Assert.assertEquals(targetDetector.overlapsAny(query), !expected.isEmpty()); Assert.assertEquals(new HashSet<>(targetDetector.getAll()), new HashSet<>(input)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testOverlapsNullArg() throws Exception { final List<Locatable> input = Arrays.asList( new Interval("1",10,100) ); final OverlapDetector<Locatable> targetDetector = OverlapDetector.create(input); targetDetector.overlapsAny(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullArgGetOverlaps() throws Exception { final List<Locatable> input = Arrays.asList( new Interval("1",10,100) ); final OverlapDetector<Locatable> targetDetector = OverlapDetector.create(input); targetDetector.getOverlaps(null); }
@Test public void testLotsOfTinyIntervals() throws Exception { final List<Locatable> input = new ArrayList<>(); final int n = 1000000; for (int i = 0; i < n; i++) { input.add(new Interval("1", 3*i+1, 3*i+2)); //1:1-2, 1:4-5, 1:7-8 } final OverlapDetector<Locatable> detector = OverlapDetector.create(input); final Set<Locatable> overlapping = detector.getOverlaps(new Interval("1", 1, 3 * n + 2)); Assert.assertEquals(new HashSet<>(input), overlapping); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullObjectsAddAll() throws Exception { final List<Locatable> input = Arrays.asList( new Interval("1",10,100) ); final OverlapDetector<Locatable> targetDetector = OverlapDetector.create(input); targetDetector.addAll(null, Arrays.asList(new Interval("2",10,100))); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullIntervalsAddAll() throws Exception { final List<Locatable> input = Arrays.asList( new Interval("1",10,100) ); final OverlapDetector<Locatable> targetDetector = OverlapDetector.create(input); targetDetector.addAll(Arrays.asList(new Interval("2",10,100)), null); }
@Test public void testAddTwice() throws Exception { final List<Locatable> input = Arrays.asList( new Interval("1",10,100), new Interval("1",10,100) ); final OverlapDetector<Locatable> detector = OverlapDetector.create(input); final Set<Locatable> overlaps = detector.getOverlaps(new Interval("1", 50, 200)); Assert.assertEquals(overlaps.size(), 1); Assert.assertEquals(overlaps, Collections.singleton(new Interval("1",10,100))); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullObjectAddLHS() throws Exception { final List<Locatable> input = Arrays.asList( new Interval("1",10,100) ); final OverlapDetector<Locatable> targetDetector = OverlapDetector.create(input); targetDetector.addLhs(null, new Interval("2",10,100)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullIntervalAddLHS() throws Exception { final List<Locatable> input = Arrays.asList( new Interval("1",10,100) ); final OverlapDetector<Locatable> targetDetector = OverlapDetector.create(input); targetDetector.addLhs(new Interval("2",10,100), null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testDifferentSizesAddAll() throws Exception { final List<Locatable> input = Arrays.asList( new Interval("1",10,100) ); final OverlapDetector<Locatable> targetDetector = OverlapDetector.create(input); final List<Locatable> l1 = Arrays.asList(new Interval("2", 10, 100)); final List<Locatable> l2 = Arrays.asList(new Interval("2", 10, 100), new Interval("3", 10, 100)); targetDetector.addAll(l1, l2); }
overlapDetector = OverlapDetector.create(intervals);
@Test(expectedExceptions = IllegalArgumentException.class) public void testAddAllDifferentSizes() throws Exception { final List<Locatable> input = Arrays.asList( new Interval("1",10,100) ); final OverlapDetector<Locatable> targetDetector = OverlapDetector.create(input); final List<Locatable> input1Interval = Arrays.asList( new Interval("1",11,101) ); final List<Locatable> input2Intervals = Arrays.asList( new Interval("1",20,200), new Interval("1",20,200) ); targetDetector.addAll(input1Interval, input2Intervals); }
overlapDetector = OverlapDetector.create(intervals);