Search in sources :

Example 36 with AbstractSched

use of com.ichi2.libanki.sched.AbstractSched in project Anki-Android by ankidroid.

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();
    ModelManager mm = col.getModels();
    JSONObject t = Models.newTemplate("Reverse");
    t.put("qfmt", "{{Back}}");
    t.put("afmt", "{{Front}}");
    mm.addTemplateModChanged(m, t);
    t = Models.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();
    advanceRobolectricLooperWithSleep();
    // 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();
    advanceRobolectricLooperWithSleep();
    // 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();
    advanceRobolectricLooperWithSleep();
    // not upstream. But we are not expecting multiple getCard without review
    sched.answerCard(c, sched.answerButtons(c) - 1);
    advanceRobolectricLooperWithSleep();
    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) ModelManager(com.ichi2.libanki.ModelManager) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 37 with AbstractSched

use of com.ichi2.libanki.sched.AbstractSched in project Anki-Android by ankidroid.

the class SchedV2Test method ensureDeckTree.

@Test
public void ensureDeckTree() {
    for (String deckName : TEST_DECKS) {
        addDeck(deckName);
    }
    AbstractSched sched = getCol().getSched();
    List<DeckDueTreeNode> tree = sched.deckDueTree();
    Assert.assertEquals("Tree has not the expected structure", expectedTree(getCol(), true), tree);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 38 with AbstractSched

use of com.ichi2.libanki.sched.AbstractSched in project Anki-Android by ankidroid.

the class SchedTest method testRevLogValues.

@Test
public void testRevLogValues() {
    MutableTime time = new MutableTime(MockTime.timeStamp(2020, 8, 4, 11, 22, 19, 123), 10);
    Collection col = CollectionHelper.getInstance().getCol(getTargetContext(), time);
    addNoteUsingBasicModel("Hello", "World");
    AbstractSched sched = col.getSched();
    Card c = sched.getCard();
    time.setFrozen(true);
    long currentTime = time.getInternalTimeMs();
    sched.answerCard(c, BUTTON_ONE);
    long timeAnswered = col.getDb().queryLongScalar("select id from revlog");
    assertThat(timeAnswered, is(currentTime));
}
Also used : MutableTime(com.ichi2.testutils.MutableTime) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 39 with AbstractSched

use of com.ichi2.libanki.sched.AbstractSched in project Anki-Android by ankidroid.

the class SchedTest method ensureDeckTree.

@Test
public void ensureDeckTree() {
    for (String deckName : TEST_DECKS) {
        addDeck(deckName);
    }
    getCol().getSched().deckDueTree();
    AbstractSched sched = getCol().getSched();
    List<DeckDueTreeNode> tree = sched.deckDueTree();
    Assert.assertEquals("Tree has not the expected structure", SchedV2Test.expectedTree(getCol(), false), tree);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 40 with AbstractSched

use of com.ichi2.libanki.sched.AbstractSched in project Anki-Android by ankidroid.

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();
    Counts 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 Counts(0, 0, 0)));
    sched.answerCard(cardBeforeUndo, Consts.BUTTON_THREE);
    waitFortask(new UndoService.Undo().toDelegate(), 5000);
    Counts 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) CollectionTask.nonTaskUndo(com.ichi2.async.CollectionTask.nonTaskUndo) 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