Search in sources :

Example 6 with DeckDueTreeNode

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

the class SchedV2Test method test_review_limits.

@Test
public void test_review_limits() throws Exception {
    Collection col = getColV2();
    Deck parent = col.getDecks().get(col.getDecks().id("parent"));
    Deck child = col.getDecks().get(col.getDecks().id("parent::child"));
    DeckConfig pconf = col.getDecks().getConf(col.getDecks().confId("parentConf"));
    DeckConfig cconf = col.getDecks().getConf(col.getDecks().confId("childConf"));
    pconf.getJSONObject("rev").put("perDay", 5);
    col.getDecks().updateConf(pconf);
    col.getDecks().setConf(parent, pconf.getLong("id"));
    cconf.getJSONObject("rev").put("perDay", 10);
    col.getDecks().updateConf(cconf);
    col.getDecks().setConf(child, cconf.getLong("id"));
    Model m = col.getModels().current();
    m.put("did", child.getLong("id"));
    col.getModels().save(m, false);
    // add some cards
    for (int i = 0; i < 20; i++) {
        Note note = col.newNote();
        note.setItem("Front", "one");
        note.setItem("Back", "two");
        col.addNote(note);
        // make them reviews
        Card c = note.cards().get(0);
        c.setQueue(CARD_TYPE_REV);
        c.setType(QUEUE_TYPE_REV);
        c.setDue(0);
        c.flush();
    }
    // position 0 is default deck. Different from upstream
    DeckDueTreeNode tree = col.getSched().deckDueTree().get(1);
    // (('parent', 1514457677462, 5, 0, 0, (('child', 1514457677463, 5, 0, 0, ()),)))
    assertEquals("parent", tree.getFullDeckName());
    // paren, tree.review_count)t
    assertEquals(5, tree.getRevCount());
    assertEquals(5, tree.getChildren().get(0).getRevCount());
    // .counts() should match
    col.getDecks().select(child.getLong("id"));
    col.reset();
    assertArrayEquals(new int[] { 0, 0, 5 }, col.getSched().counts());
    // answering a card in the child should decrement parent count
    Card c = col.getSched().getCard();
    col.getSched().answerCard(c, 3);
    assertArrayEquals(new int[] { 0, 0, 4 }, col.getSched().counts());
    tree = col.getSched().deckDueTree().get(1);
    assertEquals(4, tree.getRevCount());
    assertEquals(4, tree.getChildren().get(0).getRevCount());
}
Also used : Note(com.ichi2.libanki.Note) Model(com.ichi2.libanki.Model) Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 7 with DeckDueTreeNode

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

the class SchedV2Test method ensureDeckTree.

@Test
public void ensureDeckTree() throws Exception {
    for (String deckName : TEST_DECKS) {
        addDeck(deckName);
    }
    AbstractSched sched = getCol().getSched();
    List<DeckDueTreeNode> tree = sched.deckDueTree();
    Assert.assertEquals("Tree has not the expected structure", expectedTree(getCol(), true), tree);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 8 with DeckDueTreeNode

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

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

the class SchedV2Test method test_deckTree.

@Test
public void test_deckTree() throws Exception {
    Collection col = getColV2();
    col.getDecks().id("new::b::c");
    col.getDecks().id("new2");
    // new should not appear twice in tree
    List<String> names = new ArrayList<>();
    for (DeckDueTreeNode tree : col.getSched().deckDueTree()) {
        names.add(tree.getLastDeckNameComponent());
    }
    names.remove("new");
    assertFalse(names.contains("new"));
}
Also used : ArrayList(java.util.ArrayList) Collection(com.ichi2.libanki.Collection) Matchers.containsString(org.hamcrest.Matchers.containsString) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 10 with DeckDueTreeNode

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

the class SchedTest method ensureDeckTree.

@Test
public void ensureDeckTree() {
    for (String deckName : TEST_DECKS) {
        addDeck(deckName);
    }
    getCol().getSched().deckDueTree();
    AbstractSched sched = getCol().getSched();
    List<DeckDueTreeNode> tree = sched.deckDueTree();
    Assert.assertEquals("Tree has not the expected structure", SchedV2Test.expectedTree(getCol(), false), tree);
}
Also used : DeckDueTreeNode(com.ichi2.libanki.sched.DeckDueTreeNode) Matchers.containsString(org.hamcrest.Matchers.containsString) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

RobolectricTest (com.ichi2.anki.RobolectricTest)13 Test (org.junit.Test)13 Collection (com.ichi2.libanki.Collection)11 ArrayList (java.util.ArrayList)9 Card (com.ichi2.libanki.Card)8 Note (com.ichi2.libanki.Note)8 DeckDueTreeNode (com.ichi2.libanki.sched.DeckDueTreeNode)7 Deck (com.ichi2.libanki.Deck)6 JSONObject (com.ichi2.utils.JSONObject)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 Nullable (androidx.annotation.Nullable)5 Model (com.ichi2.libanki.Model)4 JSONArray (com.ichi2.utils.JSONArray)4 MatrixCursor (android.database.MatrixCursor)2 DeckConfig (com.ichi2.libanki.DeckConfig)2 JSONException (com.ichi2.utils.JSONException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 AlarmManager (android.app.AlarmManager)1 Notification (android.app.Notification)1