01: /*
02: * ====================================================================
03: * Copyright (c) 2004 Marc Strapetz, marc.strapetz@smartsvn.com.
04: * All rights reserved.
05: *
06: * This software is licensed as described in the file COPYING, which
07: * you should have received as part of this distribution. Use is
08: * subject to license terms.
09: * ====================================================================
10: */
11:
12: package de.regnis.q.sequence;
13:
14: import java.util.*;
15: import junit.framework.*;
16:
17: import de.regnis.q.sequence.core.*;
18: import de.regnis.q.sequence.media.*;
19:
20: /**
21: * @author Marc Strapetz
22: */
23: public class QSequenceDifferenceBlockShifterTest extends TestCase {
24:
25: // Accessing ==============================================================
26:
27: public void test() throws QSequenceException {
28: test2("aa", "aaa", "aa", "aa-");
29: test2("xaa", "yaaa", "-aa", "--aa");
30: test2("ababab", "abababab", "ababab", "ababab--");
31: test2("xababab", "yabababab", "-ababab", "---ababab");
32: test2(
33: "public class PolygonExtractionTree implements QBBox2D {",
34: "class PolygonExtractionTree implements QBBox2D {",
35: "-------class PolygonExtractionTree implements QBBox2D {",
36: "class PolygonExtractionTree implements QBBox2D {");
37: test2("abcde", "axcye", "a-c-e", "a-c-e");
38: test2("ab*#cd*#", "ab*#ef*#cd*#", "ab*#cd*#", "ab*#----cd*#");
39: }
40:
41: // Utils ==================================================================
42:
43: private void test2(String left, String right, String leftTest,
44: String rightTest) throws QSequenceException {
45: test1(left, right, leftTest, rightTest);
46: test1(right, left, rightTest, leftTest);
47: }
48:
49: private void test1(String left, String right, String leftTest,
50: String rightTest) throws QSequenceException {
51: final QSequenceTestMedia media = QSequenceTestMedia
52: .createCharacterMedia(left, right);
53:
54: final QSequenceDifference difference = new QSequenceDifference(
55: media, new QSequenceMediaDummyIndexTransformer(media
56: .getLeftLength(), media.getRightLength()));
57: final List blocks = difference.getBlocks();
58:
59: final QSequenceDifferenceBlockShifter blockShifter = new QSequenceDifferenceBlockShifter(
60: media, media);
61: blockShifter.shiftBlocks(blocks);
62:
63: final StringBuffer leftBuffer = new StringBuffer(left);
64: final StringBuffer rightBuffer = new StringBuffer(right);
65: for (int index = 0; index < blocks.size(); index++) {
66: final QSequenceDifferenceBlock block = (QSequenceDifferenceBlock) blocks
67: .get(index);
68:
69: final int leftFrom = block.getLeftFrom();
70: final int leftTo = block.getLeftTo();
71: if (leftFrom <= leftTo) {
72: leftBuffer.replace(leftFrom, leftTo + 1,
73: QSequenceDifferenceCoreTest.fillWithChar("",
74: leftTo - leftFrom + 1, '-'));
75: }
76:
77: final int rightFrom = block.getRightFrom();
78: final int rightTo = block.getRightTo();
79: if (rightFrom <= rightTo) {
80: rightBuffer.replace(rightFrom, rightTo + 1,
81: QSequenceDifferenceCoreTest.fillWithChar("",
82: rightTo - rightFrom + 1, '-'));
83: }
84: }
85:
86: assertEquals(leftTest, leftBuffer.toString());
87: assertEquals(rightTest, rightBuffer.toString());
88: }
89: }
|