BsDiff { static Match searchForMatchBaseCase( final RandomAccessObject groupArray, final RandomAccessObject oldData, final RandomAccessObject newData, final int newStart, final int oldDataRangeStartA, final int oldDataRangeStartB) throws IOException { groupArray.seekToIntAligned(oldDataRangeStartA); final int groupArrayOldDataRangeStartA = groupArray.readInt(); final int lengthOfMatchA = lengthOfMatch(oldData, groupArrayOldDataRangeStartA, newData, newStart); groupArray.seekToIntAligned(oldDataRangeStartB); final int groupArrayOldDataRangeStartB = groupArray.readInt(); final int lengthOfMatchB = lengthOfMatch(oldData, groupArrayOldDataRangeStartB, newData, newStart); if (lengthOfMatchA > lengthOfMatchB) { return Match.of(groupArrayOldDataRangeStartA, lengthOfMatchA); } return Match.of(groupArrayOldDataRangeStartB, lengthOfMatchB); }    }
@Test public void searchForMatchBaseCaseShortGroupArrayTest() throws IOException { final String s1 = "asdf;1234;this should match;5678"; final String s2 = "hkjl.9999.00vbn,``'=-this should match.9900-mmmnmn,,,.x??'"; final byte[] s1b = s1.getBytes(Charset.forName("US-ASCII")); final byte[] s2b = s2.getBytes(Charset.forName("US-ASCII")); final RandomAccessObject s1ro = new RandomAccessObject.RandomAccessByteArrayObject(s1b); final RandomAccessObject s2ro = new RandomAccessObject.RandomAccessByteArrayObject(s2b); final RandomAccessObject groupArrayRO = intArrayToRandomAccessObject(BsDiffTestData.SHORT_GROUP_ARRAY); BsDiff.Match ret = BsDiff.searchForMatchBaseCase(groupArrayRO, s1ro, s2ro, 0, 0, 12); Assert.assertEquals(0, ret.length); Assert.assertEquals(12, ret.start); ret = BsDiff.searchForMatchBaseCase(groupArrayRO, s1ro, s2ro, 0, 9, 10); Assert.assertEquals(0, ret.length); Assert.assertEquals(10, ret.start); }
@Test public void searchForMatchBaseCaseLongGroupArrayTest() throws IOException { final RandomAccessObject groupArray2RO = intArrayToRandomAccessObject(BsDiffTestData.LONG_GROUP_ARRAY_100); final int scan = 1; BsDiff.Match ret = BsDiff.searchForMatchBaseCase( groupArray2RO, BsDiffTestData.LONG_DATA_99_RO, BsDiffTestData.LONG_DATA_104_NEW_RO, scan, 0, BsDiffTestData.LONG_DATA_99.length); Assert.assertEquals(0, ret.length); Assert.assertEquals(10, ret.start); ret = BsDiff.searchForMatchBaseCase( groupArray2RO, BsDiffTestData.LONG_DATA_99_RO, BsDiffTestData.LONG_DATA_104_NEW_RO, scan, 64, 65); Assert.assertEquals(0, ret.length); Assert.assertEquals(52, ret.start); ret = BsDiff.searchForMatchBaseCase( groupArray2RO, BsDiffTestData.LONG_DATA_99_RO, BsDiffTestData.LONG_DATA_104_NEW_RO, scan, 1, 2); Assert.assertEquals(0, ret.length); Assert.assertEquals(46, ret.start); }
@Test public void searchForMatchBaseCaseVeryLongGroupArrayTest() throws IOException { final RandomAccessObject groupArray3RO = intArrayToRandomAccessObject(BsDiffTestData.LONGER_GROUP_ARRAY_350); final int scan = 1; BsDiff.Match ret = BsDiff.searchForMatchBaseCase( groupArray3RO, BsDiffTestData.LONGER_DATA_349_RO, BsDiffTestData.LONGER_DATA_354_NEW_RO, scan, 0, BsDiffTestData.LONGER_DATA_349.length); Assert.assertEquals(0, ret.length); Assert.assertEquals(246, ret.start); ret = BsDiff.searchForMatchBaseCase( groupArray3RO, BsDiffTestData.LONGER_DATA_349_RO, BsDiffTestData.LONGER_DATA_354_NEW_RO, scan, 219, 220); Assert.assertEquals(0, ret.length); Assert.assertEquals(251, ret.start); }