Search in sources :

Example 16 with Sched

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

the class SchedV2Test method ensureDeckTree.

@Test
public void ensureDeckTree() throws Exception {
    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 17 with Sched

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

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 : DeckDueTreeNode(com.ichi2.libanki.sched.DeckDueTreeNode) Matchers.containsString(org.hamcrest.Matchers.containsString) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 18 with Sched

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

the class SchedTest method markNextCardAsGood.

private void markNextCardAsGood(Sched sched) {
    Card toAnswer = sched.getCard();
    assertThat(toAnswer, notNullValue());
    // Good
    sched.answerCard(toAnswer, BUTTON_TWO);
}
Also used : Card(com.ichi2.libanki.Card)

Example 19 with Sched

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

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();
    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();
    // not upstream. But we are not expecting multiple getCard without review
    sched.answerCard(c, sched.answerButtons(c) - 1);
    waitForAsyncTasksToComplete();
    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);
    waitForAsyncTasksToComplete();
    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) ModelManager(com.ichi2.libanki.ModelManager) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 20 with Sched

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

the class SchedV2Test method regression_test_preview.

@Test
public void regression_test_preview() throws Exception {
    // "https://github.com/ankidroid/Anki-Android/issues/7285"
    Collection col = getColV2();
    DeckManager decks = col.getDecks();
    AbstractSched sched = col.getSched();
    addNoteUsingBasicModel("foo", "bar");
    long did = addDynamicDeck("test");
    Deck deck = decks.get(did);
    deck.put("resched", false);
    sched.rebuildDyn(did);
    col.reset();
    Card card;
    for (int i = 0; i < 3; i++) {
        advanceRobolectricLooperWithSleep();
        card = sched.getCard();
        assertNotNull(card);
        sched.answerCard(card, BUTTON_ONE);
    }
    advanceRobolectricLooperWithSleep();
    assertEquals(1, sched.lrnCount());
    card = sched.getCard();
    assertEquals(1, sched.counts(card).getLrn());
    advanceRobolectricLooperWithSleep();
    sched.answerCard(card, BUTTON_ONE);
    assertDoesNotThrow(col::undo);
}
Also used : Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) DeckManager(com.ichi2.libanki.DeckManager) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

Card (com.ichi2.libanki.Card)44 Collection (com.ichi2.libanki.Collection)38 Test (org.junit.Test)35 RobolectricTest (com.ichi2.anki.RobolectricTest)28 Note (com.ichi2.libanki.Note)19 AbstractSched (com.ichi2.libanki.sched.AbstractSched)18 DeckConfig (com.ichi2.libanki.DeckConfig)11 JSONObject (com.ichi2.utils.JSONObject)9 Cursor (android.database.Cursor)7 Sched (com.ichi2.libanki.Sched)6 SchedV2 (com.ichi2.libanki.sched.SchedV2)6 JSONArray (com.ichi2.utils.JSONArray)6 SuppressLint (android.annotation.SuppressLint)4 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)4 DB (com.ichi2.libanki.DB)4 Model (com.ichi2.libanki.Model)4 Sched (com.ichi2.libanki.sched.Sched)4 ArrayList (java.util.ArrayList)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ContentValues (android.content.ContentValues)3