Search in sources :

Example 96 with CARD

use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method test_timingV2.

@Test
public void test_timingV2() throws Exception {
    Collection col = getColV2();
    // add a few review cards, due today
    for (int i = 0; i < 5; i++) {
        Note note = col.newNote();
        note.setItem("Front", "num" + i);
        col.addNote(note);
        Card c = note.cards().get(0);
        c.setType(CARD_TYPE_REV);
        c.setQueue(QUEUE_TYPE_REV);
        c.setDue(0);
        c.flush();
    }
    // fail the first one
    col.reset();
    Card c = col.getSched().getCard();
    col.getSched().answerCard(c, 1);
    // the next card should be another review
    Card c2 = col.getSched().getCard();
    assertEquals(QUEUE_TYPE_REV, c2.getQueue());
    // if the failed card becomes due, it should show first
    c.setDue(col.getTime().intTime() - 1);
    c.flush();
    col.reset();
    c = col.getSched().getCard();
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
}
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)

Example 97 with CARD

use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method test_reschedV2.

@Test
public void test_reschedV2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    col.getSched().reschedCards(new long[] { c.getId() }, 0, 0);
    c.load();
    assertEquals(col.getSched().getToday(), c.getDue());
    assertEquals(1, c.getIvl());
    assertEquals(QUEUE_TYPE_REV, c.getType());
    assertEquals(CARD_TYPE_REV, c.getQueue());
    col.getSched().reschedCards(new long[] { c.getId() }, 1, 1);
    c.load();
    assertEquals(col.getSched().getToday() + 1, c.getDue());
    assertEquals(+1, c.getIvl());
}
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)

Example 98 with CARD

use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.

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(CARD_TYPE_REV);
    c.setType(QUEUE_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 = col.getSched().getCard();
    col.getSched().answerCard(c, 1);
    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 99 with CARD

use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method test_deckDueV2.

@Test
public void test_deckDueV2() throws Exception {
    Collection col = getColV2();
    // add a note with default deck
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    // and one that's a child
    note = col.newNote();
    note.setItem("Front", "two");
    long default1 = col.getDecks().id("Default::1");
    note.model().put("did", default1);
    col.addNote(note);
    // make it a review card
    Card c = note.cards().get(0);
    c.setQueue(QUEUE_TYPE_REV);
    c.setDue(0);
    c.flush();
    // add one more with a new deck
    note = col.newNote();
    note.setItem("Front", "two");
    note.model().put("did", col.getDecks().id("foo::bar"));
    col.addNote(note);
    // and one that's a sibling
    note = col.newNote();
    note.setItem("Front", "three");
    note.model().put("did", col.getDecks().id("foo::baz"));
    col.addNote(note);
    col.reset();
    assertEquals(5, col.getDecks().allSortedNames().size());
    DeckDueTreeNode tree = col.getSched().deckDueTree().get(0);
    assertEquals("Default", tree.getLastDeckNameComponent());
    // sum of child and parent
    assertEquals(1, tree.getDid());
    assertEquals(1, tree.getRevCount());
    assertEquals(1, tree.getNewCount());
    // child count is just review
    DeckDueTreeNode child = tree.getChildren().get(0);
    assertEquals("1", child.getLastDeckNameComponent());
    assertEquals(default1, child.getDid());
    assertEquals(1, child.getRevCount());
    assertEquals(0, child.getNewCount());
    // code should not fail if a card has an invalid deck
    c.setDid(12345);
    c.flush();
    col.getSched().deckDueTree();
}
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)

Example 100 with CARD

use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method filteredDeckSchedulingOptionsRegressionTest.

/**
 * Reported by /u/CarelessSecretary9 on reddit:
 */
