use of com.ichi2.libanki.sched.AbstractSched in project AnkiChinaAndroid by ankichinateam.
the class AbstractSchedTest method undoAndRedo.
protected void undoAndRedo(boolean preload) {
Collection col = getCol();
DeckConfig conf = col.getDecks().confForDid(1);
conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 3, 5, 10 }));
col.getConf().put("collapseTime", 20 * 60);
AbstractSched sched = col.getSched();
Note note = addNoteUsingBasicModel("foo", "bar");
col.reset();
Card card = sched.getCard();
assertNotNull(card);
assertArrayEquals(new int[] { 1, 0, 0 }, sched.counts(card));
if (preload) {
sched.preloadNextCard();
}
sched.answerCard(card, sched.getGoodNewButton());
card = sched.getCard();
assertNotNull(card);
assertArrayEquals(new int[] { 0, (schedVersion == 1) ? 3 : 1, 0 }, sched.counts(card));
if (preload) {
sched.preloadNextCard();
}
sched.answerCard(card, sched.getGoodNewButton());
card = sched.getCard();
assertNotNull(card);
assertArrayEquals(new int[] { 0, (schedVersion == 1) ? 2 : 1, 0 }, sched.counts(card));
if (preload) {
sched.preloadNextCard();
}
assertNotNull(card);
card = nonTaskUndo(col);
assertNotNull(card);
assertArrayEquals(new int[] { 0, (schedVersion == 1) ? 3 : 1, 0 }, sched.counts(card));
sched.count();
if (preload) {
sched.preloadNextCard();
}
sched.answerCard(card, sched.getGoodNewButton());
card = sched.getCard();
assertNotNull(card);
if (preload) {
sched.preloadNextCard();
}
assertArrayEquals(new int[] { 0, (schedVersion == 1) ? 2 : 1, 0 }, sched.counts(card));
assertNotNull(card);
}
use of com.ichi2.libanki.sched.AbstractSched in project AnkiChinaAndroid by ankichinateam.
the class AbstractSchedTest method siblingCorrectlyBuried.
@Test
public void siblingCorrectlyBuried() {
// #6903
Collection col = getCol();
AbstractSched sched = col.getSched();
Models models = col.getModels();
DeckConfig dconf = col.getDecks().getConf(1);
dconf.getJSONObject("new").put("bury", true);
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();
assertArrayEquals(new int[] { nbNote * 2 - i, 0, 0 }, sched.counts(card));
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);
}
use of com.ichi2.libanki.sched.AbstractSched in project AnkiChinaAndroid by ankichinateam.
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();
int[] 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 int[] { 0, 0, 0 }));
sched.answerCard(cardBeforeUndo, EASE_3);
waitForTask(UNDO, 5000);
int[] 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.AbstractSched in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_ordcycleV2.
@Test
public void test_ordcycleV2() throws Exception {
Collection col = getColV2();
// add two more templates and set second active
Model m = col.getModels().current();
Models mm = col.getModels();
JSONObject t = mm.newTemplate("Reverse");
t.put("qfmt", "{{Back}}");
t.put("afmt", "{{Front}}");
mm.addTemplateModChanged(m, t);
t = mm.newTemplate("f2");
t.put("qfmt", "{{Front}}");
t.put("afmt", "{{Back}}");
mm.addTemplateModChanged(m, t);
mm.save(m);
// create a new note; it should have 3 cards
Note note = col.newNote();
note.setItem("Front", "1");
note.setItem("Back", "1");
col.addNote(note);
assertEquals(3, col.cardCount());
col.reset();
// ordinals should arrive in order
AbstractSched sched = col.getSched();
Card c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(0, c.getOrd());
c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(1, c.getOrd());
c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(2, c.getOrd());
}
use of com.ichi2.libanki.sched.AbstractSched in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_ordcycleV1.
@Test
public void test_ordcycleV1() throws Exception {
Collection col = getColV1();
// add two more templates and set second active
Model m = col.getModels().current();
Models mm = col.getModels();
JSONObject t = mm.newTemplate("Reverse");
t.put("qfmt", "{{Back}}");
t.put("afmt", "{{Front}}");
mm.addTemplateModChanged(m, t);
t = mm.newTemplate("f2");
t.put("qfmt", "{{Front}}");
t.put("afmt", "{{Back}}");
mm.addTemplateModChanged(m, t);
mm.save(m);
// create a new note; it should have 3 cards
Note note = col.newNote();
note.setItem("Front", "1");
note.setItem("Back", "1");
col.addNote(note);
assertEquals(3, col.cardCount());
col.reset();
// ordinals should arrive in order
AbstractSched sched = col.getSched();
Card c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(0, c.getOrd());
c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(1, c.getOrd());
c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(2, c.getOrd());
}
Aggregations