Search in sources :

Example 41 with Queue

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

the class SchedTest method test_counts_idxV1.

@Test
public void test_counts_idxV1() throws Exception {
    Collection col = getColV1();
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    col.reset();
    assertEquals(new Counts(1, 0, 0), col.getSched().counts());
    Card c = getCard();
    // counter's been decremented but idx indicates 1
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    assertEquals(NEW, col.getSched().countIdx(c));
    // answer to move to learn queue
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(new Counts(0, 2, 0), col.getSched().counts());
    // fetching again will decrement the count
    c = getCard();
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    assertEquals(LRN, col.getSched().countIdx(c));
    // answering should add it back again
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(new Counts(0, 2, 0), col.getSched().counts());
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 42 with Queue

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

the class SchedTest method test_learn_collapsedV1.

@Test
public void test_learn_collapsedV1() throws Exception {
    Collection col = getColV1();
    // add 2 notes
    Note note = col.newNote();
    note.setItem("Front", "1");
    col.addNote(note);
    note = col.newNote();
    note.setItem("Front", "2");
    col.addNote(note);
    // set as a learn card and rebuild queues
    col.getDb().execute("update cards set queue=0, type=0");
    col.reset();
    // should get '1' first
    Card c = getCard();
    assertTrue(c.q().endsWith("1"));
    // pass it so it's due in 10 minutes
    col.getSched().answerCard(c, BUTTON_TWO);
    // get the other card
    c = getCard();
    assertTrue(c.q().endsWith("2"));
    // fail it so it's due in 1 minute
    col.getSched().answerCard(c, BUTTON_ONE);
    // we shouldn't get the same card again
    c = getCard();
    assertFalse(c.q().endsWith("2"));
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 43 with Queue

use of com.ichi2.libanki.sched.Counts.Queue 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 44 with Queue

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

the class UndoTest method test_review.

@Test
public void test_review() throws Exception {
    Collection col = getColV2();
    col.set_config("counts", COUNT_REMAINING);
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    col.reset();
    /* TODO:  undo after reset ?
        assertNotNull(col.undoType());

         */
    // answer
    assertEquals(new Counts(1, 0, 0), col.getSched().counts());
    Card c = col.getSched().getCard();
    assertEquals(QUEUE_TYPE_NEW, c.getQueue());
    col.getSched().answerCard(c, Consts.BUTTON_THREE);
    assertEquals(1001, c.getLeft());
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    // undo
    assertNotNull(col.undoType());
    col.undo();
    col.reset();
    assertEquals(new Counts(1, 0, 0), col.getSched().counts());
    c.load();
    assertEquals(QUEUE_TYPE_NEW, c.getQueue());
    assertNotEquals(1001, c.getLeft());
    assertNull(col.undoType());
    // we should be able to undo multiple answers too
    note = col.newNote();
    note.setItem("Front", "two");
    col.addNote(note);
    col.reset();
    assertEquals(new Counts(2, 0, 0), col.getSched().counts());
    c = col.getSched().getCard();
    col.getSched().answerCard(c, Consts.BUTTON_THREE);
    c = col.getSched().getCard();
    col.getSched().answerCard(c, Consts.BUTTON_THREE);
    assertEquals(new Counts(0, 2, 0), col.getSched().counts());
    col.undo();
    col.reset();
    assertEquals(new Counts(1, 1, 0), col.getSched().counts());
    col.undo();
    col.reset();
    assertEquals(new Counts(2, 0, 0), col.getSched().counts());
    // performing a normal op will clear the review queue
    c = col.getSched().getCard();
    col.getSched().answerCard(c, Consts.BUTTON_THREE);
    assertThat(col.undoType(), is(instanceOf(Collection.UndoReview.class)));
    col.save("foo");
    // Upstream, "save" can be undone. This test fails here because it's not the case in AnkiDroid
    assumeThat(col.undoName(getTargetContext().getResources()), is("foo"));
    col.undo();
}
Also used : Counts(com.ichi2.libanki.sched.Counts) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 45 with Queue

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

the class AbstractSchedTest method testCardQueue.

@Test
public void testCardQueue() {
    Collection col = getCol();
    SchedV2 sched = (SchedV2) col.getSched();
    SimpleCardQueue queue = new SimpleCardQueue(sched);
    assertThat(queue.size(), is(0));
    final int nbCard = 6;
    long[] cids = new long[nbCard];
    for (int i = 0; i < nbCard; i++) {
        Note note = addNoteUsingBasicModel("foo", "bar");
        Card card = note.firstCard();
        long cid = card.getId();
        cids[i] = cid;
        queue.add(cid);
    }
    assertThat(queue.size(), is(nbCard));
    assertEquals(cids[0], queue.removeFirstCard().getId());
    assertThat(queue.size(), is(nbCard - 1));
    queue.remove(cids[1]);
    assertThat(queue.size(), is(nbCard - 2));
    queue.remove(cids[3]);
    assertThat(queue.size(), is(nbCard - 3));
    assertEquals(cids[2], queue.removeFirstCard().getId());
    assertThat(queue.size(), is(nbCard - 4));
    assertEquals(cids[4], queue.removeFirstCard().getId());
    assertThat(queue.size(), is(nbCard - 5));
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

Card (com.ichi2.libanki.Card)31 Test (org.junit.Test)30 RobolectricTest (com.ichi2.anki.RobolectricTest)29 Collection (com.ichi2.libanki.Collection)27 Note (com.ichi2.libanki.Note)24 JSONObject (com.ichi2.utils.JSONObject)20 JSONArray (com.ichi2.utils.JSONArray)17 DeckConfig (com.ichi2.libanki.DeckConfig)15 Cursor (android.database.Cursor)10 ArrayList (java.util.ArrayList)10 Deck (com.ichi2.libanki.Deck)6 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)4 JSONException (com.ichi2.utils.JSONException)3 Nullable (androidx.annotation.Nullable)2 SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)2 Model (com.ichi2.libanki.Model)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 SuppressLint (android.annotation.SuppressLint)1