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());
}
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();
}
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));
}
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;
}
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;
}
Aggregations