Add simple test for LineMapper.appendReplace

Change-Id: I19902da5445bd63c8a8c4578426a8b22d93e96c7
This commit is contained in:
Shawn Pearce
2013-12-27 20:54:30 -08:00
parent a76877cfb0
commit a9119b8061
2 changed files with 29 additions and 4 deletions

View File

@@ -52,11 +52,9 @@ class LineMapper {
void appendReplace(int aLen, int bLen) {
appendCommon(Math.min(aLen, bLen));
if (aLen < bLen) { // Edit with insertion
int insertCnt = bLen - aLen;
appendInsert(insertCnt);
appendInsert(bLen - aLen);
} else if (aLen > bLen) { // Edit with deletion
int deleteCnt = aLen - bLen;
appendDelete(deleteCnt);
appendDelete(aLen - bLen);
}
}

View File

@@ -102,4 +102,31 @@ public class LineMapperTest {
assertEquals(new LineOnOtherInfo(10, true),
mapper.lineOnOther(DisplaySide.B, 0));
}
@Test
public void testReplaceWithInsertInB() {
// 0 c c
// 1 a b
// 2 a b
// 3 - b
// 4 - b
// 5 c c
LineMapper mapper = new LineMapper();
mapper.appendCommon(1);
mapper.appendReplace(2, 4);
mapper.appendCommon(1);
assertEquals(4, mapper.getLineA());
assertEquals(6, mapper.getLineB());
assertEquals(new LineOnOtherInfo(1, true),
mapper.lineOnOther(DisplaySide.B, 1));
assertEquals(new LineOnOtherInfo(3, true),
mapper.lineOnOther(DisplaySide.B, 5));
assertEquals(new LineOnOtherInfo(2, true),
mapper.lineOnOther(DisplaySide.B, 2));
assertEquals(new LineOnOtherInfo(2, false),
mapper.lineOnOther(DisplaySide.B, 3));
}
}