Search in sources :

Example 11 with SchedV2

use of com.ichi2.libanki.sched.SchedV2 in project Anki-Android by ankidroid.

the class AbstractSchedTest method regression_7984.

@Test
public void regression_7984() {
    Collection col = getCol();
    SchedV2 sched = (SchedV2) col.getSched();
    Time time = getCol().getTime();
    Card[] cards = new Card[2];
    for (int i = 0; i < 2; i++) {
        cards[i] = addNoteUsingBasicModel(Integer.toString(i), "").cards().get(0);
        cards[i].setQueue(Consts.QUEUE_TYPE_LRN);
        cards[i].setType(Consts.CARD_TYPE_LRN);
        cards[i].setDue(time.intTime() - 20 * 60 + i);
        cards[i].flush();
    }
    col.reset();
    // Regression test success non deterministically without the sleep
    Card gotten = sched.getCard();
    advanceRobolectricLooperWithSleep();
    assertThat(gotten, is(cards[0]));
    sched.answerCard(gotten, Consts.BUTTON_ONE);
    gotten = sched.getCard();
    assertThat(gotten, is(cards[1]));
    sched.answerCard(gotten, Consts.BUTTON_ONE);
    gotten = sched.getCard();
    assertThat(gotten, is(cards[0]));
}
Also used : Collection(com.ichi2.libanki.Collection) Time(com.ichi2.libanki.utils.Time) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 12 with SchedV2

use of com.ichi2.libanki.sched.SchedV2 in project Anki-Android by ankidroid.

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

RobolectricTest (com.ichi2.anki.RobolectricTest)7 SchedV2 (com.ichi2.libanki.sched.SchedV2)7 Test (org.junit.Test)7 Card (com.ichi2.libanki.Card)5 Collection (com.ichi2.libanki.Collection)5 SuppressLint (android.annotation.SuppressLint)4 Note (com.ichi2.libanki.Note)4 AbstractSched (com.ichi2.libanki.sched.AbstractSched)3 Sched (com.ichi2.libanki.sched.Sched)3 DeckConfig (com.ichi2.libanki.DeckConfig)2 JSONArray (com.ichi2.utils.JSONArray)2 JSONObject (com.ichi2.utils.JSONObject)2 Config (org.robolectric.annotation.Config)2 Time (com.ichi2.libanki.utils.Time)1