Search in sources :

Example 11 with SECONDS_PER_DAY

use of com.ichi2.libanki.stats.Stats.SECONDS_PER_DAY in project AnkiChinaAndroid by ankichinateam.

the class FinderTest method test_findCards.

@Test
public void test_findCards() {
    Collection col = getCol();
    Note note = col.newNote();
    note.setItem("Front", "dog");
    note.setItem("Back", "cat");
    note.addTag("monkey animal_1 * %");
    col.addNote(note);
    long n1id = note.getId();
    long firstCardId = note.cards().get(0).getId();
    note = col.newNote();
    note.setItem("Front", "goats are fun");
    note.setItem("Back", "sheep");
    note.addTag("sheep goat horse animal11");
    col.addNote(note);
    long n2id = note.getId();
    note = col.newNote();
    note.setItem("Front", "cat");
    note.setItem("Back", "sheep");
    col.addNote(note);
    Card catCard = note.cards().get(0);
    Model m = col.getModels().current();
    m = col.getModels().copy(m);
    Models mm = col.getModels();
    JSONObject t = Models.newTemplate("Reverse");
    t.put("qfmt", "{{Back}}");
    t.put("afmt", "{{Front}}");
    mm.addTemplateModChanged(m, t);
    mm.save(m);
    note = col.newNote();
    note.setItem("Front", "test");
    note.setItem("Back", "foo bar");
    col.addNote(note);
    col.save();
    List<Long> latestCardIds = note.cids();
    // tag searches
    assertEquals(5, col.findCards("tag:*").size());
    assertEquals(1, col.findCards("tag:\\*").size());
    assertEquals(5, col.findCards("tag:%").size());
    assertEquals(1, col.findCards("tag:\\%").size());
    assertEquals(2, col.findCards("tag:animal_1").size());
    assertEquals(1, col.findCards("tag:animal\\_1").size());
    assertEquals(0, col.findCards("tag:donkey").size());
    assertEquals(1, col.findCards("tag:sheep").size());
    assertEquals(1, col.findCards("tag:sheep tag:goat").size());
    assertEquals(0, col.findCards("tag:sheep tag:monkey").size());
    assertEquals(1, col.findCards("tag:monkey").size());
    assertEquals(1, col.findCards("tag:sheep -tag:monkey").size());
    assertEquals(4, col.findCards("-tag:sheep").size());
    col.getTags().bulkAdd(col.getDb().queryLongList("select id from notes"), "foo bar");
    assertEquals(5, col.findCards("tag:foo").size());
    assertEquals(5, col.findCards("tag:bar").size());
    col.getTags().bulkRem(col.getDb().queryLongList("select id from notes"), "foo");
    assertEquals(0, col.findCards("tag:foo").size());
    assertEquals(5, col.findCards("tag:bar").size());
    // text searches
    assertEquals(2, col.findCards("cat").size());
    assertEquals(1, col.findCards("cat -dog").size());
    assertEquals(1, col.findCards("cat -dog").size());
    assertEquals(1, col.findCards("are goats").size());
    assertEquals(0, col.findCards("\"are goats\"").size());
    assertEquals(1, col.findCards("\"goats are\"").size());
    // card states
    Card c = note.cards().get(0);
    c.setQueue(QUEUE_TYPE_REV);
    c.setType(CARD_TYPE_REV);
    assertEquals(0, col.findCards("is:review").size());
    c.flush();
    assertEqualsArrayList((new Long[] { c.getId() }), col.findCards("is:review"));
    assertEquals(0, col.findCards("is:due").size());
    c.setDue(0);
    c.setQueue(QUEUE_TYPE_REV);
    c.flush();
    assertEqualsArrayList((new Long[] { c.getId() }), col.findCards("is:due"));
    assertEquals(4, col.findCards("-is:due").size());
    c.setQueue(QUEUE_TYPE_SUSPENDED);
    // ensure this card gets a later mod time
    c.flush();
    col.getDb().execute("update cards set mod = mod + 1 where id = ?", c.getId());
    assertEqualsArrayList((new Long[] { c.getId() }), col.findCards("is:suspended"));
    // nids
    assertEquals(0, col.findCards("nid:54321").size());
    assertEquals(2, col.findCards("nid:" + note.getId()).size());
    assertEquals(2, col.findCards("nid:" + n1id + "," + n2id).size());
    // templates
    assertEquals(0, col.findCards("card:foo").size());
    assertEquals(4, col.findCards("\"card:card 1\"").size());
    assertEquals(1, col.findCards("card:reverse").size());
    assertEquals(4, col.findCards("card:1").size());
    assertEquals(1, col.findCards("card:2").size());
    // fields
    assertEquals(1, col.findCards("front:dog").size());
    assertEquals(4, col.findCards("-front:dog").size());
    assertEquals(0, col.findCards("front:sheep").size());
    assertEquals(2, col.findCards("back:sheep").size());
    assertEquals(3, col.findCards("-back:sheep").size());
    assertEquals(0, col.findCards("front:do").size());
    assertEquals(5, col.findCards("front:*").size());
    // ordering
    col.getConf().put("sortType", "noteCrt");
    col.flush();
    assertTrue(latestCardIds.contains(getLastListElement(col.findCards("front:*", true))));
    assertTrue(latestCardIds.contains(getLastListElement(col.findCards("", true))));
    col.getConf().put("sortType", "noteFld");
    col.flush();
    assertEquals(catCard.getId(), (long) col.findCards("", true).get(0));
    assertTrue(latestCardIds.contains(getLastListElement(col.findCards("", true))));
    col.getConf().put("sortType", "cardMod");
    col.flush();
    assertTrue(latestCardIds.contains(getLastListElement(col.findCards("", true))));
    assertEquals(firstCardId, (long) col.findCards("", true).get(0));
    col.getConf().put("sortBackwards", true);
    col.flush();
    assertTrue(latestCardIds.contains(col.findCards("", true).get(0)));
    /* TODO: Port BuiltinSortKind
           assertEquals(firstCardId,
           col.findCards("", BuiltinSortKind.CARD_DUE, reverse=false).get(0)
           );
           assertNotEquals(firstCardId,
           col.findCards("", BuiltinSortKind.CARD_DUE, reverse=true).get(0));
        */
    // model
    assertEquals(3, col.findCards("note:basic").size());
    assertEquals(2, col.findCards("-note:basic").size());
    assertEquals(5, col.findCards("-note:foo").size());
    // col
    assertEquals(5, col.findCards("deck:default").size());
    assertEquals(0, col.findCards("-deck:default").size());
    assertEquals(5, col.findCards("-deck:foo").size());
    assertEquals(5, col.findCards("deck:def*").size());
    assertEquals(5, col.findCards("deck:*EFAULT").size());
    assertEquals(0, col.findCards("deck:*cefault").size());
    // full search
    note = col.newNote();
    note.setItem("Front", "hello<b>world</b>");
    note.setItem("Back", "abc");
    col.addNote(note);
    // as it's the sort field, it matches
    assertEquals(2, col.findCards("helloworld").size());
    // assertEquals(, col.findCards("helloworld", full=true).size())2 This is commented upstream
    // if we put it on the back, it won't
    String note_front = note.getItem("Front");
    String note_back = note.getItem("Back");
    note.setItem("Front", note_back);
    note.setItem("Back", note_front);
    note.flush();
    assertEquals(0, col.findCards("helloworld").size());
    //  Those lines are commented above
    // assertEquals(, col.findCards("helloworld", full=true).size())2
    // assertEquals(, col.findCards("back:helloworld", full=true).size())2
    // searching for an invalid special tag should not error
    // TODO: ensure the search fail
    // assertThrows(Exception.class, () -> col.findCards("is:invalid").size());
    // should be able to limit to parent col, no children
    long id = col.getDb().queryLongScalar("select id from cards limit 1");
    col.getDb().execute("update cards set did = ? where id = ?", col.getDecks().id("Default::Child"), id);
    col.save();
    assertEquals(7, col.findCards("deck:default").size());
    assertEquals(1, col.findCards("deck:default::child").size());
    assertEquals(6, col.findCards("deck:default -deck:default::*").size());
    // properties
    id = col.getDb().queryLongScalar("select id from cards limit 1");
    col.getDb().execute("update cards set queue=2, ivl=10, reps=20, due=30, factor=2200 where id = ?", id);
    assertEquals(1, col.findCards("prop:ivl>5").size());
    assertThat(col.findCards("prop:ivl<5").size(), greaterThan(1));
    assertEquals(1, col.findCards("prop:ivl>=5").size());
    assertEquals(0, col.findCards("prop:ivl=9").size());
    assertEquals(1, col.findCards("prop:ivl=10").size());
    assertThat(col.findCards("prop:ivl!=10").size(), greaterThan(1));
    assertEquals(1, col.findCards("prop:due>0").size());
    // due dates should work
    assertEquals(0, col.findCards("prop:due=29").size());
    assertEquals(1, col.findCards("prop:due=30").size());
    // ease factors
    assertEquals(0, col.findCards("prop:ease=2.3").size());
    assertEquals(1, col.findCards("prop:ease=2.2").size());
    assertEquals(1, col.findCards("prop:ease>2").size());
    assertThat(col.findCards("-prop:ease>2").size(), greaterThan(1));
    // recently failed
    if (!isNearCutoff(col)) {
        assertEquals(0, col.findCards("rated:1:1").size());
        assertEquals(0, col.findCards("rated:1:2").size());
        c = col.getSched().getCard();
        col.getSched().answerCard(c, 2);
        assertEquals(0, col.findCards("rated:1:1").size());
        assertEquals(1, col.findCards("rated:1:2").size());
        c = col.getSched().getCard();
        col.getSched().answerCard(c, 1);
        assertEquals(1, col.findCards("rated:1:1").size());
        assertEquals(1, col.findCards("rated:1:2").size());
        assertEquals(2, col.findCards("rated:1").size());
        assertEquals(0, col.findCards("rated:0:2").size());
        assertEquals(1, col.findCards("rated:2:2").size());
        // added
        assertEquals(0, col.findCards("added:0").size());
        col.getDb().execute("update cards set id = id - " + SECONDS_PER_DAY * 1000 + " where id = ?", id);
        assertEquals(col.cardCount() - 1, col.findCards("added:1").size());
        assertEquals(col.cardCount(), col.findCards("added:2").size());
    } else {
        Timber.w("some find tests disabled near cutoff");
    }
    // empty field
    assertEquals(0, col.findCards("front:").size());
    note = col.newNote();
    note.setItem("Front", "");
    note.setItem("Back", "abc2");
    assertEquals(1, col.addNote(note));
    assertEquals(1, col.findCards("front:").size());
    // OR searches and nesting
    assertEquals(2, col.findCards("tag:monkey or tag:sheep").size());
    assertEquals(2, col.findCards("(tag:monkey OR tag:sheep)").size());
    assertEquals(6, col.findCards("-(tag:monkey OR tag:sheep)").size());
    assertEquals(2, col.findCards("tag:monkey or (tag:sheep sheep)").size());
    assertEquals(1, col.findCards("tag:monkey or (tag:sheep octopus)").size());
// flag
// Todo: ensure it fails
// assertThrows(Exception.class, () -> col.findCards("flag:12"));
}
Also used : JSONObject(com.ichi2.utils.JSONObject) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 12 with SECONDS_PER_DAY

