Search in sources :

Example 36 with DeckConfig

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

the class SchedV2Test method test_newLimits_V2.

@Test
public void test_newLimits_V2() throws Exception {
    Collection col = getColV2();
    // add some notes
    long deck2 = addDeck("Default::foo");
    for (int i = 0; i < 30; i++) {
        Note note = col.newNote();
        note.setItem("Front", Integer.toString(i));
        if (i > 4) {
            note.model().put("did", deck2);
        }
        col.addNote(note);
    }
    // give the child deck a different configuration
    long c2 = col.getDecks().confId("new conf");
    col.getDecks().setConf(col.getDecks().get(deck2), c2);
    col.reset();
    // both confs have defaulted to a limit of 20
    assertEquals(20, col.getSched().newCount());
    // first card we get comes from parent
    Card c = getCard();
    assertEquals(1, c.getDid());
    // limit the parent to 10 cards, meaning we get 10 in total
    DeckConfig conf1 = col.getDecks().confForDid(1);
    conf1.getJSONObject("new").put("perDay", 10);
    col.getDecks().save(conf1);
    col.reset();
    assertEquals(10, col.getSched().newCount());
    // if we limit child to 4, we should get 9
    DeckConfig conf2 = col.getDecks().confForDid(deck2);
    conf2.getJSONObject("new").put("perDay", 4);
    col.getDecks().save(conf2);
    col.reset();
    assertEquals(9, col.getSched().newCount());
}
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)

Example 37 with DeckConfig

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

the class SchedTest method test_reviewsV1.

@Test
public void test_reviewsV1() throws Exception {
    Collection col = getColV1();
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    // set the card up as a review card, due 8 days ago
    Card c = note.cards().get(0);
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setDue(col.getSched().getToday() - 8);
    c.setFactor(STARTING_FACTOR);
    c.setReps(3);
    c.setLapses(1);
    c.setIvl(100);
    c.startTimer();
    c.flush();
    // save it for later use as well
    Card cardcopy = c.clone();
    // failing it should put it in the learn queue with the default options
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    // different delay to new
    col.reset();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 2, 20 }));
    col.getDecks().save(conf);
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    // it should be due tomorrow, with an interval of 1
    assertEquals(col.getSched().getToday() + 1, c.getODue());
    assertEquals(1, c.getIvl());
    // but because it's in the learn queue, its current due time should be in
    // the future
    assertThat(c.getDue(), is(greaterThanOrEqualTo(col.getTime().intTime())));
    assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(118L)));
    // factor should have been decremented
    assertEquals(2300, c.getFactor());
    // check counters
    assertEquals(2, c.getLapses());
    assertEquals(4, c.getReps());
    // check ests.
    assertEquals(120, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(20 * 60, col.getSched().nextIvl(c, BUTTON_TWO));
    // try again with an ease of 2 instead
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c = cardcopy.clone();
    c.flush();
    col.getSched().answerCard(c, BUTTON_TWO);
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    // the new interval should be (100 + 8/4) * 1.2 = 122
    assertTrue(checkRevIvl(col, c, 122));
    assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
    // factor should have been decremented
    assertEquals(2350, c.getFactor());
    // check counters
    assertEquals(1, c.getLapses());
    assertEquals(4, c.getReps());
    // ease 3
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c = cardcopy.clone();
    c.flush();
    col.getSched().answerCard(c, BUTTON_THREE);
    // the new interval should be (100 + 8/2) * 2.5 = 260
    assertTrue(checkRevIvl(col, c, 260));
    assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
    // factor should have been left alone
    assertEquals(STARTING_FACTOR, c.getFactor());
    // ease 4
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c = cardcopy.clone();
    c.flush();
    col.getSched().answerCard(c, BUTTON_FOUR);
    // the new interval should be (100 + 8) * 2.5 * 1.3 = 351
    assertTrue(checkRevIvl(col, c, 351));
    assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
    // factor should have been increased
    assertEquals(2650, c.getFactor());
}
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) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 38 with DeckConfig

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

the class SchedTest method test_newLimits_V1.

