Search in sources :

Example 46 with Sched

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

the class SchedTest method unburyWorksIfDeckIsNotSelected.

@Test
public void unburyWorksIfDeckIsNotSelected() {
    // Issue 6200
    Sched sched = new Sched(getCol());
    Card buriedCard = createBuriedCardInDefaultDeck();
    assertThat(buriedCard.getDid(), is(Consts.DEFAULT_DECK_ID));
    assertThat("Card should be buried", getCardInDefaultDeck(sched), nullValue());
    // We want to assert that we can unbury, even if the deck we're unburying from isn't selected
    selectNewDeck();
    sched.unburyCardsForDeck(Consts.DEFAULT_DECK_ID);
    assertThat("Card should no longer be buried", getCardInDefaultDeck(sched), notNullValue());
}
Also used : Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 47 with Sched

use of com.ichi2.libanki.sched.Sched 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 48 with Sched

use of com.ichi2.libanki.sched.Sched 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)

Example 49 with Sched

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

the class SchedTest method learnCardsAreNotFiltered.

@Test
public void learnCardsAreNotFiltered() {
    // Replicates Anki commit: 13c54e02d8fd2b35f6c2f4b796fc44dec65043b8
    addNoteUsingBasicModel("Hello", "World");
    Sched sched = new Sched(getCol());
    markNextCardAsGood(sched);
    long dynDeck = addDynamicDeck("Hello");
    // Act
    sched.rebuildDyn(dynDeck);
    // Assert
    DeckDueTreeNode dynamicDeck = getCountsForDid(dynDeck);
    assertThat("A learn card should not be moved into a dyn deck", dynamicDeck.getLrnCount(), is(0));
    assertThat("A learn card should not be moved into a dyn deck", dynamicDeck.getNewCount(), is(0));
    assertThat("A learn card should not be moved into a dyn deck", dynamicDeck.getRevCount(), is(0));
}
Also used : DeckDueTreeNode(com.ichi2.libanki.sched.DeckDueTreeNode) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 50 with Sched

use of com.ichi2.libanki.sched.Sched 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)

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