use of com.ichi2.libanki.stats.Stats.SECONDS_PER_DAY in project AnkiChinaAndroid by ankichinateam.

the class SchedTest method test_cram.

@Test
public void test_cram() throws Exception {
    Collection col = getColV1();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    c.setIvl(100);
    c.setQueue(CARD_TYPE_REV);
    c.setType(QUEUE_TYPE_REV);
    // due in 25 days, so it's been waiting 75 days
    c.setDue(col.getSched().getToday() + 25);
    c.setMod(1);
    c.setFactor(STARTING_FACTOR);
    c.startTimer();
    c.flush();
    col.reset();
    assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
    Card cardcopy = c.clone();
    // create a dynamic deck and refresh it
    long did = col.getDecks().newDyn("Cram");
    col.getSched().rebuildDyn(did);
    col.reset();
    // should appear as new in the deck list
    // todo: which sort
    // and should appear in the counts
    assertArrayEquals(new int[] { 1, 0, 0 }, col.getSched().counts());
    // grab it and check estimates
    c = col.getSched().getCard();
    assertEquals(2, col.getSched().answerButtons(c));
    assertEquals(600, col.getSched().nextIvl(c, 1));
    assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, 2));
    Deck cram = col.getDecks().get(did);
    cram.put("delays", new JSONArray(new double[] { 1, 10 }));
    col.getDecks().save(cram);
    assertEquals(3, col.getSched().answerButtons(c));
    assertEquals(60, col.getSched().nextIvl(c, 1));
    assertEquals(600, col.getSched().nextIvl(c, 2));
    assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, 3));
    col.getSched().answerCard(c, 2);
    // elapsed time was 75 days
    // factor = 2.5+1.2/2 = 1.85
    // int(75*1.85) = 138
    assertEquals(138, c.getIvl());
    assertEquals(138, c.getODue());
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    // should be logged as a cram rep
    assertEquals(3, col.getDb().queryLongScalar("select type from revlog order by id desc limit 1"));
    // check ivls again
    assertEquals(60, col.getSched().nextIvl(c, 1));
    assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, 2));
    assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, 3));
    // when it graduates, due is updated
    c = col.getSched().getCard();
    col.getSched().answerCard(c, 2);
    assertEquals(138, c.getIvl());
    assertEquals(138, c.getDue());
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    // and it will have moved back to the previous deck
    assertEquals(1, c.getDid());
    // cram the deck again
    col.getSched().rebuildDyn(did);
    col.reset();
    c = col.getSched().getCard();
    // check ivls again - passing should be idempotent
    assertEquals(60, col.getSched().nextIvl(c, 1));
    assertEquals(600, col.getSched().nextIvl(c, 2));
    assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, 3));
    col.getSched().answerCard(c, 2);
    assertEquals(138, c.getIvl());
    assertEquals(138, c.getODue());
    // fail
    col.getSched().answerCard(c, 1);
    assertEquals(60, col.getSched().nextIvl(c, 1));
    assertEquals(600, col.getSched().nextIvl(c, 2));
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
    // delete the deck, returning the card mid-study
    col.getDecks().rem(col.getDecks().selected());
    assertEquals(1, col.getSched().deckDueTree().size());
    c.load();
    assertEquals(1, c.getIvl());
    assertEquals(col.getSched().getToday() + 1, c.getDue());
    // make it due
    col.reset();
    assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
    c.setDue(-5);
    c.setIvl(100);
    c.flush();
    col.reset();
    assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
    // cram again
    did = col.getDecks().newDyn("Cram");
    col.getSched().rebuildDyn(did);
    col.reset();
    assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
    c.load();
    assertEquals(4, col.getSched().answerButtons(c));
    // add a sibling so we can test minSpace, etc
    Card c2 = c.clone();
    c2.setId(0);
    c2.setOrd(1);
    c2.setDue(325);
    c2.flush();
    // should be able to answer it
    c = col.getSched().getCard();
    col.getSched().answerCard(c, 4);
    // it should have been moved back to the original deck
    assertEquals(1, c.getDid());
}
Also used : Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 13 with SECONDS_PER_DAY

