Search in sources :

Example 51 with Sched

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

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

the class SchedTest method unburyWorksIfDeckIsNotSelected.

@Test
public void unburyWorksIfDeckIsNotSelected() {
    // Issue 6200
    Sched sched = new Sched(getCol());
    Card buriedCard = createBuriedCardInDefaultDeck();
    assertThat(buriedCard.getDid(), is(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(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 53 with Sched

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

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

the class SchedTest method test_learnV1.

@Test
public void test_learnV1() throws Exception {
    Collection col = getColV1();
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    // set as a learn card and rebuild queues
    col.getDb().execute("update cards set queue=0, type=0");
    col.reset();
    // sched.getCard should return it, since it's due in the past
    Card c = getCard();
    assertNotNull(c);
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 0.5, 3, 10 }));
    col.getDecks().save(conf);
    // fail it
    col.getSched().answerCard(c, BUTTON_ONE);
    // it should have three reps left to graduation
    assertEquals(3, c.getLeft() % 1000);
    assertEquals(3, c.getLeft() / 1000);
    // it should be due in 30 seconds
    long t = Math.round(c.getDue() - col.getTime().intTime());
    assertThat(t, is(greaterThanOrEqualTo(25L)));
    assertThat(t, is(lessThanOrEqualTo(40L)));
    // pass it once
    col.getSched().answerCard(c, BUTTON_TWO);
    // it should be due in 3 minutes
    assertEquals(Math.round(c.getDue() - col.getTime().intTime()), 179, 1);
    assertEquals(2, c.getLeft() % 1000);
    assertEquals(2, c.getLeft() / 1000);
    // check log is accurate
    Cursor log = col.getDb().getDatabase().query("select * from revlog order by id desc");
    assertTrue(log.moveToFirst());
    assertEquals(2, log.getInt(3));
    assertEquals(-180, log.getInt(4));
    assertEquals(-30, log.getInt(5));
    // pass again
    col.getSched().answerCard(c, BUTTON_TWO);
    // it should be due in 10 minutes
    assertEquals(c.getDue() - col.getTime().intTime(), 599, 1);
    assertEquals(1, c.getLeft() % 1000);
    assertEquals(1, c.getLeft() / 1000);
    // the next pass should graduate the card
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    assertEquals(CARD_TYPE_LRN, c.getType());
    col.getSched().answerCard(c, BUTTON_TWO);
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    assertEquals(CARD_TYPE_REV, c.getType());
    // should be due tomorrow, with an interval of 1
    assertEquals(col.getSched().getToday() + 1, c.getDue());
    assertEquals(1, c.getIvl());
    // or normal removal
    c.setType(CARD_TYPE_NEW);
    c.setQueue(QUEUE_TYPE_LRN);
    col.getSched().answerCard(c, BUTTON_THREE);
    assertEquals(CARD_TYPE_REV, c.getType());
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    assertTrue(checkRevIvl(col, c, 4));
    // revlog should have been updated each time
    assertEquals(5, col.getDb().queryScalar("select count() from revlog where type = 0"));
    // now failed card handling
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_LRN);
    c.setODue(123);
    col.getSched().answerCard(c, BUTTON_THREE);
    assertEquals(123, c.getDue());
    assertEquals(CARD_TYPE_REV, c.getType());
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    // we should be able to remove manually, too
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_LRN);
    c.setODue(321);
    c.flush();
    ((Sched) col.getSched()).removeLrn();
    c.load();
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    assertEquals(321, c.getDue());
}
Also used : Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) Cursor(android.database.Cursor) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 55 with Sched

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

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