Search in sources :

Example 41 with Sched

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));
}
Also used : SchedV2(com.ichi2.libanki.sched.SchedV2) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 42 with Sched

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);
}
Also used : Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card)

Example 43 with Sched

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);
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Models(com.ichi2.libanki.Models) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 44 with Sched

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));
}
Also used : Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 45 with Sched

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));
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

Card (com.ichi2.libanki.Card)44 Collection (com.ichi2.libanki.Collection)38 Test (org.junit.Test)35 RobolectricTest (com.ichi2.anki.RobolectricTest)28 Note (com.ichi2.libanki.Note)19 AbstractSched (com.ichi2.libanki.sched.AbstractSched)18 DeckConfig (com.ichi2.libanki.DeckConfig)11 JSONObject (com.ichi2.utils.JSONObject)9 Cursor (android.database.Cursor)7 Sched (com.ichi2.libanki.Sched)6 SchedV2 (com.ichi2.libanki.sched.SchedV2)6 JSONArray (com.ichi2.utils.JSONArray)6 SuppressLint (android.annotation.SuppressLint)4 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)4 DB (com.ichi2.libanki.DB)4 Model (com.ichi2.libanki.Model)4 Sched (com.ichi2.libanki.sched.Sched)4 ArrayList (java.util.ArrayList)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ContentValues (android.content.ContentValues)3