use of com.ichi2.libanki.stats.Stats.SECONDS_PER_DAY in project AnkiChinaAndroid by ankichinateam.

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 = col.getSched().getCard();
    // new cards
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    assertEquals(30, col.getSched().nextIvl(c, 1));
    assertEquals((30 + 180) / 2, col.getSched().nextIvl(c, 2));
    assertEquals(180, col.getSched().nextIvl(c, 3));
    assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
    col.getSched().answerCard(c, 1);
    // cards in learning
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    assertEquals(30, col.getSched().nextIvl(c, 1));
    assertEquals((30 + 180) / 2, col.getSched().nextIvl(c, 2));
    assertEquals(180, col.getSched().nextIvl(c, 3));
    assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
    col.getSched().answerCard(c, 3);
    assertEquals(30, col.getSched().nextIvl(c, 1));
    assertEquals((180 + 600) / 2, col.getSched().nextIvl(c, 2));
    assertEquals(600, col.getSched().nextIvl(c, 3));
    assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
    col.getSched().answerCard(c, 3);
    // normal graduation is tomorrow
    assertEquals(1 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
    assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
    // lapsed cards
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c.setType(CARD_TYPE_REV);
    c.setIvl(100);
    c.setFactor(STARTING_FACTOR);
    assertEquals(60, col.getSched().nextIvl(c, 1));
    assertEquals(100 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
    assertEquals(101 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
    // 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, 1));
    // or 1 day if relearn is false
    conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] {}));
    col.getDecks().save(conf);
    assertEquals(1 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 1));
    // (* 100 1.2 SECONDS_PER_DAY)10368000.0
    assertEquals(10368000, col.getSched().nextIvl(c, 2));
    // (* 100 2.5 SECONDS_PER_DAY)21600000.0
    assertEquals(21600000, col.getSched().nextIvl(c, 3));
    // (* 100 2.5 1.3 SECONDS_PER_DAY)28080000.0
    assertEquals(28080000, col.getSched().nextIvl(c, 4));
    assertThat(without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 4)), 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)

