Search in sources :

Example 16 with DeckDueTreeNode

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

the class DeckDueTreeNode method setChildren.

public void setChildren(@NonNull List<DeckDueTreeNode> children, boolean addRev) {
    super.setChildren(children, addRev);
    // tally up children counts
    for (DeckDueTreeNode ch : children) {
        mLrnCount += ch.getLrnCount();
        mNewCount += ch.getNewCount();
        if (addRev) {
            mRevCount += ch.getRevCount();
        }
    }
    // limit the counts to the deck's limits
    JSONObject conf = getCol().getDecks().confForDid(getDid());
    if (conf.getInt("dyn") == 0) {
        JSONObject deck = getCol().getDecks().get(getDid());
        limitNewCount(conf.getJSONObject("new").getInt("perDay") - deck.getJSONArray("newToday").getInt(1));
        if (addRev) {
            limitRevCount(conf.getJSONObject("rev").getInt("perDay") - deck.getJSONArray("revToday").getInt(1));
        }
    }
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Example 17 with DeckDueTreeNode

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

the class SchedTest method learnCardsAreNotFiltered.

@Test
public void learnCardsAreNotFiltered() {
    // Replicates Anki commit: 13c54e02d8fd2b35f6c2f4b796fc44dec65043b8
    addNoteUsingBasicModel("Hello", "World");
    Sched sched = new Sched(getCol());
    markNextCardAsGood(sched);
    long dynDeck = addDynamicDeck("Hello");
    // Act
    sched.rebuildDyn(dynDeck);
    // Assert
    DeckDueTreeNode dynamicDeck = getCountsForDid(dynDeck);
    assertThat("A learn card should not be moved into a dyn deck", dynamicDeck.getLrnCount(), is(0));
    assertThat("A learn card should not be moved into a dyn deck", dynamicDeck.getNewCount(), is(0));
    assertThat("A learn card should not be moved into a dyn deck", dynamicDeck.getRevCount(), is(0));
}
Also used : DeckDueTreeNode(com.ichi2.libanki.sched.DeckDueTreeNode) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 18 with DeckDueTreeNode

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

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 = addDeck("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", addDeck("foo::bar"));
    col.addNote(note);
    // and one that's a sibling
    note = col.newNote();
    note.setItem("Front", "three");
    note.model().put("did", addDeck("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 19 with DeckDueTreeNode

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

the class SchedV2Test method test_deckTree.

@Test
public void test_deckTree() throws Exception {
    Collection col = getColV2();
    addDeck("new::b::c");
    addDeck("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 20 with DeckDueTreeNode

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

the class SchedV2Test method ensureDeckTree.

@Test
public void ensureDeckTree() {
    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)

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