Search in sources :

Example 16 with Counts

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

the class SchedV2Test method test_forgetV2.

@Test
public void test_forgetV2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    c.setQueue(QUEUE_TYPE_REV);
    c.setType(CARD_TYPE_REV);
    c.setIvl(100);
    c.setDue(0);
    c.flush();
    col.reset();
    assertEquals(new Counts(0, 0, 1), col.getSched().counts());
    col.getSched().forgetCards(Collections.singletonList(c.getId()));
    col.reset();
    assertEquals(new Counts(1, 0, 0), col.getSched().counts());
}
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 17 with Counts

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

the class SchedTest method test_repCountsV1.

@Test
public void test_repCountsV1() throws Exception {
    Collection col = getColV1();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    col.reset();
    // lrnReps should be accurate on pass/fail
    assertEquals(new Counts(1, 0, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_ONE);
    assertEquals(new Counts(0, 2, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_ONE);
    assertEquals(new Counts(0, 2, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_TWO);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_ONE);
    assertEquals(new Counts(0, 2, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_TWO);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_TWO);
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    note = col.newNote();
    note.setItem("Front", "two");
    col.addNote(note);
    col.reset();
    // initial pass should be correct too
    col.getSched().answerCard(getCard(), BUTTON_TWO);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_ONE);
    assertEquals(new Counts(0, 2, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_THREE);
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    // immediate graduate should work
    note = col.newNote();
    note.setItem("Front", "three");
    col.addNote(note);
    col.reset();
    col.getSched().answerCard(getCard(), BUTTON_THREE);
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    // and failing a review should too
    note = col.newNote();
    note.setItem("Front", "three");
    col.addNote(note);
    Card c = note.cards().get(0);
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setDue(col.getSched().getToday());
    c.flush();
    col.reset();
    assertEquals(new Counts(0, 0, 1), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_ONE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
}
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 18 with Counts

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

the class SchedTest method test_new_v1.

public void test_new_v1() throws Exception {
    Collection col = getColV1();
    col.reset();
    assertEquals(0, col.getSched().newCount());
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    col.reset();
    assertEquals(1, col.getSched().counts().getNew());
    // fetch it
    Card c = getCard();
    assertNotNull(c);
    assertEquals(QUEUE_TYPE_NEW, c.getQueue());
    assertEquals(CARD_TYPE_NEW, c.getType());
    // if we answer it, it should become a learn card
    long t = col.getTime().intTime();
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    assertEquals(CARD_TYPE_LRN, c.getType());
    assertThat(c.getDue(), is(greaterThanOrEqualTo(t)));
// disabled for now, as the learn fudging makes this randomly fail
// // the default order should ensure siblings are not seen together, and
// // should show all cards
// Model m = col.getModels().current(); Models mm = col.getModels()
// JSONObject t = mm.newTemplate("Reverse")
// t['qfmt'] = "{{Back}}"
// t['afmt'] = "{{Front}}"
// mm.addTemplateModChanged(m, t)
// mm.save(m)
// note = col.newNote()
// note['Front'] = u"2"; note['Back'] = u"2"
// col.addNote(note)
// note = col.newNote()
// note['Front'] = u"3"; note['Back'] = u"3"
// col.addNote(note)
// col.reset()
// qs = ("2", "3", "2", "3")
// for (int n = 0; n < 4; n++) {
// c = getCard()
// assertTrue(qs[n] in c.q())
// col.getSched().answerCard(c, 2)
// }
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card)

Example 19 with Counts

use of com.ichi2.libanki.sched.Counts 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 20 with Counts

use of com.ichi2.libanki.sched.Counts 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

Collection (com.ichi2.libanki.Collection)47 Card (com.ichi2.libanki.Card)43 Test (org.junit.Test)39 RobolectricTest (com.ichi2.anki.RobolectricTest)38 Note (com.ichi2.libanki.Note)38 Deck (com.ichi2.libanki.Deck)12 DeckConfig (com.ichi2.libanki.DeckConfig)11 JSONArray (com.ichi2.utils.JSONArray)11 JSONObject (com.ichi2.utils.JSONObject)10 JSONException (com.ichi2.utils.JSONException)6 HashMap (java.util.HashMap)6 Resources (android.content.res.Resources)4 Nullable (androidx.annotation.Nullable)4 Model (com.ichi2.libanki.Model)4 AbstractDeckTreeNode (com.ichi2.libanki.sched.AbstractDeckTreeNode)4 IOException (java.io.IOException)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 JSONObject (org.json.JSONObject)4 Cursor (android.database.Cursor)3 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)3