@Test
public void filteredDeckSchedulingOptionsRegressionTest() {
    Collection col = getCol();
    col.setCrt(1587852900L);
    // 30 minutes learn ahead. required as we have 20m delay
    col.getConf().put("collapseTime", 1800);
    long homeDeckId = addDeck("Poorretention");
    DeckConfig homeDeckConf = col.getDecks().confForDid(homeDeckId);
    JSONObject lapse = homeDeckConf.getJSONObject("lapse");
    lapse.put("minInt", 2);
    lapse.put("mult", 0.7d);
    lapse.put("delays", new JSONArray("[20]"));
    ensureLapseMatchesSppliedAnkiDesktopConfig(lapse);
    col.flush();
    long dynId = addDynamicDeck("Dyn");
    /*
        >>> pp(self.reviewer.card)
        {'data': '', 'did': 1587939535230, 'due': 0, 'factor': 1300, 'flags': 0, 'id': 1510928829863, 'ivl': 25,
        'lapses': 5, 'left': 1004, 'mod': 1587921512, 'nid': 1510928805161, 'odid': 1587920944107,
        'odue': 0, 'ord': 0, 'queue': 2, 'reps': 22, 'type': 2, 'usn': -1}

         */
    Note n = addNoteUsingBasicModel("Hello", "World");
    Card c = getOnlyElement(n.cards());
    c.setType(Consts.CARD_TYPE_REV);
    c.setQueue(Consts.QUEUE_TYPE_REV);
    c.setIvl(25);
    c.setDue(0);
    c.setLapses(5);
    c.setFactor(1300);
    c.setLeft(1004);
    c.setODid(homeDeckId);
    c.setDid(dynId);
    c.flush();
    SchedV2 v2 = new SchedV2(col);
    Card schedCard = v2.getCard();
    assertThat(schedCard, Matchers.notNullValue());
    v2.answerCard(schedCard, Consts.BUTTON_ONE);
    assertThat("The lapsed card should now be counted as lrn", v2.mLrnCount, is(1));
    Card after = v2.getCard();
    assertThat("A card should be returned ", after, Matchers.notNullValue());
    /* Data from Anki - pp(self.reviewer.card)
        {'data': '', 'did': 1587939535230, 'due': 1587941137, 'factor': 1300,
        'flags': 0, 'id': 1510928829863, 'ivl': 17, 'lapses': 6, 'left': 1001,
        'mod': 1587939720, 'nid': 1510928805161, 'odid': 1587920944107, 'odue': 0,
        'ord': 0, 'queue': 1, 'reps': 23, 'type': 3, 'usn': -1}
         */
    assertThat(after.getType(), is(Consts.CARD_TYPE_RELEARNING));
    assertThat(after.getQueue(), is(Consts.QUEUE_TYPE_LRN));
    assertThat(after.getLeft(), is(1001));
    assertThat("ivl is reduced by 70%", after.getIvl(), is(17));
    assertThat("One lapse is added", after.getLapses(), is(6));
    assertThat(v2.answerButtons(after), is(4));
    long one = v2.nextIvl(after, Consts.BUTTON_ONE);
    long two = v2.nextIvl(after, Consts.BUTTON_TWO);
    long three = v2.nextIvl(after, Consts.BUTTON_THREE);
    long four = v2.nextIvl(after, Consts.BUTTON_FOUR);
    // 20 mins
    assertThat("Again should pick the current step", one, is(1200L));
    // 30 mins
    assertThat("Repeating single step - 20 minutes * 1.5", two, is(1800L));
    // 17 days
    assertThat("Good should take the reduced interval (25 * 0.7)", three, is(1468800L));
    // 18 days
    assertThat("Easy should have a bonus day over good", four, is(1555200L));
}
Also used : JSONObject(com.ichi2.utils.JSONObject) 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

Card (com.ichi2.libanki.Card)222 Test (org.junit.Test)212 Collection (com.ichi2.libanki.Collection)179 Note (com.ichi2.libanki.Note)173 RobolectricTest (com.ichi2.anki.RobolectricTest)168 JSONObject (com.ichi2.utils.JSONObject)114 JSONArray (com.ichi2.utils.JSONArray)80 DeckConfig (com.ichi2.libanki.DeckConfig)72 ArrayList (java.util.ArrayList)48 NonNull (androidx.annotation.NonNull)33 Deck (com.ichi2.libanki.Deck)32 Intent (android.content.Intent)29 JSONException (com.ichi2.utils.JSONException)27 Model (com.ichi2.libanki.Model)26 Context (android.content.Context)23 SuppressLint (android.annotation.SuppressLint)22 Cursor (android.database.Cursor)22 HashMap (java.util.HashMap)21 Matchers.containsString (org.hamcrest.Matchers.containsString)20 List (java.util.List)17