Search in sources :

Example 66 with Counts

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

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

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

Example 69 with Counts

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

the class SchedV2 method counts.

/**
 * Same as counts(), but also count `card`. In practice, we use it because `card` is in the reviewer and that is the
 * number we actually want.
 * Overridden: left / 1000 in V1
 */
@NonNull
public Counts counts(@NonNull Card card) {
    Counts counts = counts();
    Queue idx = countIdx(card);
    counts.changeCount(idx, 1);
    return counts;
}
Also used : Queue(com.ichi2.libanki.sched.Counts.Queue) NonNull(androidx.annotation.NonNull)

Example 70 with Counts

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

the class SchedV2 method getCard.

/**
 * Pop the next card from the queue. null if finished.
 */
@Nullable
public Card getCard() {
    _checkDay();
    if (!mHaveQueues) {
        resetQueues(false);
    }
    @Nullable Card card = _getCard();
    if (card == null && !mHaveCounts) {
        // maybe we didn't refill queues because counts were not
        // set. This could only occur if the only card is a buried
        // sibling. So let's try to set counts and check again.
        reset();
        card = _getCard();
    }
    if (card != null) {
        mCol.log(card);
        incrReps();
        // In upstream, counts are decremented when the card is
        // gotten; i.e. in _getLrnCard, _getRevCard and
        // _getNewCard. This can not be done anymore since we use
        // those methods to pre-fetch the next card. Instead we
        // decrement the counts here, when the card is returned to
        // the reviewer.
        decrementCounts(card);
        setCurrentCard(card);
        card.startTimer();
    } else {
        discardCurrentCard();
    }
    if (!mHaveCounts) {
        // Need to reset queues once counts are reset
        TaskManager.launchCollectionTask(new CollectionTask.Reset());
    }
    return card;
}
Also used : CollectionTask(com.ichi2.async.CollectionTask) Nullable(androidx.annotation.Nullable) Card(com.ichi2.libanki.Card) Nullable(androidx.annotation.Nullable)

Aggregations

Collection (com.ichi2.libanki.Collection)47 Card (com.ichi2.libanki.Card)43 Test (org.junit.Test)39 RobolectricTest (com.ichi2.anki.RobolectricTest)38 Note (com.ichi2.libanki.Note)38 Deck (com.ichi2.libanki.Deck)12 DeckConfig (com.ichi2.libanki.DeckConfig)11 JSONArray (com.ichi2.utils.JSONArray)11 JSONObject (com.ichi2.utils.JSONObject)10 JSONException (com.ichi2.utils.JSONException)6 HashMap (java.util.HashMap)6 Resources (android.content.res.Resources)4 Nullable (androidx.annotation.Nullable)4 Model (com.ichi2.libanki.Model)4 AbstractDeckTreeNode (com.ichi2.libanki.sched.AbstractDeckTreeNode)4 IOException (java.io.IOException)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 JSONObject (org.json.JSONObject)4 Cursor (android.database.Cursor)3 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)3