<commit_before>/**
 * Copyright (c) 2010, Distributed Systems Group, University of Konstanz
 * 
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * 
 */
package com.treetank.diff;

import static org.junit.Assert.*;

import java.util.HashSet;
import java.util.Set;

import com.treetank.TestHelper;
import com.treetank.api.IDatabase;
import com.treetank.exception.TTException;
import com.treetank.utils.DocumentCreater;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * @author <NAME>, University of Konstanz
 * 
 */
public class StructuralDiffTest implements IDiffObserver {
    private transient IDatabase mDatabase;

    private transient EDiff mDiff;
    
    private transient int mCounter;

    @Before
    public final void setUp() throws TTException {
        TestHelper.deleteEverything();
        mDatabase = TestHelper.getDatabase(TestHelper.PATHS.PATH1.getFile());
        DocumentCreater.createVersioned(mDatabase.getSession().beginWriteTransaction());
        mDiff = EDiff.SAME;
    }

    @After
    public final void tearDown() {
        TestHelper.closeEverything();
    }

    @Test
    public final void testStructuralDiff() {
        final Set<IDiffObserver> observer = new HashSet<IDiffObserver>();
        observer.add(this);
        DiffFactory.invokeStructuralDiff(mDatabase, 0, 1, 0, EDiffKind.NORMAL, observer);
        
        while (mDiff != EDiff.DONE) {
            switch (mCounter) {
            case 1:
                assertEquals(mDiff, EDiff.INSERTED);
                break;
            case 2:
                assertEquals(mDiff, EDiff.INSERTED);
                break;     
            default:
                assertEquals(mDiff, EDiff.SAME);
                break;
            }
        }
    }

    @Override
    public final void diffListener(final EDiff paramDiff) {
        mDiff = paramDiff;
        mCounter++;
    }
}<commit_msg>ASSIGNED - task 1002: Diff package in Treetank  https://projects.uni-konstanz.de/issues/show/1002<commit_after>/**
 * Copyright (c) 2010, Distributed Systems Group, University of Konstanz
 * 
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * 
 */
package com.treetank.diff;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import javax.xml.stream.XMLStreamException;

import com.treetank.TestHelper;
import com.treetank.api.IDatabase;
import com.treetank.api.IWriteTransaction;
import com.treetank.exception.TTException;
import com.treetank.service.xml.shredder.EShredderCommit;
import com.treetank.service.xml.shredder.EShredderInsert;
import com.treetank.service.xml.shredder.XMLShredder;
import com.treetank.service.xml.shredder.XMLUpdateShredder;
import com.treetank.utils.DocumentCreater;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * @author <NAME>, University of Konstanz
 * 
 */
public final class StructuralDiffTest implements IDiffObserver {
    private transient IDatabase mDatabase;

    private transient EDiff mDiff;

    private transient int mCounter;

    private static final String RESOURCES = "src" + File.separator + "test" + File.separator + "resources";

    @Before
    public void setUp() throws TTException {
        TestHelper.deleteEverything();
        mDatabase = TestHelper.getDatabase(TestHelper.PATHS.PATH1.getFile());
        DocumentCreater.createVersioned(mDatabase.getSession().beginWriteTransaction());
        mDiff = EDiff.SAME;
    }

    @After
    public void tearDown() {
        TestHelper.closeEverything();
    }

    @Test
    public void testStructuralDiffFirst() {
        final Set<IDiffObserver> observer = new HashSet<IDiffObserver>();
        observer.add(this);
        DiffFactory.invokeStructuralDiff(mDatabase, 0, 1, 0, EDiffKind.NORMAL, observer);

        while (mDiff != EDiff.DONE) {
            switch (mCounter) {
            case 1:
                assertEquals(mDiff, EDiff.INSERTED);
                break;
            case 2:
                assertEquals(mDiff, EDiff.INSERTED);
                break;
            default:
                assertEquals(mDiff, EDiff.SAME);
                break;
            }
        }
    }

    @Test
    public void testStructuralDiffSecond() throws TTException, IOException, XMLStreamException {
        TestHelper.closeEverything();
        TestHelper.deleteEverything();
        final IDatabase database = TestHelper.getDatabase(TestHelper.PATHS.PATH1.getFile());
        final IWriteTransaction wtx = database.getSession().beginWriteTransaction();
        final XMLShredder init =
            new XMLShredder(wtx, XMLShredder.createReader(new File(RESOURCES + File.separator + "revXMLsAll4"
                + File.separator + "1.xml")), EShredderInsert.ADDASFIRSTCHILD);
        init.call();
        final File file = new File(RESOURCES + File.separator + "revXMLsAll4" + File.separator + "2.xml");
        final XMLShredder shredder =
            new XMLUpdateShredder(wtx, XMLShredder.createReader(file), EShredderInsert.ADDASFIRSTCHILD, file,
                EShredderCommit.COMMIT);
        shredder.call();
        
        final Set<IDiffObserver> observer = new HashSet<IDiffObserver>();
        observer.add(this);
        DiffFactory.invokeStructuralDiff(database, 0, 1, 0, EDiffKind.NORMAL, observer);

        while (mDiff != EDiff.DONE) {
            switch (mCounter) {
            case 1:
                assertEquals(mDiff, EDiff.SAME);
                break;
            case 2:
                assertEquals(mDiff, EDiff.SAME);
                break;
            case 3:
                assertEquals(mDiff, EDiff.INSERTED);
                break;
            case 4:
                assertEquals(mDiff, EDiff.DELETED);
                break;
            default:
                assertEquals(mDiff, EDiff.SAME);
                break;
            }
        }
    }

    @Override
    public void diffListener(final EDiff paramDiff) {
        mDiff = paramDiff;
        mCounter++;
    }
}
{'fraction_non_alphanumeric': 0.08554054054054054, 'fraction_numerical': 0.005405405405405406, 'mean_word_length': 2.683922349427576, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2500041', 'n_tokens_mistral': 2154, 'n_tokens_neox': 1995, 'n_words': 583}