Search in sources :

Example 81 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedV2Test method test_reviewsV2.

@Test
public void test_reviewsV2() throws Exception {
    Collection col = getColV2();
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    // set the card up as a review card, due 8 days ago
    Card c = note.cards().get(0);
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setDue(col.getSched().getToday() - 8);
    c.setFactor(STARTING_FACTOR);
    c.setReps(3);
    c.setLapses(1);
    c.setIvl(100);
    c.startTimer();
    c.flush();
    // save it for later use as well
    Card cardcopy = c.clone();
    // try with an ease of 2
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c = cardcopy.clone();
    c.flush();
    col.reset();
    col.getSched().answerCard(c, BUTTON_TWO);
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    // the new interval should be (100) * 1.2 = 120
    assertTrue(checkRevIvl(col, c, 120));
    assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
    // factor should have been decremented
    assertEquals(2350, c.getFactor());
    // check counters
    assertEquals(1, c.getLapses());
    assertEquals(4, c.getReps());
    // ease 3
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c = cardcopy.clone();
    c.flush();
    col.getSched().answerCard(c, BUTTON_THREE);
    // the new interval should be (100 + 8/2) * 2.5 = 260
    assertTrue(checkRevIvl(col, c, 260));
    assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
    // factor should have been left alone
    assertEquals(STARTING_FACTOR, c.getFactor());
    // ease 4
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c = cardcopy.clone();
    c.flush();
    col.getSched().answerCard(c, BUTTON_FOUR);
    // the new interval should be (100 + 8) * 2.5 * 1.3 = 351
    assertTrue(checkRevIvl(col, c, 351));
    assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
    // factor should have been increased
    assertEquals(2650, c.getFactor());
    // leech handling
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    DeckConfig conf = col.getDecks().getConf(1);
    conf.getJSONObject("lapse").put("leechAction", LEECH_SUSPEND);
    col.getDecks().save(conf);
    c = cardcopy.clone();
    c.setLapses(7);
    c.flush();
/* todo hook
        // steup hook
        hooked = new [] {};

        def onLeech(card):
        hooked.append(1);

        hooks.card_did_leech.append(onLeech);
        col.getSched().answerCard(c, BUTTON_ONE);
        assertTrue(hooked);
        assertEquals(QUEUE_TYPE_SUSPENDED, c.getQueue());
        c.load();
        assertEquals(QUEUE_TYPE_SUSPENDED, c.getQueue());
        */
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 82 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedV2Test method test_finishedV2.

@Test
public void test_finishedV2() throws Exception {
    Collection col = getColV2();
    // nothing due
    assertThat(col.getSched().finishedMsg(getTargetContext()).toString(), containsString("Congratulations"));
    assertThat(col.getSched().finishedMsg(getTargetContext()).toString(), not(containsString("limit")));
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    // have a new card
    assertThat(col.getSched().finishedMsg(getTargetContext()).toString(), containsString("new cards available"));
    // turn it into a review
    col.reset();
    Card c = note.cards().get(0);
    c.startTimer();
    col.getSched().answerCard(c, BUTTON_THREE);
    // nothing should be due tomorrow, as it's due in a week
    assertThat(col.getSched().finishedMsg(getTargetContext()).toString(), containsString("Congratulations"));
    assertThat(col.getSched().finishedMsg(getTargetContext()).toString(), not(containsString("limit")));
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 83 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedV2Test method test_filt_reviewing_early_normal.

@Test
public void test_filt_reviewing_early_normal() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    c.setIvl(100);
    c.setQueue(QUEUE_TYPE_REV);
    c.setType(CARD_TYPE_REV);
    // due in 25 days, so it's been waiting 75 days
    c.setDue(col.getSched().getToday() + 25);
    c.setMod(1);
    c.setFactor(STARTING_FACTOR);
    c.startTimer();
    c.flush();
    col.reset();
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    // create a dynamic deck and refresh it
    long did = addDynamicDeck("Cram");
    col.getSched().rebuildDyn(did);
    col.reset();
    // should appear as normal in the deck list
    /* todo sort
           assertEquals(1, sorted(col.getSched().deckDueTree().getChildren())[0].review_count);
        */
    // and should appear in the counts
    assertEquals(new Counts(0, 0, 1), col.getSched().counts());
    // grab it and check estimates
    c = getCard();
    assertEquals(4, col.getSched().answerButtons(c));
    assertEquals(600, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(Math.round(75 * 1.2) * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_TWO));
    assertThat(col.getSched().nextIvl(c, BUTTON_THREE), is((long) (75 * 2.5) * SECONDS_PER_DAY));
    assertThat(col.getSched().nextIvl(c, BUTTON_FOUR), is((long) (75 * 2.5 * 1.15) * SECONDS_PER_DAY));
    // answer 'good'
    col.getSched().answerCard(c, BUTTON_THREE);
    checkRevIvl(col, c, 90);
    assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
    assertEquals(0L, c.getODue());
    // should not be in learning
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    // should be logged as a cram rep
    assertEquals(3, col.getDb().queryLongScalar("select type from revlog order by id desc limit 1"));
    // due in 75 days, so it's been waiting 25 days
    c.setIvl(100);
    c.setDue(col.getSched().getToday() + 75);
    c.flush();
    col.getSched().rebuildDyn(did);
    col.reset();
    c = getCard();
    assertEquals(60 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_TWO));
    assertEquals(100 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_THREE));
    assertEquals(114 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_FOUR));
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 84 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedTest method test_cram_resched.

