Search in sources :

Example 56 with Card

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

the class CardDaoTest method testReviewCardsOrderOfAllDifferentEasiness.

@SmallTest
@Test
public void testReviewCardsOrderOfAllDifferentEasiness() throws SQLException {
    CardDao cardDao = helper.getCardDao();
    CategoryDao categoryDao = helper.getCategoryDao();
    setupThreeCategories();
    Card c2 = cardDao.queryForId(2);
    Card c5 = cardDao.queryForId(5);
    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.6);
    learningDataDao.update(c14Ld);
    learningDataDao.refresh(c15.getLearningData());
    LearningData c15Ld = c15.getLearningData();
    c15Ld.setAcqReps(1);
    c15Ld.setNextLearnDate(testDate);
    c15Ld.setEasiness((float) 2.8);
    learningDataDao.update(c15Ld);
    learningDataDao.refresh(c2.getLearningData());
    LearningData c2Ld = c2.getLearningData();
    c2Ld.setAcqReps(1);
    c2Ld.setNextLearnDate(testDate);
    c2Ld.setEasiness((float) 3.0);
    learningDataDao.update(c2Ld);
    learningDataDao.refresh(c5.getLearningData());
    LearningData c5Ld = c5.getLearningData();
    c5Ld.setAcqReps(1);
    c5Ld.setNextLearnDate(testDate);
    c5Ld.setEasiness((float) 2.9);
    learningDataDao.update(c5Ld);
    List<Category> cts = categoryDao.queryForEq("name", "My category");
    Category ct = cts.get(0);
    List<Card> cards = cardDao.getCardsForReview(ct, null, 50, ReviewOrdering.HardestFirst);
    assertEquals(2, cards.size());
    assertEquals(5, (int) cards.get(0).getOrdinal());
    assertEquals(2, (int) cards.get(1).getOrdinal());
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) 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 57 with Card

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

the class CardDaoTest method testCreateCard.

@SmallTest
@Test
public void testCreateCard() throws Exception {
    CardDao cardDao = helper.getCardDao();
    Card c = new Card();
    c.setCategory(new Category());
    c.setLearningData(new LearningData());
    cardDao.createCard(c);
    // Should create a new card
    assertEquals(29, cardDao.countOf());
    // The new card's id and ordinal should be correct
    assertEquals(29, (int) c.getId());
    assertEquals(29, (int) c.getOrdinal());
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) 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 58 with Card

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

the class CardDaoTest method testGetAllCardWithoutFilteringCategory.

@SmallTest
@Test
public void testGetAllCardWithoutFilteringCategory() throws SQLException {
    setupThreeCategories();
    CardDao cardDao = helper.getCardDao();
    List<Card> cards = cardDao.getAllCards(null);
    assertEquals(28, (int) cards.size());
}
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 59 with Card

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

the class CategoryTest method testRemoveCategories.

@SmallTest
@Test
public void testRemoveCategories() throws Exception {
    CardDao cardDao = helper.getCardDao();
    CategoryDao categoryDao = helper.getCategoryDao();
    Category c1 = categoryDao.createOrReturn("c1");
    categoryDao.create(c1);
    Card nc = new Card();
    nc.setCategory(c1);
    cardDao.create(nc);
    categoryDao.refresh(nc.getCategory());
    assertEquals("c1", nc.getCategory().getName());
    categoryDao.removeCategory(c1);
    nc = cardDao.queryForId(nc.getId());
    categoryDao.refresh(nc.getCategory());
    assertEquals("", nc.getCategory().getName());
}
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) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest)

Example 60 with Card

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

the class NewDbTest method testCreateFirstCardWithCorrectOrdinal.

@SmallTest
@Test
public void testCreateFirstCardWithCorrectOrdinal() throws Exception {
    CardDao cardDao = newDbHelper.getCardDao();
    // Create card has null ordinal, append to the end
    Card nc = new Card();
    assertNull(nc.getOrdinal());
    cardDao.create(nc);
    assertEquals(1, (int) nc.getOrdinal());
}
Also used : CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest)

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