Search in sources :

Example 21 with Sched

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

the class DeckPickerTest method limitAppliedAfterReview.

@Test
public void limitAppliedAfterReview() {
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    DeckConfig dconf = col.getDecks().getConf(1);
    assertNotNull(dconf);
    dconf.getJSONObject("new").put("perDay", 10);
    col.getDecks().save(dconf);
    for (int i = 0; i < 11; i++) {
        addNoteUsingBasicModel("Which card is this ?", Integer.toString(i));
    }
    // This set a card as current card
    sched.getCard();
    ensureCollectionLoadIsSynchronous();
    DeckPicker deckPicker = super.startActivityNormallyOpenCollectionWithIntent(DeckPicker.class, new Intent());
    assertEquals(10, deckPicker.mDueTree.get(0).getNewCount());
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Collection(com.ichi2.libanki.Collection) Intent(android.content.Intent) DeckConfig(com.ichi2.libanki.DeckConfig) Test(org.junit.Test)

Example 22 with Sched

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

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;
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Sched(com.ichi2.libanki.sched.Sched) SuppressLint(android.annotation.SuppressLint) SchedV2(com.ichi2.libanki.sched.SchedV2)

Example 23 with Sched

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

the class CardContentProvider method answerCard.

private void answerCard(Collection col, AbstractSched sched, Card cardToAnswer, @Consts.BUTTON_TYPE int ease, long timeTaken) {
    try {
        DB db = col.getDb();
        db.getDatabase().beginTransaction();
        try {
            if (cardToAnswer != null) {
                if (timeTaken != -1) {
                    cardToAnswer.setTimerStarted(col.getTime().intTimeMS() - timeTaken);
                }
                sched.answerCard(cardToAnswer, ease);
            }
            db.getDatabase().setTransactionSuccessful();
        } finally {
            DB.safeEndInTransaction(db);
        }
    } catch (RuntimeException e) {
        Timber.e(e, "answerCard - RuntimeException on answering card");
        AnkiDroidApp.sendExceptionReport(e, "doInBackgroundAnswerCard");
    }
}
Also used : DB(com.ichi2.libanki.DB)

Example 24 with Sched

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

the class FinderTest method searchForBuriedReturnsManuallyAndSiblingBuried.

@Test
@Config(qualifiers = "en")
public void searchForBuriedReturnsManuallyAndSiblingBuried() throws ConfirmModSchemaException {
    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, new SortOrder.NoOrdering());
    // 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 25 with Sched

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

the class AbstractSchedTest method siblingCorrectlyBuried.

@Test
public void siblingCorrectlyBuried() {
    // #6903
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    DeckConfig dconf = col.getDecks().getConf(1);
    assertThat(dconf, notNullValue());
    dconf.getJSONObject("new").put("bury", true);
    getCol().getDecks().save(dconf);
    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();
        Counts counts = sched.counts(card);
        // imitate what the reviewer does
        sched.setCurrentCard(card);
        // Actual number of new card.
        assertThat(counts.getNew(), is(greaterThan(nbNote - i)));
        // Maximal number potentially shown,
        assertThat(counts.getNew(), is(lessThanOrEqualTo(nbNote * 2 - i)));
        // because decrementing does not consider burying sibling
        assertEquals(0, counts.getLrn());
        assertEquals(0, counts.getRev());
        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) DeckConfig(com.ichi2.libanki.DeckConfig) 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