@Test
public void test_cram_resched() throws Exception {
    // add card
    Collection col = getColV1();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    // cram deck
    long did = addDynamicDeck("Cram");
    Deck cram = col.getDecks().get(did);
    cram.put("resched", false);
    col.getDecks().save(cram);
    col.getSched().rebuildDyn(did);
    col.reset();
    // graduate should return it to new
    Card c = getCard();
    assertEquals(60, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(600, col.getSched().nextIvl(c, BUTTON_TWO));
    assertEquals(0, col.getSched().nextIvl(c, BUTTON_THREE));
    assertEquals("(end)", col.getSched().nextIvlStr(getTargetContext(), c, BUTTON_THREE));
    col.getSched().answerCard(c, BUTTON_THREE);
    assertEquals(CARD_TYPE_NEW, c.getType());
    assertEquals(QUEUE_TYPE_NEW, c.getQueue());
    // undue reviews should also be unaffected
    c.setIvl(100);
    c.setQueue(QUEUE_TYPE_REV);
    c.setType(CARD_TYPE_REV);
    c.setDue(col.getSched().getToday() + 25);
    c.setFactor(STARTING_FACTOR);
    c.flush();
    Card cardcopy = c.clone();
    col.getSched().rebuildDyn(did);
    col.reset();
    c = getCard();
    assertEquals(600, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(0, col.getSched().nextIvl(c, BUTTON_TWO));
    assertEquals(0, col.getSched().nextIvl(c, BUTTON_THREE));
    col.getSched().answerCard(c, BUTTON_TWO);
    assertEquals(100, c.getIvl());
    assertEquals(col.getSched().getToday() + 25, c.getDue());
    // check failure too
    c = cardcopy;
    c.flush();
    col.getSched().rebuildDyn(did);
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    col.getSched().emptyDyn(did);
    c.load();
    assertEquals(100, c.getIvl());
    assertEquals(col.getSched().getToday() + 25, c.getDue());
    // fail+grad early
    c = cardcopy;
    c.flush();
    col.getSched().rebuildDyn(did);
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    col.getSched().answerCard(c, BUTTON_THREE);
    col.getSched().emptyDyn(did);
    c.load();
    assertEquals(100, c.getIvl());
    assertEquals(col.getSched().getToday() + 25, c.getDue());
    // due cards - pass
    c = cardcopy;
    c.setDue(-25);
    c.flush();
    col.getSched().rebuildDyn(did);
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_THREE);
    col.getSched().emptyDyn(did);
    c.load();
    assertEquals(100, c.getIvl());
    assertEquals(-25, c.getDue());
    // fail
    c = cardcopy;
    c.setDue(-25);
    c.flush();
    col.getSched().rebuildDyn(did);
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    col.getSched().emptyDyn(did);
    c.load();
    assertEquals(100, c.getIvl());
    assertEquals(-25, c.getDue());
    // fail with normal grad
    c = cardcopy;
    c.setDue(-25);
    c.flush();
    col.getSched().rebuildDyn(did);
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    col.getSched().answerCard(c, BUTTON_THREE);
    c.load();
    assertEquals(100, c.getIvl());
    assertEquals(-25, c.getDue());
// lapsed card pulled into cram
// col.getSched()._cardConf(c)['lapse']['mult']=0.5
// col.getSched().answerCard(c, 1)
// col.getSched().rebuildDyn(did)
// col.reset()
// c = getCard()
// col.getSched().answerCard(c, 2)
// print c.__dict__
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 85 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedTest method test_cram.

@Test
public void test_cram() throws Exception {
    Collection col = getColV1();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    c.setIvl(100);
    c.setQueue(QUEUE_TYPE_REV);
    c.setType(CARD_TYPE_REV);
    // due in 25 days, so it's been waiting 75 days
    c.setDue(col.getSched().getToday() + 25);
    c.setMod(1);
    c.setFactor(STARTING_FACTOR);
    c.startTimer();
    c.flush();
    col.reset();
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    Card cardcopy = c.clone();
    // create a dynamic deck and refresh it
    long did = addDynamicDeck("Cram");
    col.getSched().rebuildDyn(did);
    col.reset();
    // should appear as new in the deck list
    // todo: which sort
    // and should appear in the counts
    assertEquals(new Counts(1, 0, 0), col.getSched().counts());
    // grab it and check estimates
    c = getCard();
    assertEquals(2, col.getSched().answerButtons(c));
    assertEquals(600, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, BUTTON_TWO));
    Deck cram = col.getDecks().get(did);
    cram.put("delays", new JSONArray(new double[] { 1, 10 }));
    col.getDecks().save(cram);
    assertEquals(3, col.getSched().answerButtons(c));
    assertEquals(60, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(600, col.getSched().nextIvl(c, BUTTON_TWO));
    assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, BUTTON_THREE));
    col.getSched().answerCard(c, BUTTON_TWO);
    // elapsed time was 75 days
    // factor = 2.5+1.2/2 = 1.85
    // int(75*1.85) = 138
    assertEquals(138, c.getIvl());
    assertEquals(138, c.getODue());
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    // should be logged as a cram rep
    assertEquals(3, col.getDb().queryLongScalar("select type from revlog order by id desc limit 1"));
    // check ivls again
    assertEquals(60, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, BUTTON_TWO));
    assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, BUTTON_THREE));
    // when it graduates, due is updated
    c = getCard();
    col.getSched().answerCard(c, BUTTON_TWO);
    assertEquals(138, c.getIvl());
    assertEquals(138, c.getDue());
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    // and it will have moved back to the previous deck
    assertEquals(1, c.getDid());
    // cram the deck again
    col.getSched().rebuildDyn(did);
    col.reset();
    c = getCard();
    // check ivls again - passing should be idempotent
    assertEquals(60, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(600, col.getSched().nextIvl(c, BUTTON_TWO));
    assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, BUTTON_THREE));
    col.getSched().answerCard(c, BUTTON_TWO);
    assertEquals(138, c.getIvl());
    assertEquals(138, c.getODue());
    // fail
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(60, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(600, col.getSched().nextIvl(c, BUTTON_TWO));
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_THREE));
    // delete the deck, returning the card mid-study
    col.getDecks().rem(col.getDecks().selected());
    assertEquals(1, col.getSched().deckDueTree().size());
    c.load();
    assertEquals(1, c.getIvl());
    assertEquals(col.getSched().getToday() + 1, c.getDue());
    // make it due
    col.reset();
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    c.setDue(-5);
    c.setIvl(100);
    c.flush();
    col.reset();
    assertEquals(new Counts(0, 0, 1), col.getSched().counts());
    // cram again
    did = addDynamicDeck("Cram");
    col.getSched().rebuildDyn(did);
    col.reset();
    assertEquals(new Counts(0, 0, 1), col.getSched().counts());
    c.load();
    assertEquals(4, col.getSched().answerButtons(c));
    // add a sibling so we can test minSpace, etc
    Card c2 = c.clone();
    c2.setId(0);
    c2.setOrd(1);
    c2.setDue(325);
    c2.flush();
    // should be able to answer it
    c = getCard();
    col.getSched().answerCard(c, BUTTON_FOUR);
    // it should have been moved back to the original deck
    assertEquals(1, c.getDid());
}
Also used : Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)58 Collection (com.ichi2.libanki.Collection)57 Card (com.ichi2.libanki.Card)55 Note (com.ichi2.libanki.Note)52 RobolectricTest (com.ichi2.anki.RobolectricTest)51 JSONObject (com.ichi2.utils.JSONObject)25 DeckConfig (com.ichi2.libanki.DeckConfig)20 JSONArray (com.ichi2.utils.JSONArray)16 ArrayList (java.util.ArrayList)16 Cursor (android.database.Cursor)14 Deck (com.ichi2.libanki.Deck)10 ContentResolver (android.content.ContentResolver)6 ContentValues (android.content.ContentValues)6 Uri (android.net.Uri)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 SuppressLint (android.annotation.SuppressLint)5 FileNotFoundException (java.io.FileNotFoundException)5 Activity (android.app.Activity)4 WebView (android.webkit.WebView)4