Search in sources :

Example 31 with AbstractSched

use of com.ichi2.libanki.sched.AbstractSched in project AnkiChinaAndroid by ankichinateam.

the class AbstractSchedTest method undoAndRedo.

protected void undoAndRedo(boolean preload) {
    Collection col = getCol();
    DeckConfig conf = col.getDecks().confForDid(1);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 3, 5, 10 }));
    col.getConf().put("collapseTime", 20 * 60);
    AbstractSched sched = col.getSched();
    Note note = addNoteUsingBasicModel("foo", "bar");
    col.reset();
    Card card = sched.getCard();
    assertNotNull(card);
    assertArrayEquals(new int[] { 1, 0, 0 }, sched.counts(card));
    if (preload) {
        sched.preloadNextCard();
    }
    sched.answerCard(card, sched.getGoodNewButton());
    card = sched.getCard();
    assertNotNull(card);
    assertArrayEquals(new int[] { 0, (schedVersion == 1) ? 3 : 1, 0 }, sched.counts(card));
    if (preload) {
        sched.preloadNextCard();
    }
    sched.answerCard(card, sched.getGoodNewButton());
    card = sched.getCard();
    assertNotNull(card);
    assertArrayEquals(new int[] { 0, (schedVersion == 1) ? 2 : 1, 0 }, sched.counts(card));
    if (preload) {
        sched.preloadNextCard();
    }
    assertNotNull(card);
    card = nonTaskUndo(col);
    assertNotNull(card);
    assertArrayEquals(new int[] { 0, (schedVersion == 1) ? 3 : 1, 0 }, sched.counts(card));
    sched.count();
    if (preload) {
        sched.preloadNextCard();
    }
    sched.answerCard(card, sched.getGoodNewButton());
    card = sched.getCard();
    assertNotNull(card);
    if (preload) {
        sched.preloadNextCard();
    }
    assertArrayEquals(new int[] { 0, (schedVersion == 1) ? 2 : 1, 0 }, sched.counts(card));
    assertNotNull(card);
}
Also used : Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card)

Example 32 with AbstractSched

use of com.ichi2.libanki.sched.AbstractSched in project AnkiChinaAndroid by ankichinateam.

the class AbstractSchedTest method siblingCorrectlyBuried.

