Skip to content

Commit

Permalink
Fix FrameSet bug where last frame of range would not be included. (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcipriano committed Apr 30, 2020
1 parent 4f815a6 commit b45cf72
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cuebot/src/main/java/com/imageworks/spcue/util/FrameSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public String getChunk(int startFrameIndex, int chunkSize) {
return String.valueOf(frameList.get(startFrameIndex));
}
int finalFrameIndex = frameList.size() - 1;
int endFrameIndex = startFrameIndex + chunkSize;
int endFrameIndex = startFrameIndex + chunkSize - 1;
if (endFrameIndex > finalFrameIndex) {
// We don't have enough frames, so return the remaining frames.
endFrameIndex = finalFrameIndex;
}

return framesToFrameRanges(frameList.subList(startFrameIndex, endFrameIndex));
return framesToFrameRanges(frameList.subList(startFrameIndex, endFrameIndex+1));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@

public class FrameSetTests {
@Test
public void testMultipleSegments() {
public void shouldSplitListAndMaintainOrder() {
FrameSet result = new FrameSet("57,1-3,4-2,12-15x2,76-70x-3,5-12y3,1-7:5");

assertThat(result.getAll()).containsExactly(
57, 1, 2, 3, 4, 3, 2, 12, 14, 76, 73, 70, 6, 7, 9, 10, 12, 1, 6, 2, 4, 3, 5, 7);
}

@Test
public void testSize() {
public void shouldReturnCorrectSize() {
FrameSet result = new FrameSet("1-7");

assertEquals(7, result.size());
}

@Test
public void testGet() {
public void shouldReturnSingleFrame() {
FrameSet result = new FrameSet("1-7");

assertEquals(5, result.get(4));
}

@Test
public void testIndex() {
public void shouldReturnCorrectIndexes() {
FrameSet result = new FrameSet("1-7");

assertEquals(5, result.index(6));
assertEquals(-1, result.index(22));
}

@Test
public void testFramesToFrameRanges00() {
public void shouldReconstructSteppedRange() {
FrameSet result = new FrameSet("1-10x2,11-100x20,103-108");

// int[] intArray = {1, 3, 5, 7, 9, 11, 31, 51, 71, 91, 103, 104, 105, 106, 107, 108};
Expand All @@ -47,7 +47,7 @@ public void testFramesToFrameRanges00() {
}

@Test
public void testFramesToFrameRanges01() {
public void shouldCreateNewSteppedRangeAndNextFrame() {
FrameSet result = new FrameSet("1-10x2,11-100x20,103-108");

// int[] intArray = {1, 3, 5, 7, 9, 11, 31, 51, 71, 91, 103, 104, 105, 106, 107, 108};
Expand All @@ -56,7 +56,7 @@ public void testFramesToFrameRanges01() {
}

@Test
public void testFramesToFrameRanges02() {
public void shouldReturnCommaSeparatedList() {
FrameSet result = new FrameSet("1-10x2,11-100x20,103-108");

// int[] intArray = {1, 3, 5, 7, 9, 11, 31, 51, 71, 91, 103, 104, 105, 106, 107, 108};
Expand All @@ -65,16 +65,23 @@ public void testFramesToFrameRanges02() {
}

@Test
public void testFramesToFrameRanges03() {
public void shouldReturnSubsetOfSteppedRange() {
FrameSet result = new FrameSet("1-100x3");

assertEquals("28-34x3", result.getChunk(9, 3));
}

@Test
public void testFramesToFrameRanges04() {
public void shouldReturnSubsetOfRange() {
FrameSet result = new FrameSet("1-100");

assertEquals("10-12", result.getChunk(9, 3));
}

@Test
public void shouldStopBeforeTheEndOfTheRange() {
FrameSet result = new FrameSet("55-60");

assertEquals("55-60", result.getChunk(0, 10));
}
}

0 comments on commit b45cf72

Please sign in to comment.