use of com.ichi2.libanki.sched.Sched in project Anki-Android by ankidroid.
the class DeckPickerTest method limitAppliedAfterReview.
@Test
public void limitAppliedAfterReview() {
Collection col = getCol();
AbstractSched sched = col.getSched();
DeckConfig dconf = col.getDecks().getConf(1);
assertNotNull(dconf);
dconf.getJSONObject("new").put("perDay", 10);
col.getDecks().save(dconf);
for (int i = 0; i < 11; i++) {
addNoteUsingBasicModel("Which card is this ?", Integer.toString(i));
}
// This set a card as current card
sched.getCard();
ensureCollectionLoadIsSynchronous();
DeckPicker deckPicker = super.startActivityNormallyOpenCollectionWithIntent(DeckPicker.class, new Intent());
assertEquals(10, deckPicker.mDueTree.get(0).getNewCount());
}
use of com.ichi2.libanki.sched.Sched in project Anki-Android by ankidroid.
the class Collection method createScheduler.
// This duplicates _loadScheduler (but returns the value and sets the report limit).
public AbstractSched createScheduler(int reportLimit) {
int ver = schedVer();
if (ver == 1) {
mSched = new Sched(this);
} else if (ver == 2) {
mSched = new SchedV2(this);
}
mSched.setReportLimit(reportLimit);
return mSched;
}
use of com.ichi2.libanki.sched.Sched in project Anki-Android by ankidroid.
the class CardContentProvider method answerCard.
private void answerCard(Collection col, AbstractSched sched, Card cardToAnswer, @Consts.BUTTON_TYPE int ease, long timeTaken) {
try {
DB db = col.getDb();
db.getDatabase().beginTransaction();
try {
if (cardToAnswer != null) {
if (timeTaken != -1) {
cardToAnswer.setTimerStarted(col.getTime().intTimeMS() - timeTaken);
}
sched.answerCard(cardToAnswer, ease);
}
db.getDatabase().setTransactionSuccessful();
} finally {
DB.safeEndInTransaction(db);
}
} catch (RuntimeException e) {
Timber.e(e, "answerCard - RuntimeException on answering card");
AnkiDroidApp.sendExceptionReport(e, "doInBackgroundAnswerCard");
}
}
use of com.ichi2.libanki.sched.Sched in project Anki-Android by ankidroid.
the class FinderTest method searchForBuriedReturnsManuallyAndSiblingBuried.
@Test
@Config(qualifiers = "en")
public void searchForBuriedReturnsManuallyAndSiblingBuried() throws ConfirmModSchemaException {
final String searchQuery = "is:buried";
// needs to be first
SchedV2 sched = upgradeToSchedV2();
enableBurySiblings();
super.addNoteUsingModelName("Basic (and reversed card)", "Front", "Back");
Card toAnswer = sched.getCard();
// act
Card siblingBuried = burySiblings(sched, toAnswer);
Card manuallyBuriedCard = buryManually(sched, toAnswer.getId());
// perform the search
List<Long> buriedCards = new Finder(getCol()).findCards(searchQuery, new SortOrder.NoOrdering());
// assert
assertThat("A manually buried card should be returned", buriedCards, hasItem(manuallyBuriedCard.getId()));
assertThat("A sibling buried card should be returned", buriedCards, hasItem(siblingBuried.getId()));
assertThat("sibling and manually buried should be the only cards returned", buriedCards, hasSize(2));
}
use of com.ichi2.libanki.sched.Sched in project Anki-Android by ankidroid.
the class AbstractSchedTest method siblingCorrectlyBuried.
@Test
public void siblingCorrectlyBuried() {
// #6903
Collection col = getCol();
AbstractSched sched = col.getSched();
DeckConfig dconf = col.getDecks().getConf(1);
assertThat(dconf, notNullValue());
dconf.getJSONObject("new").put("bury", true);
getCol().getDecks().save(dconf);
final int nbNote = 2;
Note[] notes = new Note[nbNote];
for (int i = 0; i < nbNote; i++) {
Note note = addNoteUsingBasicAndReversedModel("front", "back");
notes[i] = note;
}
col.reset();
for (int i = 0; i < nbNote; i++) {
Card card = sched.getCard();
Counts counts = sched.counts(card);
// imitate what the reviewer does
sched.setCurrentCard(card);
// Actual number of new card.
assertThat(counts.getNew(), is(greaterThan(nbNote - i)));
// Maximal number potentially shown,
assertThat(counts.getNew(), is(lessThanOrEqualTo(nbNote * 2 - i)));
// because decrementing does not consider burying sibling
assertEquals(0, counts.getLrn());
assertEquals(0, counts.getRev());
assertEquals(notes[i].firstCard().getId(), card.getId());
assertEquals(Consts.QUEUE_TYPE_NEW, card.getQueue());
sched.answerCard(card, sched.answerButtons(card));
}
Card card = sched.getCard();
assertNull(card);
}
Aggregations