@Test
public void siblingCorrectlyBuried() {
    // #6903
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    Models models = col.getModels();
    DeckConfig dconf = col.getDecks().getConf(1);
    dconf.getJSONObject("new").put("bury", true);
    final int nbNote = 2;
    Note[] notes = new Note[nbNote];
    for (int i = 0; i < nbNote; i++) {
        Note note = addNoteUsingBasicAndReversedModel("front", "back");
        notes[i] = note;
    }
    col.reset();
    for (int i = 0; i < nbNote; i++) {
        Card card = sched.getCard();
        assertArrayEquals(new int[] { nbNote * 2 - i, 0, 0 }, sched.counts(card));
        assertEquals(notes[i].firstCard().getId(), card.getId());
        assertEquals(Consts.QUEUE_TYPE_NEW, card.getQueue());
        sched.answerCard(card, sched.answerButtons(card));
    }
    Card card = sched.getCard();
    assertNull(card);
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Models(com.ichi2.libanki.Models) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 33 with AbstractSched

use of com.ichi2.libanki.sched.AbstractSched in project AnkiChinaAndroid by ankichinateam.

the class AbstractSchedTest method testUndoResetsCardCountsToCorrectValue.

@Test
public void testUndoResetsCardCountsToCorrectValue() throws InterruptedException {
    // #6587
    addNoteUsingBasicModel("Hello", "World");
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    col.reset();
    Card cardBeforeUndo = sched.getCard();
    int[] countsBeforeUndo = sched.counts();
    // Not shown in the UI, but there is a state where the card has been removed from the queue, but not answered
    // where the counts are decremented.
    assertThat(countsBeforeUndo, is(new int[] { 0, 0, 0 }));
    sched.answerCard(cardBeforeUndo, EASE_3);
    waitForTask(UNDO, 5000);
    int[] countsAfterUndo = sched.counts();
    assertThat("Counts after an undo should be the same as before an undo", countsAfterUndo, is(countsBeforeUndo));
}
Also used : Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 34 with AbstractSched

use of com.ichi2.libanki.sched.AbstractSched in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method test_ordcycleV2.

@Test
public void test_ordcycleV2() throws Exception {
    Collection col = getColV2();
    // add two more templates and set second active
    Model m = col.getModels().current();
    Models mm = col.getModels();
    JSONObject t = mm.newTemplate("Reverse");
    t.put("qfmt", "{{Back}}");
    t.put("afmt", "{{Front}}");
    mm.addTemplateModChanged(m, t);
    t = mm.newTemplate("f2");
    t.put("qfmt", "{{Front}}");
    t.put("afmt", "{{Back}}");
    mm.addTemplateModChanged(m, t);
    mm.save(m);
    // create a new note; it should have 3 cards
    Note note = col.newNote();
    note.setItem("Front", "1");
    note.setItem("Back", "1");
    col.addNote(note);
    assertEquals(3, col.cardCount());
    col.reset();
    // ordinals should arrive in order
    AbstractSched sched = col.getSched();
    Card c = sched.getCard();
    // not upstream. But we are not expecting multiple getCard without review
    sched.answerCard(c, sched.answerButtons(c) - 1);
    assertEquals(0, c.getOrd());
    c = sched.getCard();
    // not upstream. But we are not expecting multiple getCard without review
    sched.answerCard(c, sched.answerButtons(c) - 1);
    assertEquals(1, c.getOrd());
    c = sched.getCard();
    // not upstream. But we are not expecting multiple getCard without review
    sched.answerCard(c, sched.answerButtons(c) - 1);
    assertEquals(2, c.getOrd());
}
Also used : JSONObject(com.ichi2.utils.JSONObject) Note(com.ichi2.libanki.Note) Model(com.ichi2.libanki.Model) Collection(com.ichi2.libanki.Collection) Models(com.ichi2.libanki.Models) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 35 with AbstractSched

use of com.ichi2.libanki.sched.AbstractSched in project AnkiChinaAndroid by ankichinateam.

the class SchedTest method test_ordcycleV1.

@Test
public void test_ordcycleV1() throws Exception {
    Collection col = getColV1();
    // add two more templates and set second active
    Model m = col.getModels().current();
    Models mm = col.getModels();
    JSONObject t = mm.newTemplate("Reverse");
    t.put("qfmt", "{{Back}}");
    t.put("afmt", "{{Front}}");
    mm.addTemplateModChanged(m, t);
    t = mm.newTemplate("f2");
    t.put("qfmt", "{{Front}}");
    t.put("afmt", "{{Back}}");
    mm.addTemplateModChanged(m, t);
    mm.save(m);
    // create a new note; it should have 3 cards
    Note note = col.newNote();
    note.setItem("Front", "1");
    note.setItem("Back", "1");
    col.addNote(note);
    assertEquals(3, col.cardCount());
    col.reset();
    // ordinals should arrive in order
    AbstractSched sched = col.getSched();
    Card c = sched.getCard();
    // not upstream. But we are not expecting multiple getCard without review
    sched.answerCard(c, sched.answerButtons(c) - 1);
    assertEquals(0, c.getOrd());
    c = sched.getCard();
    // not upstream. But we are not expecting multiple getCard without review
    sched.answerCard(c, sched.answerButtons(c) - 1);
    assertEquals(1, c.getOrd());
    c = sched.getCard();
    // not upstream. But we are not expecting multiple getCard without review
    sched.answerCard(c, sched.answerButtons(c) - 1);
    assertEquals(2, c.getOrd());
}
Also used : JSONObject(com.ichi2.utils.JSONObject) Note(com.ichi2.libanki.Note) Model(com.ichi2.libanki.Model) Collection(com.ichi2.libanki.Collection) Models(com.ichi2.libanki.Models) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

Card (com.ichi2.libanki.Card)28 Collection (com.ichi2.libanki.Collection)28 Test (org.junit.Test)23 AbstractSched (com.ichi2.libanki.sched.AbstractSched)19 RobolectricTest (com.ichi2.anki.RobolectricTest)18 Note (com.ichi2.libanki.Note)12 DeckConfig (com.ichi2.libanki.DeckConfig)9 JSONObject (com.ichi2.utils.JSONObject)9 Deck (com.ichi2.libanki.Deck)5 JSONArray (com.ichi2.utils.JSONArray)5 Cursor (android.database.Cursor)4 DB (com.ichi2.libanki.DB)4 Model (com.ichi2.libanki.Model)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Models (com.ichi2.libanki.Models)3 Undoable (com.ichi2.libanki.Undoable)3 Sched (com.ichi2.libanki.sched.Sched)3 SchedV2 (com.ichi2.libanki.sched.SchedV2)3 JSONException (com.ichi2.utils.JSONException)3 SuppressLint (android.annotation.SuppressLint)2