Search in sources :

Example 76 with DeckConfig

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

the class SchedV2Test method test_moveVersions.

@Test
public void test_moveVersions() throws Exception {
    Collection col = getColV2();
    col.changeSchedulerVer(1);
    Note n = col.newNote();
    n.setItem("Front", "one");
    col.addNote(n);
    // make it a learning card
    col.reset();
    Card c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    // the move to v2 should reset it to new
    col.changeSchedulerVer(2);
    c.load();
    assertEquals(QUEUE_TYPE_NEW, c.getQueue());
    assertEquals(CARD_TYPE_NEW, c.getType());
    // fail it again, and manually bury it
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    col.getSched().buryCards(new long[] { c.getId() });
    c.load();
    assertEquals(QUEUE_TYPE_MANUALLY_BURIED, c.getQueue());
    // revert to version 1
    col.changeSchedulerVer(1);
    // card should have moved queues
    c.load();
    assertEquals(QUEUE_TYPE_SIBLING_BURIED, c.getQueue());
    // and it should be new again when unburied
    col.getSched().unburyCards();
    c.load();
    assertEquals(CARD_TYPE_NEW, c.getQueue());
    assertEquals(QUEUE_TYPE_NEW, c.getType());
    // make sure relearning cards transition correctly to v1
    col.changeSchedulerVer(2);
    // card with 100 day interval, answering again
    col.getSched().reschedCards(Collections.singletonList(c.getId()), 100, 100);
    c.load();
    c.setDue(0);
    c.flush();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("lapse").put("mult", 0.5);
    col.getDecks().save(conf);
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    c.load();
    assertEquals(50, c.getIvl());
    // due should be correctly set when removed from learning early
    col.changeSchedulerVer(1);
    c.load();
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    assertEquals(CARD_TYPE_REV, c.getType());
    assertEquals(50, c.getDue());
}
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 77 with DeckConfig

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

the class SchedV2Test method test_relearn_no_steps.

@Test
public void test_relearn_no_steps() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    c.setIvl(100);
    c.setDue(col.getSched().getToday());
    c.setQueue(QUEUE_TYPE_REV);
    c.setType(CARD_TYPE_REV);
    c.flush();
    DeckConfig conf = col.getDecks().confForDid(1);
    conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] {}));
    col.getDecks().save(conf);
    // fail the card
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(CARD_TYPE_REV, c.getType());
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
}
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 78 with DeckConfig

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

the class SchedV2Test method test_button_spacingV2.

@Test
public void test_button_spacingV2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    // 1 day ivl review card due now
    Card c = note.cards().get(0);
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setDue(col.getSched().getToday());
    c.setReps(1);
    c.setIvl(1);
    c.startTimer();
    c.flush();
    col.reset();
    // Upstream, there is no space in 2d
    assertEquals("2 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, BUTTON_TWO)));
    assertEquals("3 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, BUTTON_THREE)));
    assertEquals("4 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, BUTTON_FOUR)));
    // if hard factor is <= 1, then hard may not increase
    DeckConfig conf = col.getDecks().confForDid(1);
    conf.getJSONObject("rev").put("hardFactor", 1);
    col.getDecks().save(conf);
    assertEquals("1 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, BUTTON_TWO)));
}
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 79 with DeckConfig

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

the class SchedV2Test method test_filt_keep_lrn_state.

@Test
public void test_filt_keep_lrn_state() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    // fail the card outside filtered deck
    Card c = getCard();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 10, 61 }));
    col.getDecks().save(conf);
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(CARD_TYPE_LRN, c.getQueue());
    assertEquals(QUEUE_TYPE_LRN, c.getType());
    assertEquals(3003, c.getLeft());
    col.getSched().answerCard(c, BUTTON_THREE);
    assertEquals(CARD_TYPE_LRN, c.getQueue());
    assertEquals(QUEUE_TYPE_LRN, c.getType());
    // create a dynamic deck and refresh it
    long did = addDynamicDeck("Cram");
    col.getSched().rebuildDyn(did);
    col.reset();
    // card should still be in learning state
    c.load();
    assertEquals(CARD_TYPE_LRN, c.getQueue());
    assertEquals(QUEUE_TYPE_LRN, c.getType());
    assertEquals(2002, c.getLeft());
    // should be able to advance learning steps
    col.getSched().answerCard(c, BUTTON_THREE);
    // should be due at least an hour in the future
    assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(60 * 60L)));
    // emptying the deck preserves learning state
    col.getSched().emptyDyn(did);
    c.load();
    assertEquals(CARD_TYPE_LRN, c.getQueue());
    assertEquals(QUEUE_TYPE_LRN, c.getType());
    assertEquals(1001, c.getLeft());
    assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(60 * 60L)));
}
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 80 with DeckConfig

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

the class SchedV2Test method test_nextIvlV2.

@Test
public void test_nextIvlV2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    col.reset();
    DeckConfig conf = col.getDecks().confForDid(1);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 0.5, 3, 10 }));
    conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 1, 5, 9 }));
    col.getDecks().save(conf);
    Card c = getCard();
    // new cards
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    assertEquals(30, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals((30 + 180) / 2, col.getSched().nextIvl(c, BUTTON_TWO));
    assertEquals(180, col.getSched().nextIvl(c, BUTTON_THREE));
    assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_FOUR));
    col.getSched().answerCard(c, BUTTON_ONE);
    // cards in learning
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    assertEquals(30, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals((30 + 180) / 2, col.getSched().nextIvl(c, BUTTON_TWO));
    assertEquals(180, col.getSched().nextIvl(c, BUTTON_THREE));
    assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_FOUR));
    col.getSched().answerCard(c, BUTTON_THREE);
    assertEquals(30, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals((180 + 600) / 2, col.getSched().nextIvl(c, BUTTON_TWO));
    assertEquals(600, col.getSched().nextIvl(c, BUTTON_THREE));
    assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_FOUR));
    col.getSched().answerCard(c, BUTTON_THREE);
    // normal graduation is tomorrow
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_THREE));
    assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_FOUR));
    // lapsed cards
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c.setType(CARD_TYPE_REV);
    c.setIvl(100);
    c.setFactor(STARTING_FACTOR);
    assertEquals(60, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(100 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_THREE));
    assertEquals(101 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_FOUR));
    // review cards
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c.setQueue(QUEUE_TYPE_REV);
    c.setIvl(100);
    c.setFactor(STARTING_FACTOR);
    // failing it should put it at 60s
    assertEquals(60, col.getSched().nextIvl(c, BUTTON_ONE));
    // or 1 day if relearn is false
    conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] {}));
    col.getDecks().save(conf);
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_ONE));
    // (* 100 1.2 SECONDS_PER_DAY)10368000.0
    assertEquals(10368000, col.getSched().nextIvl(c, BUTTON_TWO));
    // (* 100 2.5 SECONDS_PER_DAY)21600000.0
    assertEquals(21600000, col.getSched().nextIvl(c, BUTTON_THREE));
    // (* 100 2.5 1.3 SECONDS_PER_DAY)28080000.0
    assertEquals(28080000, col.getSched().nextIvl(c, BUTTON_FOUR));
    assertThat(without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, BUTTON_FOUR)), is("10.8 mo"));
}
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