@Test
public void test_newLimits_V1() throws Exception {
    Collection col = getColV1();
    // add some notes
    long deck2 = addDeck("Default::foo");
    Note note;
    for (int i = 0; i < 30; i++) {
        note = col.newNote();
        note.setItem("Front", Integer.toString(i));
        if (i > 4) {
            note.model().put("did", deck2);
        }
        col.addNote(note);
    }
    // give the child deck a different configuration
    long c2 = col.getDecks().confId("new conf");
    col.getDecks().setConf(col.getDecks().get(deck2), c2);
    col.reset();
    // both confs have defaulted to a limit of 20
    assertEquals("both confs have defaulted to a limit of 20", 20, col.getSched().counts().getNew());
    // first card we get comes from parent
    Card c = getCard();
    assertEquals(1, c.getDid());
    // limit the parent to 10 cards, meaning we get 10 in total
    DeckConfig conf1 = col.getDecks().confForDid(1);
    conf1.getJSONObject("new").put("perDay", 10);
    col.getDecks().save(conf1);
    col.reset();
    assertEquals(10, col.getSched().counts().getNew());
    // if we limit child to 4, we should get 9
    DeckConfig conf2 = col.getDecks().confForDid(deck2);
    conf2.getJSONObject("new").put("perDay", 4);
    col.getDecks().save(conf2);
    col.reset();
    assertEquals(9, col.getSched().counts().getNew());
}
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)

Example 39 with DeckConfig

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

the class SchedTest method test_newBoxes_v1.

@Test
public void test_newBoxes_v1() throws Exception {
    Collection col = getColV1();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    col.reset();
    Card c = getCard();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 2, 3, 4, 5 }));
    col.getDecks().save(conf);
    col.getSched().answerCard(c, BUTTON_TWO);
    // should handle gracefully
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1 }));
    col.getDecks().save(conf);
    col.getSched().answerCard(c, BUTTON_TWO);
}
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) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 40 with DeckConfig

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

the class SchedTest method test_learn_dayV1.

@Test
public void test_learn_dayV1() throws Exception {
    Collection col = getColV1();
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    col.reset();
    Card c = getCard();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 10, 1440, 2880 }));
    col.getDecks().save(conf);
    // pass it
    col.getSched().answerCard(c, BUTTON_TWO);
    // two reps to graduate, 1 more today
    assertEquals(3, c.getLeft() % 1000);
    assertEquals(1, c.getLeft() / 1000);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    c = getCard();
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_TWO));
    // answering it will place it in queue 3
    col.getSched().answerCard(c, BUTTON_TWO);
    assertEquals(col.getSched().getToday() + 1, c.getDue());
    assertEquals(QUEUE_TYPE_DAY_LEARN_RELEARN, c.getQueue());
    assertNull(getCard());
    // for testing, move it back a day
    c.setDue(c.getDue() - 1);
    c.flush();
    col.reset();
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    c = getCard();
    // nextIvl should work
    assertEquals(SECONDS_PER_DAY * 2, col.getSched().nextIvl(c, BUTTON_TWO));
    // if we fail it, it should be back in the correct queue
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    col.undo();
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_TWO);
    // simulate the passing of another two days
    c.setDue(c.getDue() - 2);
    c.flush();
    col.reset();
    // the last pass should graduate it into a review card
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_TWO));
    col.getSched().answerCard(c, BUTTON_TWO);
    assertEquals(CARD_TYPE_REV, c.getType());
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    // if the lapse step is tomorrow, failing it should handle the counts
    // correctly
    c.setDue(0);
    c.flush();
    col.reset();
    assertEquals(new Counts(0, 0, 1), col.getSched().counts());
    conf = col.getSched()._cardConf(c);
    conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 1440 }));
    col.getDecks().save(conf);
    c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(CARD_TYPE_RELEARNING, c.getQueue());
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
}
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) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

DeckConfig (com.ichi2.libanki.DeckConfig)85 Collection (com.ichi2.libanki.Collection)57 Card (com.ichi2.libanki.Card)50 Test (org.junit.Test)49 RobolectricTest (com.ichi2.anki.RobolectricTest)48 Note (com.ichi2.libanki.Note)47 JSONArray (com.ichi2.utils.JSONArray)42 JSONObject (com.ichi2.utils.JSONObject)27 Deck (com.ichi2.libanki.Deck)14 NonNull (androidx.annotation.NonNull)12 Cursor (android.database.Cursor)5 JSONException (com.ichi2.utils.JSONException)5 ArrayList (java.util.ArrayList)5 Model (com.ichi2.libanki.Model)4 HashMap (java.util.HashMap)4 SuppressLint (android.annotation.SuppressLint)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 ContentValues (android.content.ContentValues)2 Intent (android.content.Intent)2