use of com.ichi2.libanki.sched.Sched in project AnkiChinaAndroid by ankichinateam.
the class FinderTest method searchForBuriedReturnsManuallyAndSiblingBuried.
@Test
@Config(qualifiers = "en")
public void searchForBuriedReturnsManuallyAndSiblingBuried() {
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, false);
// 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 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.Sched 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.Sched 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.Sched in project AnkiChinaAndroid by ankichinateam.
the class AbstractSchedTest method testCardQueue.
@Test
public void testCardQueue() {
Collection col = getCol();
SchedV2 sched = (SchedV2) col.getSched();
SimpleCardQueue queue = new SimpleCardQueue(sched);
assertThat(queue.size(), is(0));
final int nbCard = 6;
long[] cids = new long[nbCard];
for (int i = 0; i < nbCard; i++) {
Note note = addNoteUsingBasicModel("foo", "bar");
Card card = note.firstCard();
long cid = card.getId();
cids[i] = cid;
queue.add(cid);
}
assertThat(queue.size(), is(nbCard));
assertEquals(cids[0], queue.removeFirstCard().getId());
assertThat(queue.size(), is(nbCard - 1));
queue.remove(cids[1]);
assertThat(queue.size(), is(nbCard - 2));
queue.remove(cids[3]);
assertThat(queue.size(), is(nbCard - 3));
assertEquals(cids[2], queue.removeFirstCard().getId());
assertThat(queue.size(), is(nbCard - 4));
assertEquals(cids[4], queue.removeFirstCard().getId());
assertThat(queue.size(), is(nbCard - 5));
}
Aggregations