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());
}
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);
}
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();
}
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"));
}
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);
}
Aggregations