private void assertSingleMoveEntry( int lhsDoc, int lhsOfs, int lhsEnd, int rhsDoc, int rhsOfs, int rhsEnd) { MoveList ml = movesManager.getAllMoves(lhsDoc, rhsDoc); assertEquals("Size of move list is wrong", 1, ml.size()); FragmentPair fp = ml.get(0); assertMove(fp, lhsDoc, lhsOfs, lhsEnd, rhsDoc, rhsOfs, rhsEnd); }
private void createMove( int baseIndex, int baseOffset, int baseEnd, int witnessIndex, int witnessOffset, int witnessEnd) throws LoggedException { MovesManager.FragmentPair fp = createFragmentPair(baseIndex, baseOffset, baseEnd, witnessIndex, witnessOffset, witnessEnd); movesManager.createMove(fp.first, fp.second); }
protected void setUp() throws Exception { super.setUp(); // SimpleLogger.initFileLogging(System.getProperty("user.dir") + "/juxta.log"); SimpleLogger.initConsoleLogging(); // SimpleLogger.setLoggingLevel(DiffAlgorithm.VERBOSE_LOGGING); log = new DebugLogger(System.getProperty("user.dir") + "/TestMoves.log"); WriteFile( file1, "da fust line\nan' da secunt line\n3\nNow is the time for the fourth line\nfinally, the lassed line\nPsych! actually there is another line at the end.\n"); WriteFile( file2, "da first line\nfinally, the last line\nan' da secunt line\n33\nNow is the tine for the forth line\nPsych! actually there is another line at the end.\n"); WriteFile( file3, "first line\nan' da secunt line\n33\nfinally, the last line\nNow is the time for the fourth line\nPsych! actually there is another line at the end.\n"); WriteFile( file4, "da fust line\nan' da secunt line\n3\nNow is the time for the fourth line\nfinally, the lassed line\n"); WriteFile( file5, "da first line\nfinally, the last line\nan' da secunt line\n33\nNow is the tine for the forth line\n"); WriteFile( file6, "From the fixt lull of heaven, she saw\nTime, like a pulse, shake fierce\nThrough all the worlds. Her gaze still strove,\nIn that steep gulph, to pierce\nThe swarm: and then she spake, as when\nThe stars sang in their spheres.\n\n�I wish that he were come to me,\nFor he will come,� she said.\n�Have I not prayed in solemn heaven?\nOn earth, has he not prayed?\nAre not two prayers a perfect strength?\nAnd shall I feel afraid?\n\n�When round his head the aureole clings,\nAnd he is clothed in white,\nI'll take his hand, and go with him\nTo the deep wells of light,\nAnd we will step down as to a stream\nAnd bathe there in God's sight.\n"); WriteFile( file7, "From the fixed place of Heaven she saw\n Time like a pulse shake fierce\nThrough all the worlds. Her gaze still strove\n Within the gulf to pierce\nIts path; and now she spoke as when\n The stars sang in their spheres.\n\nThe sun was gone now; the curled moon\n Was like a little feather\nFluttering far down the gulf; and now\n She spoke through the still weather.\nHer voice was like the voice the stars\n Had when they sang together.\n\n(Ah sweet! Even now, in that bird's song,\n Strove not her accents there,\nFain to be hearkened? When those bells\n Possessed the mid-day air,\nStrove not her steps to reach my side\n Down all the echoing stair?)\n\n�I wish that he were come to me,\n For he will come,� she said.\n�Have I not prayed in Heaven?�on earth,\n Lord, Lord, has he not pray'd?\nAre not two prayers a perfect strength?\n And shall I feel afraid?\n\n�When round his head the aureole clings,\n And he is clothed in white,\nI'll take his hand and go with him\n To the deep wells of light;\nWe will step down as to a stream,\n And bathe there in God's sight\n"); try { documentManager = new DocumentManager(null); DocumentManagerAccess.getInstance().setDocumentManager(documentManager); documentManager.loadManifest(); comparisonSet = new ComparisonSet(documentManager, false); movesManager = documentManager.getMovesManager(); movesManager.addListener(comparisonSet); // LinkedList documentList = documentManager.getUncollatedDocuments(); addDoc(file1); addDoc(file2); } catch (LoggedException e) { e.printStackTrace(); fail(); } }
private MovesManager.FragmentPair createFragmentPair( int baseIndex, int baseOffset, int baseEnd, int witnessIndex, int witnessOffset, int witnessEnd) { JuxtaDocument doc = getDoc(baseIndex); JuxtaDocument doc2 = getDoc(witnessIndex); MovesManager.FragmentPair fp = MovesManager.newFragmentPair(); fp.first.set(doc, baseOffset, baseEnd); fp.second.set(doc2, witnessOffset, witnessEnd); Log("MB: " + insertBrackets(doc.getDocumentText(), baseOffset, baseEnd)); Log("MW: " + insertBrackets(doc2.getDocumentText(), witnessOffset, witnessEnd)); return fp; }
private void assertDoubleMoveEntry( int lhsDoc, int lhsOfs1, int lhsEnd1, int lhsOfs2, int lhsEnd2, int rhsDoc, int rhsOfs1, int rhsEnd1, int rhsOfs2, int rhsEnd2) { MoveList ml = movesManager.getAllMoves(lhsDoc, rhsDoc); assertEquals("Size of move list is wrong", 2, ml.size()); FragmentPair fp = ml.get(0); assertMove(fp, lhsDoc, lhsOfs1, lhsEnd1, rhsDoc, rhsOfs1, rhsEnd1); fp = ml.get(1); assertMove(fp, lhsDoc, lhsOfs2, lhsEnd2, rhsDoc, rhsOfs2, rhsEnd2); }
private void assertMovesManagerDump(String expected) { String dump = movesManager.serialize(); assertEquals("The serialized value of block manager", expected, dump); }
private void assertMoveIsEmpty(int lhs, int rhs) { MoveList ml = movesManager.getAllMoves(lhs, rhs); assertEquals("Size of move list is wrong", 0, ml.size()); }
public void testMovesManager() { // This tests the block manager. We add Moves in various orders and with various errors, and we // see what blocks are // returned. We also remove documents to make sure that the Moves are deleted correctly. try { addDoc(file3); JuxtaDocument doc1 = getDoc(0); JuxtaDocument doc2 = getDoc(1); JuxtaDocument doc3 = getDoc(2); int docId1 = doc1.getID(); int docId2 = doc2.getID(); int docId3 = doc3.getID(); // Make sure that nothing is returned before any manipulation. assertMoveIsEmpty(docId1, docId2); assertMoveIsEmpty(docId1, docId3); assertMoveIsEmpty(docId2, docId1); assertMoveIsEmpty(docId2, docId3); assertMoveIsEmpty(docId3, docId1); assertMoveIsEmpty(docId3, docId2); assertMovesManagerDump("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<moves>\n</moves>\n"); MovesManager.Fragment leftFragment = movesManager.new Fragment(); MovesManager.Fragment rightFragment = movesManager.new Fragment(); // add a move and try all permutations of retrieval leftFragment = movesManager.new Fragment(doc1, 10, 25); rightFragment = movesManager.new Fragment(doc2, 17, 27); movesManager.createMove(leftFragment, rightFragment); assertSingleMoveEntry(docId1, 10, 25, docId2, 17, 27); assertMoveIsEmpty(docId1, docId3); assertSingleMoveEntry(docId2, 17, 27, docId1, 10, 25); assertMoveIsEmpty(docId2, docId3); assertMoveIsEmpty(docId3, docId1); assertMoveIsEmpty(docId3, docId2); assertMovesManagerDump( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<moves>\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file2.txt\" space2=\"original\" start2=\"17\" end2=\"27\" />\n</moves>\n"); // add a move to a different pair and try all permutations of retrieval rightFragment = movesManager.new Fragment(doc3, 33, 43); movesManager.createMove(leftFragment, rightFragment); assertSingleMoveEntry(docId1, 10, 25, docId2, 17, 27); assertSingleMoveEntry(docId1, 10, 25, docId3, 33, 43); assertSingleMoveEntry(docId2, 17, 27, docId1, 10, 25); assertMoveIsEmpty(docId2, docId3); assertSingleMoveEntry(docId3, 33, 43, docId1, 10, 25); assertMoveIsEmpty(docId3, docId2); assertMovesManagerDump( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<moves>\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file2.txt\" space2=\"original\" start2=\"17\" end2=\"27\" />\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file3.txt\" space2=\"original\" start2=\"33\" end2=\"43\" />\n</moves>\n"); // add a second move (in the opposite base/witness order) // Note that the returned moves are sorted by left hand side. leftFragment = movesManager.new Fragment(doc2, 48, 52); rightFragment = movesManager.new Fragment(doc1, 3, 8); movesManager.createMove(leftFragment, rightFragment); assertDoubleMoveEntry(docId1, 3, 8, 10, 25, docId2, 48, 52, 17, 27); assertSingleMoveEntry(docId1, 10, 25, docId3, 33, 43); assertDoubleMoveEntry(docId2, 17, 27, 48, 52, docId1, 10, 25, 3, 8); assertMoveIsEmpty(docId2, docId3); assertSingleMoveEntry(docId3, 33, 43, docId1, 10, 25); assertMoveIsEmpty(docId3, docId2); assertMovesManagerDump( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<moves>\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file2.txt\" space2=\"original\" start2=\"17\" end2=\"27\" />\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file3.txt\" space2=\"original\" start2=\"33\" end2=\"43\" />\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"3\" end1=\"8\" doc2=\"file2.txt\" space2=\"original\" start2=\"48\" end2=\"52\" />\n</moves>\n"); // change a move MoveList ml = movesManager.getAllMoves(docId1, docId2); MovesManager.FragmentPair fp = ml.get(0); leftFragment = movesManager .new Fragment( fp.first.getDocument(), fp.first.getStartOffset(OffsetRange.Space.ACTIVE) - 1, fp.first.getEndOffset(OffsetRange.Space.ACTIVE) - 1); rightFragment = movesManager .new Fragment( fp.second.getDocument(), fp.second.getStartOffset(OffsetRange.Space.ACTIVE) - 1, fp.second.getEndOffset(OffsetRange.Space.ACTIVE) - 1); movesManager.updateBlock(fp, leftFragment, rightFragment); assertDoubleMoveEntry(docId1, 2, 7, 10, 25, docId2, 47, 51, 17, 27); assertSingleMoveEntry(docId1, 10, 25, docId3, 33, 43); assertDoubleMoveEntry(docId2, 17, 27, 47, 51, docId1, 10, 25, 2, 7); assertMoveIsEmpty(docId2, docId3); assertSingleMoveEntry(docId3, 33, 43, docId1, 10, 25); assertMoveIsEmpty(docId3, docId2); assertMovesManagerDump( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<moves>\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file2.txt\" space2=\"original\" start2=\"17\" end2=\"27\" />\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file3.txt\" space2=\"original\" start2=\"33\" end2=\"43\" />\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"2\" end1=\"7\" doc2=\"file2.txt\" space2=\"original\" start2=\"47\" end2=\"51\" />\n</moves>\n"); // delete a move ml = movesManager.getAllMoves(docId1, docId2); movesManager.deleteMove(ml.get(0)); assertSingleMoveEntry(docId1, 10, 25, docId2, 17, 27); assertSingleMoveEntry(docId1, 10, 25, docId3, 33, 43); assertSingleMoveEntry(docId2, 17, 27, docId1, 10, 25); assertMoveIsEmpty(docId2, docId3); assertSingleMoveEntry(docId3, 33, 43, docId1, 10, 25); assertMoveIsEmpty(docId3, docId2); assertMovesManagerDump( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<moves>\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file2.txt\" space2=\"original\" start2=\"17\" end2=\"27\" />\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file3.txt\" space2=\"original\" start2=\"33\" end2=\"43\" />\n</moves>\n"); // remove a document documentManager.removeDocument(getDoc(1)); // this is the second document assertMoveIsEmpty(docId1, docId2); assertSingleMoveEntry(docId1, 10, 25, docId3, 33, 43); assertMoveIsEmpty(docId2, docId1); assertMoveIsEmpty(docId2, docId3); assertSingleMoveEntry(docId3, 33, 43, docId1, 10, 25); assertMoveIsEmpty(docId3, docId2); assertMovesManagerDump( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<moves>\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file3.txt\" space2=\"original\" start2=\"33\" end2=\"43\" />\n</moves>\n"); // put it back in addDoc(file2); docId2 = getDoc(2).getID(); // the previous second document is now in the third place. assertLastGoodCase(docId1, docId2, docId3); // // Error cases // // add an overlapping move boolean failed = false; try { leftFragment = movesManager.new Fragment(doc1, 14, 29); rightFragment = movesManager.new Fragment(doc3, 17, 27); movesManager.createMove(leftFragment, rightFragment); } catch (LoggedException e) { failed = true; } assertEquals("Overlapping move should have thrown an exception", true, failed); assertLastGoodCase(docId1, docId2, docId3); // add a move with a zero length failed = false; try { leftFragment = movesManager.new Fragment(doc1, 14, 14); rightFragment = movesManager.new Fragment(doc3, 17, 27); movesManager.createMove(leftFragment, rightFragment); } catch (LoggedException e) { failed = true; } assertEquals("Zero length move should have thrown an exception", true, failed); assertLastGoodCase(docId1, docId2, docId3); // add a move with a negative length failed = false; try { leftFragment = movesManager.new Fragment(doc1, 14, 29); rightFragment = movesManager.new Fragment(doc3, 17, 12); movesManager.createMove(leftFragment, rightFragment); } catch (LoggedException e) { failed = true; } assertEquals("Negative length move should have thrown an exception", true, failed); assertLastGoodCase(docId1, docId2, docId3); // add a move that is out of bounds failed = false; try { leftFragment = movesManager.new Fragment(doc1, 14, 1229); rightFragment = movesManager.new Fragment(doc3, 17, 27); movesManager.createMove(leftFragment, rightFragment); } catch (LoggedException e) { failed = true; } assertEquals("Out of bounds move should have thrown an exception", true, failed); assertLastGoodCase(docId1, docId2, docId3); // change a move that doesn't exist failed = false; try { leftFragment = movesManager.new Fragment(doc1, 14, 19); rightFragment = movesManager.new Fragment(doc3, 17, 27); fp = movesManager.getAllMoves(docId1, docId3).get(0); fp.first.resetDocument(doc2); movesManager.updateBlock(fp, leftFragment, rightFragment); } catch (LoggedException e) { failed = true; } assertEquals("Non-existent move should have thrown an exception", true, failed); assertLastGoodCase(docId1, docId2, docId3); // delete a move that doesn't exist failed = false; try { movesManager.deleteMove(fp); } catch (LoggedException e) { failed = true; } assertEquals("Non-existent delete should have thrown an exception", true, failed); assertLastGoodCase(docId1, docId2, docId3); // change a move to one that overlaps leftFragment = movesManager.new Fragment(doc1, 30, 35); rightFragment = movesManager.new Fragment(doc3, 22, 26); movesManager.createMove(leftFragment, rightFragment); failed = false; try { fp = movesManager.getAllMoves(docId1, docId3).get(0); leftFragment = movesManager.new Fragment(doc1, 8, 35); movesManager.updateBlock(fp, leftFragment, rightFragment); } catch (LoggedException e) { failed = true; } assertEquals("Overlapped change should have thrown an exception", true, failed); assertMoveIsEmpty(docId1, docId2); assertDoubleMoveEntry(docId1, 10, 25, 30, 35, docId3, 33, 43, 22, 26); assertMoveIsEmpty(docId2, docId1); assertMoveIsEmpty(docId2, docId3); assertDoubleMoveEntry(docId3, 22, 26, 33, 43, docId1, 30, 35, 10, 25); assertMoveIsEmpty(docId3, docId2); assertMovesManagerDump( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<moves>\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"30\" end1=\"35\" doc2=\"file3.txt\" space2=\"original\" start2=\"22\" end2=\"26\" />\n\t<move doc1=\"file1.txt\" space1=\"original\" start1=\"10\" end1=\"25\" doc2=\"file3.txt\" space2=\"original\" start2=\"33\" end2=\"43\" />\n</moves>\n"); } catch (LoggedException e) { fail(); } }