use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_filt_reviewing_early_normal.
@Test
public void test_filt_reviewing_early_normal() throws Exception {
Collection col = getColV2();
Note note = col.newNote();
note.setItem("Front", "one");
col.addNote(note);
Card c = note.cards().get(0);
c.setIvl(100);
c.setQueue(CARD_TYPE_REV);
c.setType(QUEUE_TYPE_REV);
// due in 25 days, so it's been waiting 75 days
c.setDue(col.getSched().getToday() + 25);
c.setMod(1);
c.setFactor(STARTING_FACTOR);
c.startTimer();
c.flush();
col.reset();
assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
// create a dynamic deck and refresh it
long did = col.getDecks().newDyn("Cram");
col.getSched().rebuildDyn(did);
col.reset();
// should appear as normal in the deck list
/* todo sort
assertEquals(1, sorted(col.getSched().deckDueTree().getChildren())[0].review_count);
*/
// and should appear in the counts
assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
// grab it and check estimates
c = col.getSched().getCard();
assertEquals(4, col.getSched().answerButtons(c));
assertEquals(600, col.getSched().nextIvl(c, 1));
assertEquals(Math.round(75 * 1.2) * SECONDS_PER_DAY, col.getSched().nextIvl(c, 2));
assertThat(col.getSched().nextIvl(c, 3), is((long) (75 * 2.5) * SECONDS_PER_DAY));
assertThat(col.getSched().nextIvl(c, 4), is((long) (75 * 2.5 * 1.15) * SECONDS_PER_DAY));
// answer 'good'
col.getSched().answerCard(c, 3);
checkRevIvl(col, c, 90);
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
assertEquals(0L, c.getODue());
// should not be in learning
assertEquals(QUEUE_TYPE_REV, c.getQueue());
// should be logged as a cram rep
assertEquals(3, col.getDb().queryLongScalar("select type from revlog order by id desc limit 1"));
// due in 75 days, so it's been waiting 25 days
c.setIvl(100);
c.setDue(col.getSched().getToday() + 75);
c.flush();
col.getSched().rebuildDyn(did);
col.reset();
c = col.getSched().getCard();
assertEquals(60 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 2));
assertEquals(100 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
assertEquals(114 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
}
use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_new_v2.
@Test
public void test_new_v2() throws Exception {
Collection col = getColV2();
col.reset();
assertEquals(0, col.getSched().counts()[0]);
// 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.sched.Counts in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_newLimits_V2.
@Test
public void test_newLimits_V2() throws Exception {
Collection col = getColV2();
// add some notes
long deck2 = col.getDecks().id("Default::foo");
for (int i = 0; i < 30; i++) {
Note note = col.newNote();
note.setItem("Front", Integer.toString(i));
if (i > 4) {
note.model().put("did", deck2);
}
col.addNote(note);
}
// give the child deck a different configuration
long c2 = col.getDecks().confId("new conf");
col.getDecks().setConf(col.getDecks().get(deck2), c2);
col.reset();
// both confs have defaulted to a limit of 20
assertEquals(20, col.getSched().counts()[0]);
// first card we get comes from parent
Card c = col.getSched().getCard();
assertEquals(1, c.getDid());
// limit the parent to 10 cards, meaning we get 10 in total
DeckConfig conf1 = col.getDecks().confForDid(1);
conf1.getJSONObject("new").put("perDay", 10);
col.getDecks().save(conf1);
col.reset();
assertEquals(10, col.getSched().counts()[0]);
// if we limit child to 4, we should get 9
DeckConfig conf2 = col.getDecks().confForDid(deck2);
conf2.getJSONObject("new").put("perDay", 4);
col.getDecks().save(conf2);
col.reset();
assertEquals(9, col.getSched().counts()[0]);
}
use of com.ichi2.libanki.sched.Counts 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.sched.Counts 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());
}
Aggregations