use of com.ichi2.libanki.Model in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_new_v1.
public void test_new_v1() throws Exception {
Collection col = getColV1();
col.reset();
assertEquals(0, col.getSched().newDue());
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
col.reset();
assertEquals(1, col.getSched().counts()[0]);
// fetch it
Card c = col.getSched().getCard();
assertNotNull(c);
assertEquals(QUEUE_TYPE_NEW, c.getQueue());
assertEquals(CARD_TYPE_NEW, c.getType());
// if we answer it, it should become a learn card
long t = col.getTime().intTime();
col.getSched().answerCard(c, 1);
assertEquals(QUEUE_TYPE_LRN, c.getQueue());
assertEquals(CARD_TYPE_LRN, c.getType());
assertThat(c.getDue(), is(greaterThanOrEqualTo(t)));
// disabled for now, as the learn fudging makes this randomly fail
// // the default order should ensure siblings are not seen together, and
// // should show all cards
// Model m = col.getModels().current(); Models mm = col.getModels()
// JSONObject t = mm.newTemplate("Reverse")
// t['qfmt'] = "{{Back}}"
// t['afmt'] = "{{Front}}"
// mm.addTemplateModChanged(m, t)
// mm.save(m)
// note = col.newNote()
// note['Front'] = u"2"; note['Back'] = u"2"
// col.addNote(note)
// note = col.newNote()
// note['Front'] = u"3"; note['Back'] = u"3"
// col.addNote(note)
// col.reset()
// qs = ("2", "3", "2", "3")
// for (int n = 0; n < 4; n++) {
// c = col.getSched().getCard()
// assertTrue(qs[n] in c.q())
// col.getSched().answerCard(c, 2)
// }
}
use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class SchedV2Test method test_review_limits.
@Test
public void test_review_limits() throws Exception {
Collection col = getColV2();
Deck parent = col.getDecks().get(addDeck("parent"));
Deck child = col.getDecks().get(addDeck("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(QUEUE_TYPE_REV);
c.setType(CARD_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(10, tree.getChildren().get(0).getRevCount());
// .counts() should match
col.getDecks().select(child.getLong("id"));
col.reset();
assertEquals(new Counts(0, 0, 10), col.getSched().counts());
// answering a card in the child should decrement parent count
Card c = getCard();
col.getSched().answerCard(c, BUTTON_THREE);
assertEquals(new Counts(0, 0, 9), col.getSched().counts());
tree = col.getSched().deckDueTree().get(1);
assertEquals(4, tree.getRevCount());
assertEquals(9, tree.getChildren().get(0).getRevCount());
}
use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class SchedTest method test_ordcycleV1.
@Test
public void test_ordcycleV1() throws Exception {
Collection col = getColV1();
// add two more templates and set second active
Model m = col.getModels().current();
ModelManager mm = col.getModels();
JSONObject t = Models.newTemplate("Reverse");
t.put("qfmt", "{{Back}}");
t.put("afmt", "{{Front}}");
mm.addTemplateModChanged(m, t);
t = Models.newTemplate("f2");
t.put("qfmt", "{{Front}}");
t.put("afmt", "{{Back}}");
mm.addTemplateModChanged(m, t);
mm.save(m);
// create a new note; it should have 3 cards
Note note = col.newNote();
note.setItem("Front", "1");
note.setItem("Back", "1");
col.addNote(note);
assertEquals(3, col.cardCount());
col.reset();
// ordinals should arrive in order
AbstractSched sched = col.getSched();
Card c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
waitForAsyncTasksToComplete();
assertEquals(0, c.getOrd());
c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
waitForAsyncTasksToComplete();
assertEquals(1, c.getOrd());
c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(2, c.getOrd());
}
use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class SchedTest method test_new_v1.
public void test_new_v1() throws Exception {
Collection col = getColV1();
col.reset();
assertEquals(0, col.getSched().newCount());
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
col.reset();
assertEquals(1, col.getSched().counts().getNew());
// fetch it
Card c = getCard();
assertNotNull(c);
assertEquals(QUEUE_TYPE_NEW, c.getQueue());
assertEquals(CARD_TYPE_NEW, c.getType());
// if we answer it, it should become a learn card
long t = col.getTime().intTime();
col.getSched().answerCard(c, BUTTON_ONE);
assertEquals(QUEUE_TYPE_LRN, c.getQueue());
assertEquals(CARD_TYPE_LRN, c.getType());
assertThat(c.getDue(), is(greaterThanOrEqualTo(t)));
// disabled for now, as the learn fudging makes this randomly fail
// // the default order should ensure siblings are not seen together, and
// // should show all cards
// Model m = col.getModels().current(); Models mm = col.getModels()
// JSONObject t = mm.newTemplate("Reverse")
// t['qfmt'] = "{{Back}}"
// t['afmt'] = "{{Front}}"
// mm.addTemplateModChanged(m, t)
// mm.save(m)
// note = col.newNote()
// note['Front'] = u"2"; note['Back'] = u"2"
// col.addNote(note)
// note = col.newNote()
// note['Front'] = u"3"; note['Back'] = u"3"
// col.addNote(note)
// col.reset()
// qs = ("2", "3", "2", "3")
// for (int n = 0; n < 4; n++) {
// c = getCard()
// assertTrue(qs[n] in c.q())
// col.getSched().answerCard(c, 2)
// }
}
use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class CardBrowser method removeNotesView.
/**
* Removes cards from view. Doesn't delete them in model (database).
*/
@SuppressWarnings("SameParameterValue")
private void removeNotesView(Card[] cards, boolean reorderCards) {
List<Long> cardIds = new ArrayList<>(cards.length);
for (Card c : cards) {
cardIds.add(c.getId());
}
removeNotesView(cardIds, reorderCards);
}
Aggregations