Search in sources :

Example 81 with Card

use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.

the class TabTxtImporterTest method verify.

@Override
protected void verify(String destFilePath) throws Exception {
    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
    try {
        CardDao cardDao = helper.getCardDao();
        CategoryDao categoryDao = helper.getCategoryDao();
        List<Card> cards = cardDao.queryForAll();
        List<Category> categories = categoryDao.queryForAll();
        for (Card c : cards) {
            categoryDao.refresh(c.getCategory());
        }
        assertEquals(4, cards.size());
        assertEquals(3, categories.size());
        assertEquals("Question1", cards.get(0).getQuestion());
        assertEquals("Answer1", cards.get(0).getAnswer());
        assertEquals("Category1", cards.get(0).getCategory().getName());
        assertEquals("Question2", cards.get(1).getQuestion());
        assertEquals("Answer2", cards.get(1).getAnswer());
        assertEquals("Category1", cards.get(1).getCategory().getName());
        assertEquals("Question3", cards.get(2).getQuestion());
        assertEquals("Answer3", cards.get(2).getAnswer());
        assertEquals("Category2", cards.get(2).getCategory().getName());
        assertEquals("Question4", cards.get(3).getQuestion());
        assertEquals("Answer4", cards.get(3).getAnswer());
        assertEquals("", cards.get(3).getCategory().getName());
    } finally {
        helper.close();
    }
}
Also used : AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 82 with Card

use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.

the class CardDaoTest method testQueryPrevCardWithoutCategory.

@SmallTest
@Test
public void testQueryPrevCardWithoutCategory() throws Exception {
    setupThreeCategories();
    CardDao cardDao = helper.getCardDao();
    Card c2 = cardDao.queryForId(2);
    Card c1 = cardDao.queryPrevCard(c2, null);
    assertEquals(1, (int) c1.getOrdinal());
    Card c28 = cardDao.queryPrevCard(c1, null);
    assertEquals(28, (int) c28.getOrdinal());
}
Also used : CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) SmallTest(android.support.test.filters.SmallTest)

Example 83 with Card

use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.

the class CardDaoTest method testReviewCardsOrderOfSameEasiness.

@SmallTest
@Test
public void testReviewCardsOrderOfSameEasiness() throws SQLException {
    CardDao cardDao = helper.getCardDao();
    Card c13 = cardDao.queryForId(13);
    Card c14 = cardDao.queryForId(14);
    Card c15 = cardDao.queryForId(15);
    LearningDataDao learningDataDao = helper.getLearningDataDao();
    Date testDate = new Date((new Date().getTime() - 1));
    learningDataDao.refresh(c13.getLearningData());
    LearningData c13Ld = c13.getLearningData();
    c13Ld.setAcqReps(1);
    c13Ld.setNextLearnDate(testDate);
    c13Ld.setEasiness((float) 2.7);
    learningDataDao.update(c13Ld);
    learningDataDao.refresh(c14.getLearningData());
    LearningData c14Ld = c14.getLearningData();
    c14Ld.setAcqReps(1);
    c14Ld.setNextLearnDate(testDate);
    c14Ld.setEasiness((float) 2.7);
    learningDataDao.update(c14Ld);
    learningDataDao.refresh(c15.getLearningData());
    LearningData c15Ld = c15.getLearningData();
    c15Ld.setAcqReps(1);
    c15Ld.setNextLearnDate(testDate);
    c15Ld.setEasiness((float) 2.7);
    learningDataDao.update(c15Ld);
    List<Card> cards = cardDao.getCardsForReview(null, null, 50, ReviewOrdering.HardestFirst);
    assertEquals(3, cards.size());
    assertEquals(13, (int) cards.get(0).getOrdinal());
    assertEquals(14, (int) cards.get(1).getOrdinal());
    assertEquals(15, (int) cards.get(2).getOrdinal());
}
Also used : LearningDataDao(org.liberty.android.fantastischmemo.dao.LearningDataDao) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Date(java.util.Date) Card(org.liberty.android.fantastischmemo.entity.Card) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) SmallTest(android.support.test.filters.SmallTest)

Example 84 with Card

use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.

the class CardDaoTest method testSearchLastOrdinalWithcategoryIfExists.

@SmallTest
@Test
public void testSearchLastOrdinalWithcategoryIfExists() throws Exception {
    setupThreeCategories();
    CardDao cardDao = helper.getCardDao();
    CategoryDao categoryDao = helper.getCategoryDao();
    List<Category> cts = categoryDao.queryForEq("name", "My category");
    Category ct = cts.get(0);
    Card c = cardDao.queryLastOrdinal(ct);
    assertEquals(8, (int) c.getId());
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) SmallTest(android.support.test.filters.SmallTest)

Example 85 with Card

use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.

the class PreviewEditActivity method gotoPrev.

protected void gotoPrev() {
    if (getCurrentCard() != null) {
        Card prevCard = getDbOpenHelper().getCardDao().queryPrevCard(getCurrentCard(), currentCategory);
        assert prevCard != null : "Prev card is null";
        gotoCard(prevCard);
        updateTitle();
    }
}
Also used : Card(org.liberty.android.fantastischmemo.entity.Card)

Aggregations

Card (org.liberty.android.fantastischmemo.entity.Card)95 CardDao (org.liberty.android.fantastischmemo.dao.CardDao)61 SmallTest (android.support.test.filters.SmallTest)43 Test (org.junit.Test)43 AbstractExistingDBTest (org.liberty.android.fantastischmemo.test.AbstractExistingDBTest)41 Category (org.liberty.android.fantastischmemo.entity.Category)30 AnyMemoDBOpenHelper (org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper)28 LearningData (org.liberty.android.fantastischmemo.entity.LearningData)25 CategoryDao (org.liberty.android.fantastischmemo.dao.CategoryDao)20 LearningDataDao (org.liberty.android.fantastischmemo.dao.LearningDataDao)13 File (java.io.File)12 ArrayList (java.util.ArrayList)11 SQLException (java.sql.SQLException)9 QueueManager (org.liberty.android.fantastischmemo.queue.QueueManager)9 IOException (java.io.IOException)6 Date (java.util.Date)6 LearnQueueManager (org.liberty.android.fantastischmemo.queue.LearnQueueManager)6 URL (java.net.URL)5 FileWriter (java.io.FileWriter)4 Scheduler (org.liberty.android.fantastischmemo.scheduler.Scheduler)4