Example 14 with SECONDS_PER_DAY

use of com.ichi2.libanki.stats.Stats.SECONDS_PER_DAY in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method test_learn_dayV2.

@Test
public void test_learn_dayV2() throws Exception {
    Collection col = getColV2();
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    col.reset();
    Card c = col.getSched().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, 3);
    // two reps to graduate, 1 more today
    assertEquals(3, c.getLeft() % 1000);
    assertEquals(1, c.getLeft() / 1000);
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    c = col.getSched().getCard();
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
    // answering it will place it in queue 3
    col.getSched().answerCard(c, 3);
    assertEquals(col.getSched().getToday() + 1, c.getDue());
    assertEquals(QUEUE_TYPE_DAY_LEARN_RELEARN, c.getQueue());
    assertNull(col.getSched().getCard());
    // for testing, move it back a day
    c.setDue(c.getDue() - 1);
    c.flush();
    col.reset();
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    c = col.getSched().getCard();
    // nextIvl should work
    assertEquals(SECONDS_PER_DAY * 2, col.getSched().nextIvl(c, 3));
    // if we fail it, it should be back in the correct queue
    col.getSched().answerCard(c, 1);
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    col.undo();
    col.reset();
    c = col.getSched().getCard();
    col.getSched().answerCard(c, 3);
    // 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, 3));
    col.getSched().answerCard(c, 3);
    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();
    assertArrayEquals(new int[] { 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 = col.getSched().getCard();
    col.getSched().answerCard(c, 1);
    assertEquals(QUEUE_TYPE_DAY_LEARN_RELEARN, c.getQueue());
    assertArrayEquals(new int[] { 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)

Example 15 with SECONDS_PER_DAY

use of com.ichi2.libanki.stats.Stats.SECONDS_PER_DAY 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

RobolectricTest (com.ichi2.anki.RobolectricTest)14 Test (org.junit.Test)14 Card (com.ichi2.libanki.Card)12 Collection (com.ichi2.libanki.Collection)12 Note (com.ichi2.libanki.Note)12 JSONArray (com.ichi2.utils.JSONArray)10 DeckConfig (com.ichi2.libanki.DeckConfig)8 JSONObject (com.ichi2.utils.JSONObject)6 Deck (com.ichi2.libanki.Deck)4