use of com.ichi2.libanki.Deck in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_deckDueV1.
@Test
public void test_deckDueV1() throws Exception {
Collection col = getColV1();
// 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");
JSONObject foobar = 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");
JSONObject foobaz = 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.Deck in project AnkiChinaAndroid by ankichinateam.
the class CardBrowserTest method changeDeckIntegrationTestDynamicAndNon.
@Test
public void changeDeckIntegrationTestDynamicAndNon() {
addDeck("Hello");
addDynamicDeck("World");
HashSet<String> validNames = new HashSet<>();
validNames.add("Default");
validNames.add("Hello");
CardBrowser b = getBrowserWithNotes(5);
List<Deck> decks = b.getValidDecksForChangeDeck();
for (Deck d : decks) {
assertThat(validNames, hasItem(d.getString("name")));
}
assertThat("Additional unexpected decks were present", decks.size(), is(2));
}
use of com.ichi2.libanki.Deck in project AnkiChinaAndroid by ankichinateam.
the class DecksTest method duplicateName.
@Test
public void duplicateName() {
Decks decks = getCol().getDecks();
decks.load("{2: {\"name\": \"A\", \"id\":2}, 3: {\"name\": \"A\", \"id\":3}, 4: {\"name\": \"A::B\", \"id\":4}}", "{}");
decks.checkIntegrity();
JSONObject deckA = decks.byName("A");
Asserts.notNull(deckA, "A deck with name \"A\" should still exists");
assertThat("A deck with name \"A\" should have name \"A\"", deckA.getString("name"), is("A"));
JSONObject deckAPlus = decks.byName("A+");
Asserts.notNull(deckAPlus, "A deck with name \"A+\" should still exists");
}
use of com.ichi2.libanki.Deck in project AnkiChinaAndroid by ankichinateam.
the class DecksTest method test_rename.
@Test
public void test_rename() throws DeckRenameException {
Collection col = getCol();
long id = col.getDecks().id("hello::world");
// should be able to rename into a completely different branch, creating
// parents as necessary
col.getDecks().rename(col.getDecks().get(id), "foo::bar");
List<String> names = col.getDecks().allSortedNames();
assertTrue(names.contains("foo"));
assertTrue(names.contains("foo::bar"));
assertFalse(names.contains("hello::world"));
// create another col
id = col.getDecks().id("tmp");
/* TODO: do we want to follow upstream here ?
// automatically adjusted if a duplicate name
col.getDecks().rename(col.getDecks().get(id), "FOO");
names = col.getDecks().allSortedNames();
assertThat(names, containsString("FOO+"));
*/
// when renaming, the children should be renamed too
col.getDecks().id("one::two::three");
id = col.getDecks().id("one");
col.getDecks().rename(col.getDecks().get(id), "yo");
names = col.getDecks().allSortedNames();
for (String n : new String[] { "yo", "yo::two", "yo::two::three" }) {
assertTrue(names.contains(n));
}
// over filtered
long filteredId = col.getDecks().newDyn("filtered");
Deck filtered = col.getDecks().get(filteredId);
long childId = col.getDecks().id("child");
Deck child = col.getDecks().get(childId);
assertThrows(DeckRenameException.class, () -> col.getDecks().rename(child, "filtered::child"));
assertThrows(DeckRenameException.class, () -> col.getDecks().rename(child, "FILTERED::child"));
}
use of com.ichi2.libanki.Deck 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());
}
Aggregations