use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_button_spacingV2.
@Test
public void test_button_spacingV2() throws Exception {
Collection col = getColV2();
Note note = col.newNote();
note.setItem("Front", "one");
col.addNote(note);
// 1 day ivl review card due now
Card c = note.cards().get(0);
c.setType(CARD_TYPE_REV);
c.setQueue(QUEUE_TYPE_REV);
c.setDue(col.getSched().getToday());
c.setReps(1);
c.setIvl(1);
c.startTimer();
c.flush();
col.reset();
// Upstream, there is no space in 2d
assertEquals("2 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 2)));
assertEquals("3 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 3)));
assertEquals("4 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 4)));
// if hard factor is <= 1, then hard may not increase
DeckConfig conf = col.getDecks().confForDid(1);
conf.getJSONObject("rev").put("hardFactor", 1);
col.getDecks().save(conf);
assertEquals("1 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 2)));
}
use of com.ichi2.libanki.DeckConfig 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.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_learnV2.
@Test
public void test_learnV2() throws Exception {
Collection col = getColV2();
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
// set as a learn card and rebuild queues
col.getDb().execute("update cards set queue=0, type=0");
col.reset();
// sched.getCard should return it, since it's due in the past
Card c = col.getSched().getCard();
assertNotNull(c);
DeckConfig conf = col.getSched()._cardConf(c);
conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 0.5, 3, 10 }));
col.getDecks().save(conf);
// fail it
col.getSched().answerCard(c, 1);
// it should have three reps left to graduation
assertEquals(3, c.getLeft() % 1000);
assertEquals(3, c.getLeft() / 1000);
// it should be due in 30 seconds
long t = Math.round(c.getDue() - col.getTime().intTime());
assertThat(t, is(greaterThanOrEqualTo(25L)));
assertThat(t, is(lessThanOrEqualTo(40L)));
// pass it once
col.getSched().answerCard(c, 3);
// it should be due in 3 minutes
long dueIn = c.getDue() - col.getTime().intTime();
assertThat(dueIn, is(greaterThanOrEqualTo(178L)));
assertThat(dueIn, is(lessThanOrEqualTo((long) (180 * 1.25))));
assertEquals(2, c.getLeft() % 1000);
assertEquals(2, c.getLeft() / 1000);
// check log is accurate
Cursor log = col.getDb().getDatabase().query("select * from revlog order by id desc");
assertTrue(log.moveToFirst());
assertEquals(3, log.getInt(3));
assertEquals(-180, log.getInt(4));
assertEquals(-30, log.getInt(5));
// pass again
col.getSched().answerCard(c, 3);
// it should be due in 10 minutes
dueIn = c.getDue() - col.getTime().intTime();
assertThat(dueIn, is(greaterThanOrEqualTo(599L)));
assertThat(dueIn, is(lessThanOrEqualTo((long) (600 * 1.25))));
assertEquals(1, c.getLeft() % 1000);
assertEquals(1, c.getLeft() / 1000);
// the next pass should graduate the card
assertEquals(QUEUE_TYPE_LRN, c.getQueue());
assertEquals(CARD_TYPE_LRN, c.getType());
col.getSched().answerCard(c, 3);
assertEquals(QUEUE_TYPE_REV, c.getQueue());
assertEquals(CARD_TYPE_REV, c.getType());
// should be due tomorrow, with an interval of 1
assertEquals(col.getSched().getToday() + 1, c.getDue());
assertEquals(1, c.getIvl());
// or normal removal
c.setType(CARD_TYPE_NEW);
c.setQueue(QUEUE_TYPE_LRN);
col.getSched().answerCard(c, 4);
assertEquals(CARD_TYPE_REV, c.getType());
assertEquals(QUEUE_TYPE_REV, c.getQueue());
assertTrue(checkRevIvl(col, c, 4));
// revlog should have been updated each time
assertEquals(5, col.getDb().queryScalar("select count() from revlog where type = 0"));
}
use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_relearn_no_steps.
@Test
public void test_relearn_no_steps() 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.setDue(col.getSched().getToday());
c.setQueue(CARD_TYPE_REV);
c.setType(QUEUE_TYPE_REV);
c.flush();
DeckConfig conf = col.getDecks().confForDid(1);
conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] {}));
col.getDecks().save(conf);
// fail the card
col.reset();
c = col.getSched().getCard();
col.getSched().answerCard(c, 1);
assertEquals(CARD_TYPE_REV, c.getType());
assertEquals(QUEUE_TYPE_REV, c.getQueue());
}
use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method filteredDeckSchedulingOptionsRegressionTest.
/**
* Reported by /u/CarelessSecretary9 on reddit:
*/
@Test
public void filteredDeckSchedulingOptionsRegressionTest() {
Collection col = getCol();
col.setCrt(1587852900L);
// 30 minutes learn ahead. required as we have 20m delay
col.getConf().put("collapseTime", 1800);
long homeDeckId = addDeck("Poorretention");
DeckConfig homeDeckConf = col.getDecks().confForDid(homeDeckId);
JSONObject lapse = homeDeckConf.getJSONObject("lapse");
lapse.put("minInt", 2);
lapse.put("mult", 0.7d);
lapse.put("delays", new JSONArray("[20]"));
ensureLapseMatchesSppliedAnkiDesktopConfig(lapse);
col.flush();
long dynId = addDynamicDeck("Dyn");
/*
>>> pp(self.reviewer.card)
{'data': '', 'did': 1587939535230, 'due': 0, 'factor': 1300, 'flags': 0, 'id': 1510928829863, 'ivl': 25,
'lapses': 5, 'left': 1004, 'mod': 1587921512, 'nid': 1510928805161, 'odid': 1587920944107,
'odue': 0, 'ord': 0, 'queue': 2, 'reps': 22, 'type': 2, 'usn': -1}
*/
Note n = addNoteUsingBasicModel("Hello", "World");
Card c = getOnlyElement(n.cards());
c.setType(Consts.CARD_TYPE_REV);
c.setQueue(Consts.QUEUE_TYPE_REV);
c.setIvl(25);
c.setDue(0);
c.setLapses(5);
c.setFactor(1300);
c.setLeft(1004);
c.setODid(homeDeckId);
c.setDid(dynId);
c.flush();
SchedV2 v2 = new SchedV2(col);
Card schedCard = v2.getCard();
assertThat(schedCard, Matchers.notNullValue());
v2.answerCard(schedCard, Consts.BUTTON_ONE);
assertThat("The lapsed card should now be counted as lrn", v2.mLrnCount, is(1));
Card after = v2.getCard();
assertThat("A card should be returned ", after, Matchers.notNullValue());
/* Data from Anki - pp(self.reviewer.card)
{'data': '', 'did': 1587939535230, 'due': 1587941137, 'factor': 1300,
'flags': 0, 'id': 1510928829863, 'ivl': 17, 'lapses': 6, 'left': 1001,
'mod': 1587939720, 'nid': 1510928805161, 'odid': 1587920944107, 'odue': 0,
'ord': 0, 'queue': 1, 'reps': 23, 'type': 3, 'usn': -1}
*/
assertThat(after.getType(), is(Consts.CARD_TYPE_RELEARNING));
assertThat(after.getQueue(), is(Consts.QUEUE_TYPE_LRN));
assertThat(after.getLeft(), is(1001));
assertThat("ivl is reduced by 70%", after.getIvl(), is(17));
assertThat("One lapse is added", after.getLapses(), is(6));
assertThat(v2.answerButtons(after), is(4));
long one = v2.nextIvl(after, Consts.BUTTON_ONE);
long two = v2.nextIvl(after, Consts.BUTTON_TWO);
long three = v2.nextIvl(after, Consts.BUTTON_THREE);
long four = v2.nextIvl(after, Consts.BUTTON_FOUR);
// 20 mins
assertThat("Again should pick the current step", one, is(1200L));
// 30 mins
assertThat("Repeating single step - 20 minutes * 1.5", two, is(1800L));
// 17 days
assertThat("Good should take the reduced interval (25 * 0.7)", three, is(1468800L));
// 18 days
assertThat("Easy should have a bonus day over good", four, is(1555200L));
}
Aggregations