use of com.ichi2.libanki.sched.Sched in project AnkiChinaAndroid by ankichinateam.
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 AnkiChinaAndroid by ankichinateam.
the class AbstractSchedTest method regression_7066.
@Test
public void regression_7066() {
Collection col = getCol();
DeckConfig dconf = col.getDecks().getConf(1);
dconf.getJSONObject("new").put("bury", true);
AbstractSched sched = col.getSched();
addNoteUsingBasicAndReversedModel("foo", "bar");
addNoteUsingBasicModel("plop", "foo");
col.reset();
Card card = sched.getCard();
sched.setCurrentCard(card);
sched.preloadNextCard();
sched.answerCard(card, Consts.BUTTON_THREE);
card = sched.getCard();
sched.setCurrentCard(card);
AnkiAssert.assertDoesNotThrow(() -> sched.preloadNextCard());
}
use of com.ichi2.libanki.sched.Sched in project AnkiChinaAndroid by ankichinateam.
the class AbstractSchedTest method ensureUndoCorrectCounts.
@Test
public void ensureUndoCorrectCounts() {
Collection col = getCol();
AbstractSched sched = col.getSched();
Deck deck = col.getDecks().get(1);
DeckConfig dconf = col.getDecks().getConf(1);
dconf.getJSONObject("new").put("perDay", 10);
JSONArray newCount = deck.getJSONArray("newToday");
for (int i = 0; i < 20; i++) {
Note note = col.newNote();
note.setField(0, "a");
col.addNote(note);
}
col.reset();
assertThat(col.cardCount(), is(20));
assertThat(sched.newCount(), is(10));
Card card = sched.getCard();
assertThat(sched.newCount(), is(9));
assertThat(sched.counts(card)[0], is(10));
sched.answerCard(card, sched.getGoodNewButton());
sched.getCard();
nonTaskUndo(col);
card.load();
assertThat(sched.newCount(), is(9));
assertThat(sched.counts(card)[0], is(10));
}
use of com.ichi2.libanki.sched.Sched in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method markNextCardAsGood.
private void markNextCardAsGood(Sched sched) {
Card toAnswer = sched.getCard();
assertThat(toAnswer, notNullValue());
// Good
sched.answerCard(toAnswer, AbstractFlashcardViewer.EASE_2);
}
use of com.ichi2.libanki.sched.Sched in project AnkiChinaAndroid by ankichinateam.
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 = col.getSched().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, 1);
// 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, 2);
// 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, 2);
// 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, 2);
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, 3);
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, 3);
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());
}
Aggregations