Search in sources :

Example 51 with Counts

use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method test_bury.

@Test
public void test_bury() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    note = col.newNote();
    note.setItem("Front", "two");
    col.addNote(note);
    Card c2 = note.cards().get(0);
    // burying
    col.getSched().buryCards(new long[] { c.getId() }, true);
    c.load();
    assertEquals(QUEUE_TYPE_MANUALLY_BURIED, c.getQueue());
    col.getSched().buryCards(new long[] { c2.getId() }, false);
    c2.load();
    assertEquals(QUEUE_TYPE_SIBLING_BURIED, c2.getQueue());
    col.reset();
    assertNull(col.getSched().getCard());
    col.getSched().unburyCardsForDeck(AbstractSched.UnburyType.MANUAL);
    c.load();
    assertEquals(QUEUE_TYPE_NEW, c.getQueue());
    c2.load();
    assertEquals(QUEUE_TYPE_SIBLING_BURIED, c2.getQueue());
    col.getSched().unburyCardsForDeck(AbstractSched.UnburyType.SIBLINGS);
    c2.load();
    assertEquals(QUEUE_TYPE_NEW, c2.getQueue());
    col.getSched().buryCards(new long[] { c.getId(), c2.getId() });
    col.getSched().unburyCardsForDeck(AbstractSched.UnburyType.ALL);
    col.reset();
    assertArrayEquals(new int[] { 2, 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 52 with Counts

use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.

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();
    assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
    col.getSched().forgetCards(new long[] { c.getId() });
    col.reset();
    assertArrayEquals(new int[] { 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 53 with Counts

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

use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method test_repCountsV2.

@Test
public void test_repCountsV2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    col.reset();
    // lrnReps should be accurate on pass/fail
    assertArrayEquals(new int[] { 1, 0, 0 }, col.getSched().counts());
    col.getSched().answerCard(col.getSched().getCard(), 1);
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    col.getSched().answerCard(col.getSched().getCard(), 1);
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    col.getSched().answerCard(col.getSched().getCard(), 3);
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    col.getSched().answerCard(col.getSched().getCard(), 1);
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    col.getSched().answerCard(col.getSched().getCard(), 3);
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    col.getSched().answerCard(col.getSched().getCard(), 3);
    assertArrayEquals(new int[] { 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(col.getSched().getCard(), 3);
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    col.getSched().answerCard(col.getSched().getCard(), 1);
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    col.getSched().answerCard(col.getSched().getCard(), 4);
    assertArrayEquals(new int[] { 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(col.getSched().getCard(), 4);
    assertArrayEquals(new int[] { 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();
    assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
    col.getSched().answerCard(col.getSched().getCard(), 1);
    assertArrayEquals(new int[] { 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 55 with Counts

use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method test_deckFlowV2.

@Test
public void test_deckFlowV2() 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::2");
    note.model().put("did", default1);
    col.addNote(note);
    // and another that's higher up
    note = col.newNote();
    note.setItem("Front", "three");
    default1 = col.getDecks().id("Default::1");
    note.model().put("did", default1);
    col.addNote(note);
    // should get top level one first, then ::1, then ::2
    col.reset();
    assertArrayEquals(new int[] { 3, 0, 0 }, col.getSched().counts());
    for (String i : new String[] { "one", "three", "two" }) {
        Card c = col.getSched().getCard();
        assertEquals(i, c.note().getItem("Front"));
        col.getSched().answerCard(c, 3);
    }
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Matchers.containsString(org.hamcrest.Matchers.containsString) 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