@Test public void testShifts() { Slice sl; sl = new Slice().setLength(12); sl.setStop(2); assertEquals(2, sl.getNumSteps()); assertFalse(sl.setPosition(5)); assertEquals(5, (int) sl.getStart()); assertEquals(7, (int) sl.getStop()); sl.setStart(5); assertEquals(5, (int) sl.getStart()); assertTrue(sl.setPosition(11)); }
@Test public void testSliceSteps() { Slice sl; sl = new Slice(null, null, 3).setLength(1); assertEquals(1, sl.getNumSteps()); sl = new Slice(null, null, 3).setLength(2); assertEquals(1, sl.getNumSteps()); sl = new Slice(null, null, 3).setLength(3); assertEquals(1, sl.getNumSteps()); sl = new Slice(null, null, 3).setLength(4); assertEquals(2, sl.getNumSteps()); sl = new Slice(null, null, 3).setLength(5); assertEquals(2, sl.getNumSteps()); sl = new Slice(null, null, 3).setLength(6); assertEquals(2, sl.getNumSteps()); sl = new Slice(null, null, 3).setLength(7); assertEquals(3, sl.getNumSteps()); sl = new Slice(null, null, 3).setLength(8); assertEquals(3, sl.getNumSteps()); sl = new Slice(null, null, 3).setLength(9); assertEquals(3, sl.getNumSteps()); sl = new Slice().setLength(12); assertEquals(12, sl.getNumSteps()); sl = new Slice(null, null, 2).setLength(12); assertEquals(6, sl.getNumSteps()); sl = new Slice(1, null).setLength(12); assertEquals(11, sl.getNumSteps()); sl = new Slice(1, null, 2).setLength(12); assertEquals(6, sl.getNumSteps()); sl = new Slice(1, null, -2).setLength(12); assertEquals(1, sl.getNumSteps()); sl = new Slice(null, null, -1).setLength(12); assertEquals(12, sl.getNumSteps()); sl = new Slice(null, null, -2).setLength(12); assertEquals(6, sl.getNumSteps()); sl = new Slice(6, null, -2).setLength(12); assertEquals(4, sl.getNumSteps()); sl = new Slice(6, 1, -2).setLength(12); assertEquals(3, sl.getNumSteps()); sl = new Slice(6, 0, -2).setLength(12); assertEquals(3, sl.getNumSteps()); try { sl = new Slice(); sl.getNumSteps(); fail("No exception thrown"); } catch (IllegalStateException ise) { // passed } catch (Exception e) { fail("Wrong exception type passed, this should give an IllegalStateException"); } sl = new Slice(12); assertEquals(12, sl.getNumSteps()); sl = new Slice(1, 12); assertEquals(11, sl.getNumSteps()); sl = new Slice(12, 1); assertEquals(0, sl.getNumSteps()); sl = new Slice(1, 12, 2); assertEquals(6, sl.getNumSteps()); sl = new Slice(1, 12, 12); assertEquals(1, sl.getNumSteps()); sl = new Slice(12, 1, -1); assertEquals(11, sl.getNumSteps()); sl = new Slice(1, 12, -1); assertEquals(0, sl.getNumSteps()); sl = new Slice(12, 1, -2); assertEquals(6, sl.getNumSteps()); sl = new Slice(12, 1, -12); assertEquals(1, sl.getNumSteps()); sl = new Slice(null, 11, 1); assertEquals(11, sl.getNumSteps()); try { sl = new Slice(11, null, -1); sl.getNumSteps(); fail("No exception thrown"); } catch (IllegalStateException ise) { // passed } catch (Exception e) { fail("Wrong exception type passed, this should give an IllegalStateException"); } sl = new Slice(null, null, 15).setLength(4096); assertEquals(274, sl.getNumSteps()); }