Search in sources :

Example 26 with CardDao

use of org.liberty.android.fantastischmemo.dao.CardDao in project AnyMemo by helloworld1.

the class CardDaoTest method testDeleteCardMaintainOrdinal.

@SmallTest
@Test
public void testDeleteCardMaintainOrdinal() throws Exception {
    CardDao cardDao = helper.getCardDao();
    Card c13 = cardDao.queryForId(13);
    Card c14 = cardDao.queryForId(14);
    Card c15 = cardDao.queryForId(15);
    assertEquals(13, (int) c13.getOrdinal());
    assertEquals(14, (int) c14.getOrdinal());
    assertEquals(15, (int) c15.getOrdinal());
    cardDao.delete(c14);
    c13 = cardDao.queryForId(13);
    c15 = cardDao.queryForId(15);
    assertEquals(13, (int) c13.getOrdinal());
    assertEquals(14, (int) c15.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 27 with CardDao

use of org.liberty.android.fantastischmemo.dao.CardDao in project AnyMemo by helloworld1.

the class CardDaoTest method testQueryPrevCardWithCategory.

@SmallTest
@Test
public void testQueryPrevCardWithCategory() 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 c5 = cardDao.queryForId(5);
    Card c2 = cardDao.queryPrevCard(c5, ct);
    assertEquals(2, (int) c2.getId());
    Card c8 = cardDao.queryPrevCard(c2, ct);
    assertEquals(8, (int) c8.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 28 with CardDao

use of org.liberty.android.fantastischmemo.dao.CardDao in project AnyMemo by helloworld1.

the class CardDaoTest method testGetById.

@SmallTest
@Test
public void testGetById() {
    CardDao cardDao = helper.getCardDao();
    Card card = cardDao.getById(3);
    assertEquals(3, (int) card.getId());
}
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 29 with CardDao

use of org.liberty.android.fantastischmemo.dao.CardDao in project AnyMemo by helloworld1.

the class CardDaoTest method testGetCardsForReviewExclusionList.

@SmallTest
@Test
public void testGetCardsForReviewExclusionList() {
    // Setup cards that is schedule for review
    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.8);
    learningDataDao.update(c13Ld);
    learningDataDao.refresh(c14.getLearningData());
    LearningData c14Ld = c14.getLearningData();
    c14Ld.setAcqReps(1);
    c14Ld.setNextLearnDate(testDate);
    c14Ld.setEasiness((float) 2.6);
    learningDataDao.update(c14Ld);
    learningDataDao.refresh(c15.getLearningData());
    LearningData c15Ld = c15.getLearningData();
    c15Ld.setAcqReps(1);
    c15Ld.setNextLearnDate(testDate);
    c15Ld.setEasiness((float) 2.6);
    learningDataDao.update(c15Ld);
    // Create exclusion list
    List<Card> exclusionList = new ArrayList<Card>();
    exclusionList.add(c13);
    exclusionList.add(c15);
    List<Card> cards = cardDao.getCardsForReview(null, exclusionList, 50, ReviewOrdering.HardestFirst);
    // Only card 14 is there
    assertEquals(1, cards.size());
    assertEquals(14, (int) cards.get(0).getId());
}
Also used : ArrayList(java.util.ArrayList) 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 30 with CardDao

use of org.liberty.android.fantastischmemo.dao.CardDao in project AnyMemo by helloworld1.

the class CardDaoTest method testGetNewCardsWithExclusionList.

@SmallTest
@Test
public void testGetNewCardsWithExclusionList() {
    CardDao cardDao = helper.getCardDao();
    Card c2 = cardDao.queryForId(2);
    Card c5 = cardDao.queryForId(5);
    Card c8 = cardDao.queryForId(8);
    List<Card> exclusionList = new ArrayList<Card>();
    exclusionList.add(c2);
    exclusionList.add(c5);
    exclusionList.add(c8);
    List<Card> cards = cardDao.getNewCards(null, exclusionList, 10);
    assertEquals(10, cards.size());
    for (Card c : cards) {
        if (c.getId() == 2 || c.getId() == 5 || c.getId() == 8) {
            fail("Get excluded cards: " + c.getId());
        }
    }
    List<Card> cards2 = cardDao.getNewCards(null, exclusionList, 50);
    // 3 cards are excluded so only 28 - 3 = 25 cards are there
    assertEquals(25, cards2.size());
}
Also used : ArrayList(java.util.ArrayList) 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)

Aggregations

CardDao (org.liberty.android.fantastischmemo.dao.CardDao)66 Card (org.liberty.android.fantastischmemo.entity.Card)61 SmallTest (android.support.test.filters.SmallTest)37 Test (org.junit.Test)37 AbstractExistingDBTest (org.liberty.android.fantastischmemo.test.AbstractExistingDBTest)37 AnyMemoDBOpenHelper (org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper)28 Category (org.liberty.android.fantastischmemo.entity.Category)27 CategoryDao (org.liberty.android.fantastischmemo.dao.CategoryDao)22 LearningData (org.liberty.android.fantastischmemo.entity.LearningData)15 LearningDataDao (org.liberty.android.fantastischmemo.dao.LearningDataDao)13 File (java.io.File)10 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)6 URL (java.net.URL)5 FileWriter (java.io.FileWriter)4 Date (java.util.Date)4 BufferedWriter (java.io.BufferedWriter)3 PrintWriter (java.io.PrintWriter)3 SAXParser (javax.xml.parsers.SAXParser)3 SAXParserFactory (javax.xml.parsers.SAXParserFactory)3