@Test public void testGetBlackBeforeWhite() { barcode.addWhite(0, 1000); int filler = 1000; while(filler > 0) { int whereToAdd = random.nextInt(barcode.size()); int amountToAdd = random.nextInt(filler + 1); barcode.addBlack(whereToAdd, amountToAdd); filler -= amountToAdd; } for(int i = 0;i < barcode.whiteSize();i++) { int actualWhiteIndex = barcode.getIndex(i, Barcode.WHITE); int blackBeforeIndex = barcode.getBlackBeforeWhite(i); int actualBlackIndex = barcode.getBlackIndex(actualWhiteIndex, true); assertEquals(actualBlackIndex, blackBeforeIndex); } }
public int getBlackBeforeWhite(int whiteIndex) { if(root == null) { return -1; } else if(whiteIndex >= root.whiteSize()) { return root.blackSize() - 1; } else { return root.getBlackBeforeWhite(whiteIndex); } }
Barcode { public int getBlackBeforeWhite(int whiteIndex) { if(root == null) { return -1; } else if(whiteIndex >= root.whiteSize()) { return root.blackSize() - 1; } else { return root.getBlackBeforeWhite(whiteIndex); } } }
Barcode { public int getBlackBeforeWhite(int whiteIndex) { if(root == null) { return -1; } else if(whiteIndex >= root.whiteSize()) { return root.blackSize() - 1; } else { return root.getBlackBeforeWhite(whiteIndex); } }  }
Barcode { public int getBlackBeforeWhite(int whiteIndex) { if(root == null) { return -1; } else if(whiteIndex >= root.whiteSize()) { return root.blackSize() - 1; } else { return root.getBlackBeforeWhite(whiteIndex); } }  void printDebug(); void validate(); int size(); boolean isEmpty(); int whiteSize(); int blackSize(); int colourSize(Object colour); void add(int index, Object colour, int length); void addWhite(int index, int length); void addBlack(int index, int length); Object get(int index); void set(int index, Object colour, int length); void setWhite(int index, int length); void setBlack(int index, int length); void remove(int index, int length); void clear(); int getIndex(int colourIndex, Object colour); int getColourIndex(int index, Object colour); int getWhiteIndex(int index); int getBlackIndex(int index); int getColourIndex(int index, boolean left, Object colour); int getWhiteIndex(int index, boolean left); int getBlackIndex(int index, boolean left); int getWhiteSequenceIndex(int whiteIndex); int getBlackBeforeWhite(int whiteIndex); int findSequenceOfMinimumSize(int size, Object colour); BarcodeIterator iterator(); @Override String toString(); }
Barcode { public int getBlackBeforeWhite(int whiteIndex) { if(root == null) { return -1; } else if(whiteIndex >= root.whiteSize()) { return root.blackSize() - 1; } else { return root.getBlackBeforeWhite(whiteIndex); } }  void printDebug(); void validate(); int size(); boolean isEmpty(); int whiteSize(); int blackSize(); int colourSize(Object colour); void add(int index, Object colour, int length); void addWhite(int index, int length); void addBlack(int index, int length); Object get(int index); void set(int index, Object colour, int length); void setWhite(int index, int length); void setBlack(int index, int length); void remove(int index, int length); void clear(); int getIndex(int colourIndex, Object colour); int getColourIndex(int index, Object colour); int getWhiteIndex(int index); int getBlackIndex(int index); int getColourIndex(int index, boolean left, Object colour); int getWhiteIndex(int index, boolean left); int getBlackIndex(int index, boolean left); int getWhiteSequenceIndex(int whiteIndex); int getBlackBeforeWhite(int whiteIndex); int findSequenceOfMinimumSize(int size, Object colour); BarcodeIterator iterator(); @Override String toString(); static final Object WHITE; static final Object BLACK; }