<commit_before>package dmax.words.persist.dao;

import android.test.AndroidTestCase;
import android.test.RenamingDelegatingContext;

import java.util.Iterator;

import dmax.words.domain.Language;
import dmax.words.domain.Link;
import dmax.words.domain.Word;
import dmax.words.persist.Dao;
import dmax.words.persist.DataBaseManager;

/**
 * Created by <NAME> | <EMAIL>
 * on 16.12.14 at 18:08
 */
public class LinkDaoTest extends AndroidTestCase {

    private DataBaseManager db;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        RenamingDelegatingContext newContext = new RenamingDelegatingContext(getContext(), "test_");
        db = new DataBaseManager(newContext);
        db.open();
    }

    public void test_shouldReturnCorrectDao() {
        Dao<Link> dao = DaoFactory.createDao(Link.class);

        assertEquals(LinkDao.class, dao.getClass());
    }

    public void test_shouldInsert() {
        Word w = new Word();
        w.setLanguage(Language.POLISH);
        w.setData("mówię");

        Word w1 = new Word();
        w1.setLanguage(Language.UKRAINIAN);
        w1.setData("укр");

        Dao<Word> dao = DaoFactory.createDao(Word.class);
        Word saved = db.insert(dao.setPersistable(w));
        Word saved2 = db.insert(dao.setPersistable(w1));

        Link link = new Link();
        link.setWordId(Language.UKRAINIAN, saved.getId());
        link.setWordId(Language.POLISH, saved2.getId());

        Dao<Link> dao1 = DaoFactory.createDao(Link.class);
        Link saved3 = db.insert(dao1.setPersistable(link));

        assertFalse(saved.getId() == -1);
        assertTrue(link.equals(saved3));
    }

    public void test_shouldUpdate() {
        Word w = new Word();
        w.setLanguage(Language.POLISH);
        w.setData("mówię");

        Word w1 = new Word();
        w1.setLanguage(Language.POLISH);
        w1.setData("pracować");

        Word w2 = new Word();
        w2.setLanguage(Language.UKRAINIAN);
        w2.setData("укр");

        Word w3 = new Word();
        w3.setLanguage(Language.UKRAINIAN);
        w3.setData("снiг");

        Dao<Word> dao = DaoFactory.createDao(Word.class);
        Word saved = db.insert(dao.setPersistable(w));
        Word saved2 = db.insert(dao.setPersistable(w2));

        Link link = new Link();
        link.setWordId(Language.UKRAINIAN, saved.getId());
        link.setWordId(Language.POLISH, saved2.getId());

        Dao<Link> dao1 = DaoFactory.createDao(Link.class);
        Link saved3 = db.insert(dao1.setPersistable(link));


        saved3.setWord(w1);
        saved3.setWord(w3);

        Link updated = db.update(dao1.setPersistable(saved3));

        Link retrieved = db.retrieve(dao1.setRetrieveId(saved3.getId()));

        assertNotNull(retrieved);
        assertTrue(retrieved.getId() == updated.getId());
        assertTrue(retrieved.equals(updated));
    }

    public void test_shouldRetrieve() {
        Word w = new Word();
        w.setLanguage(Language.POLISH);
        w.setData("mówię");

        Word w1 = new Word();
        w1.setLanguage(Language.UKRAINIAN);
        w1.setData("укр");

        Dao<Word> dao = DaoFactory.createDao(Word.class);
        Word saved = db.insert(dao.setPersistable(w));
        Word saved2 = db.insert(dao.setPersistable(w1));

        Link link = new Link();
        link.setWordId(Language.UKRAINIAN, saved.getId());
        link.setWordId(Language.POLISH, saved2.getId());

        Dao<Link> dao1 = DaoFactory.createDao(Link.class);
        Link saved3 = db.insert(dao1.setPersistable(link));
        long id = saved3.getId();

        Link retrieved = db.retrieve(dao1.setRetrieveId(id));

        assertNotNull(retrieved);
        assertTrue(retrieved.getId() == saved.getId());
        assertTrue(retrieved.equals(saved3));
    }

    public void test_shouldDelete() {
        Word w = new Word();
        w.setLanguage(Language.POLISH);
        w.setData("mówię");

        Word w1 = new Word();
        w1.setLanguage(Language.UKRAINIAN);
        w1.setData("укр");

        Dao<Word> dao = DaoFactory.createDao(Word.class);
        Word saved = db.insert(dao.setPersistable(w));
        Word saved2 = db.insert(dao.setPersistable(w1));

        Link link = new Link();
        link.setWordId(Language.UKRAINIAN, saved.getId());
        link.setWordId(Language.POLISH, saved2.getId());<commit_msg>Modify link dao test to priority and updated fields<commit_after>package dmax.words.persist.dao;

import android.test.AndroidTestCase;
import android.test.RenamingDelegatingContext;

import java.util.Iterator;

import dmax.words.domain.Language;
import dmax.words.domain.Link;
import dmax.words.domain.Word;
import dmax.words.persist.Dao;
import dmax.words.persist.DataBaseManager;

/**
 * Created by <NAME> | <EMAIL>
 * on 16.12.14 at 18:08
 */
public class LinkDaoTest extends AndroidTestCase {

    private DataBaseManager db;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        RenamingDelegatingContext newContext = new RenamingDelegatingContext(getContext(), "test_");
        db = new DataBaseManager(newContext);
        db.open();
    }

    public void test_shouldReturnCorrectDao() {
        Dao<Link> dao = DaoFactory.createDao(Link.class);

        assertEquals(LinkDao.class, dao.getClass());
    }

    public void test_shouldInsert() {
        Word w = new Word();
        w.setLanguage(Language.POLISH);
        w.setData("mówię");

        Word w1 = new Word();
        w1.setLanguage(Language.UKRAINIAN);
        w1.setData("укр");

        Dao<Word> dao = DaoFactory.createDao(Word.class);
        Word saved = db.insert(dao.setPersistable(w));
        Word saved2 = db.insert(dao.setPersistable(w1));

        Link link = new Link();
        link.setWordId(Language.UKRAINIAN, saved.getId());
        link.setWordId(Language.POLISH, saved2.getId());
        link.setPriority(1);
        link.setUpdated(24);

        Dao<Link> dao1 = DaoFactory.createDao(Link.class);
        Link saved3 = db.insert(dao1.setPersistable(link));

        assertFalse(saved.getId() == -1);
        assertTrue(link.equals(saved3));
    }

    public void test_shouldUpdate() {
        Word w = new Word();
        w.setLanguage(Language.POLISH);
        w.setData("mówię");

        Word w1 = new Word();
        w1.setLanguage(Language.POLISH);
        w1.setData("pracować");

        Word w2 = new Word();
        w2.setLanguage(Language.UKRAINIAN);
        w2.setData("укр");

        Word w3 = new Word();
        w3.setLanguage(Language.UKRAINIAN);
        w3.setData("снiг");

        Dao<Word> dao = DaoFactory.createDao(Word.class);
        Word saved = db.insert(dao.setPersistable(w));
        Word saved2 = db.insert(dao.setPersistable(w2));

        Link link = new Link();
        link.setWordId(Language.UKRAINIAN, saved.getId());
        link.setWordId(Language.POLISH, saved2.getId());
        link.setPriority(2);
        link.setUpdated(12);

        Dao<Link> dao1 = DaoFactory.createDao(Link.class);
        Link saved3 = db.insert(dao1.setPersistable(link));


        saved3.setWord(w1);
        saved3.setWord(w3);
        saved3.setPriority(4);

        Link updated = db.update(dao1.setPersistable(saved3));

        Link retrieved = db.retrieve(dao1.setRetrieveId(saved3.getId()));

        assertNotNull(retrieved);
        assertTrue(retrieved.getId() == updated.getId());
        assertTrue(retrieved.equals(updated));
    }

    public void test_shouldRetrieve() {
        Word w = new Word();
        w.setLanguage(Language.POLISH);
        w.setData("mówię");

        Word w1 = new Word();
        w1.setLanguage(Language.UKRAINIAN);
        w1.setData("укр");

        Dao<Word> dao = DaoFactory.createDao(Word.class);
        Word saved = db.insert(dao.setPersistable(w));
        Word saved2 = db.insert(dao.setPersistable(w1));

        Link link = new Link();
        link.setWordId(Language.UKRAINIAN, saved.getId());
        link.setWordId(Language.POLISH, saved2.getId());
        link.setPriority(2);
        link.setUpdated(45);

        Dao<Link> dao1 = DaoFactory.createDao(Link.class);
        Link saved3 = db.insert(dao1.setPersistable(link));
        long id = saved3.getId();

        Link retrieved = db.retrieve(dao1.setRetrieveId(id));

        saved3.setId(-1);

        assertNotNull(retrieved);
        assertTrue(retrieved.getId() == id);
        assertTrue(retrieved.equals(saved3));
    }

    public void test_shouldDelete() {
        Word w = new Word();
        w.setLanguage(Language.POLISH);
        w.setData("mówię");

        Word w1 = new Word();
        w1.setLanguage(Language.UKRAINIAN);
        w1.setData("укр");

        Dao<Word> dao = DaoFactory.createDao(Word.class);
        Word saved = db.insert(dao.setPersistable(w));
        Word saved2 = db.insert(dao.setPersistable(w1));

        Link link = new Link();
        link.setWordId(Language.UKRAINIAN, saved.getId());
        link.setWordId(Language.POLISH, saved2.getId());
{'fraction_non_alphanumeric': 0.1341153037512449, 'fraction_numerical': 0.015159898196304084, 'mean_word_length': 2.704098360655738, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6718699', 'n_tokens_mistral': 2993, 'n_tokens_neox': 2965, 'n_words': 497}