Search in sources :

Example 51 with Card

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

the class ImportMergingTest method testMergeCsvIntoDb.

@SmallTest
@Test
public void testMergeCsvIntoDb() throws Exception {
    srcFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "csv-test.csv";
    destFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "csv-test.db";
    new File(srcFilePath).delete();
    new File(destFilePath).delete();
    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
    try {
        // Create an new db with some contents
        helper.getCardDao().createCards(newDbCardList);
    } finally {
        AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
    // Now convert the csv-test.csv into csv-test.db which will be merged
    // into existing csv-test.db
    amFileUtil.copyFileFromAsset("csv-test.csv", new File(srcFilePath));
    Converter converter = new CSVImporter(amFileUtil);
    converter.convert(srcFilePath, destFilePath);
    // verify the content of csv-test has merged cards
    helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
    try {
        List<Card> cards = helper.getCardDao().getAllCards(null);
        assertEquals(6, cards.size());
        assertEquals(1, (int) cards.get(0).getId());
        assertEquals(1, (int) cards.get(0).getOrdinal());
        assertEquals("old question 1", cards.get(0).getQuestion());
        assertEquals("old answer 1", cards.get(0).getAnswer());
        assertEquals(2, (int) cards.get(1).getId());
        assertEquals(2, (int) cards.get(1).getOrdinal());
        assertEquals("old question 2", cards.get(1).getQuestion());
        assertEquals("old answer 2", cards.get(1).getAnswer());
        assertEquals(3, (int) cards.get(2).getId());
        assertEquals(3, (int) cards.get(2).getOrdinal());
        assertEquals("Question1", cards.get(2).getQuestion());
        assertEquals("Answer1", cards.get(2).getAnswer());
        assertEquals("Category1", cards.get(2).getCategory().getName());
        assertEquals("Note1", cards.get(2).getNote());
        assertEquals(4, (int) cards.get(3).getId());
        assertEquals(4, (int) cards.get(3).getOrdinal());
        assertEquals("Question2", cards.get(3).getQuestion());
        assertEquals("Answer2", cards.get(3).getAnswer());
        assertEquals("Category1", cards.get(3).getCategory().getName());
        assertEquals("Note2", cards.get(3).getNote());
    } finally {
        AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
}
Also used : AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) Converter(org.liberty.android.fantastischmemo.converter.Converter) File(java.io.File) CSVImporter(org.liberty.android.fantastischmemo.converter.CSVImporter) Card(org.liberty.android.fantastischmemo.entity.Card) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) BaseTest(org.liberty.android.fantastischmemo.test.BaseTest) SmallTest(android.support.test.filters.SmallTest)

Example 52 with Card

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

the class ImportMergingTest method setUp.

@Before
public void setUp() throws Exception {
    // Reflect out the test context
    testContext = getContext();
    amFileUtil = new AMFileUtil(testContext, new AMPrefUtil(getContext()));
    newDbCardList = new ArrayList<Card>();
    Card c1 = new Card();
    c1.setQuestion("old question 1");
    c1.setAnswer("old answer 1");
    c1.setLearningData(new LearningData());
    c1.setCategory(new Category());
    Card c2 = new Card();
    c2.setQuestion("old question 2");
    c2.setAnswer("old answer 2");
    c2.setLearningData(new LearningData());
    c2.setCategory(new Category());
    newDbCardList.add(c1);
    newDbCardList.add(c2);
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) AMFileUtil(org.liberty.android.fantastischmemo.utils.AMFileUtil) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) AMPrefUtil(org.liberty.android.fantastischmemo.utils.AMPrefUtil) Card(org.liberty.android.fantastischmemo.entity.Card) Before(org.junit.Before)

Example 53 with Card

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

the class CardDaoTest method testReviewCardsOrderOfOneDifferentEasiness.

@SmallTest
@Test
public void testReviewCardsOrderOfOneDifferentEasiness() 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.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);
    List<Card> cards = cardDao.getCardsForReview(null, null, 50, ReviewOrdering.HardestFirst);
    assertEquals(3, cards.size());
    assertEquals(14, (int) cards.get(0).getOrdinal());
    assertEquals(15, (int) cards.get(1).getOrdinal());
    assertEquals(13, (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 54 with Card

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

the class CardDaoTest method testRemoveDuplicates.

@SmallTest
@Test
public void testRemoveDuplicates() throws Exception {
    CardDao cardDao = helper.getCardDao();
    long originalSize = cardDao.countOf();
    Card nc = new Card();
    nc.setQuestion("whatever");
    nc.setAnswer("and whatever");
    cardDao.create(nc);
    cardDao.create(nc);
    cardDao.create(nc);
    cardDao.create(nc);
    List<Card> cards = cardDao.queryForEq("question", "whatever");
    assertEquals(4, cards.size());
    assertEquals(originalSize + 4, cardDao.countOf());
    cardDao.removeDuplicates();
    assertEquals(originalSize + 1, cardDao.countOf());
    cards = cardDao.queryForEq("question", "whatever");
    assertEquals(1, cards.size());
    Card cc = cardDao.queryLastOrdinal();
    assertEquals(29, (int) cc.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 55 with Card

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

the class CardDaoTest method testGetAllCardWithFilteringCategory.

@SmallTest
@Test
public void testGetAllCardWithFilteringCategory() throws SQLException {
    setupThreeCategories();
    CardDao cardDao = helper.getCardDao();
    CategoryDao categoryDao = helper.getCategoryDao();
    List<Category> cts = categoryDao.queryForEq("name", "My category");
    Category ct = cts.get(0);
    List<Card> cards = cardDao.getAllCards(ct);
    assertEquals(3, (int) cards.size());
}
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)

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