import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.fail;
import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
import java.util.ArrayList;
ranges.add(new int[] { 3, 6 });
assertNull(MapList.traverseToPosition(ranges, 0));
}
+
+ @Test(groups = { "Functional" })
+ public void testCountPos()
+ {
+ try
+ {
+ MapList.countPos(null, 1);
+ fail("expected exception");
+ } catch (NullPointerException e)
+ {
+ // expected
+ }
+
+ List<int[]> intervals = new ArrayList<>();
+ assertNull(MapList.countPos(intervals, 1));
+
+ /*
+ * forward strand
+ */
+ intervals.add(new int[] {10, 20});
+ assertNull(MapList.countPos(intervals, 9));
+ assertNull(MapList.countPos(intervals, 21));
+ assertArrayEquals(new int[] {1, 1}, MapList.countPos(intervals, 10));
+ assertArrayEquals(new int[] {6, 1}, MapList.countPos(intervals, 15));
+ assertArrayEquals(new int[] {11, 1}, MapList.countPos(intervals, 20));
+
+ intervals.add(new int[] {25, 25});
+ assertArrayEquals(new int[] {12, 1}, MapList.countPos(intervals, 25));
+
+ // next interval repeats position 25 - which should be counted twice if traversed
+ intervals.add(new int[] {25, 26});
+ assertArrayEquals(new int[] {12, 1}, MapList.countPos(intervals, 25));
+ assertArrayEquals(new int[] {14, 1}, MapList.countPos(intervals, 26));
+
+ /*
+ * reverse strand
+ */
+ intervals.clear();
+ intervals.add(new int[] {5, -5});
+ assertNull(MapList.countPos(intervals, 6));
+ assertNull(MapList.countPos(intervals, -6));
+ assertArrayEquals(new int[] {1, -1}, MapList.countPos(intervals, 5));
+ assertArrayEquals(new int[] {7, -1}, MapList.countPos(intervals, -1));
+ assertArrayEquals(new int[] {11, -1}, MapList.countPos(intervals, -5));
+
+ /*
+ * reverse then forward
+ */
+ intervals.add(new int[] {5, 10});
+ assertArrayEquals(new int[] {13, 1}, MapList.countPos(intervals, 6));
+
+ /*
+ * reverse then forward then reverse
+ */
+ intervals.add(new int[] {-10, -20});
+ assertArrayEquals(new int[] {20, -1}, MapList.countPos(intervals, -12));
+
+ /*
+ * an interval [x, x] is treated as forward
+ */
+ intervals.add(new int[] {30, 30});
+ assertArrayEquals(new int[] {29, 1}, MapList.countPos(intervals, 30));
+ }
}