use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_newLimits_V1.
@Test
public void test_newLimits_V1() throws Exception {
Collection col = getColV1();
// add some notes
long deck2 = col.getDecks().id("Default::foo");
Note note;
for (int i = 0; i < 30; i++) {
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("both confs have defaulted to a limit of 20", 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.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_moveVersions.
@Test
public void test_moveVersions() throws Exception {
Collection col = getColV2();
col.changeSchedulerVer(1);
Note n = col.newNote();
n.setItem("Front", "one");
col.addNote(n);
// make it a learning card
col.reset();
Card c = col.getSched().getCard();
col.getSched().answerCard(c, 1);
// the move to v2 should reset it to new
col.changeSchedulerVer(2);
c.load();
assertEquals(QUEUE_TYPE_NEW, c.getQueue());
assertEquals(CARD_TYPE_NEW, c.getType());
// fail it again, and manually bury it
col.reset();
c = col.getSched().getCard();
col.getSched().answerCard(c, 1);
col.getSched().buryCards(new long[] { c.getId() });
c.load();
assertEquals(QUEUE_TYPE_MANUALLY_BURIED, c.getQueue());
// revert to version 1
col.changeSchedulerVer(1);
// card should have moved queues
c.load();
assertEquals(QUEUE_TYPE_SIBLING_BURIED, c.getQueue());
// and it should be new again when unburied
col.getSched().unburyCards();
c.load();
assertEquals(CARD_TYPE_NEW, c.getQueue());
assertEquals(QUEUE_TYPE_NEW, c.getType());
// make sure relearning cards transition correctly to v1
col.changeSchedulerVer(2);
// card with 100 day interval, answering again
col.getSched().reschedCards(new long[] { c.getId() }, 100, 100);
c.load();
c.setDue(0);
c.flush();
DeckConfig conf = col.getSched()._cardConf(c);
conf.getJSONObject("lapse").put("mult", 0.5);
col.getDecks().save(conf);
col.reset();
c = col.getSched().getCard();
col.getSched().answerCard(c, 1);
c.load();
assertEquals(50, c.getIvl());
// due should be correctly set when removed from learning early
col.changeSchedulerVer(1);
c.load();
assertEquals(QUEUE_TYPE_REV, c.getQueue());
assertEquals(CARD_TYPE_REV, c.getType());
assertEquals(50, c.getDue());
}
use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_reviewsV2.
@Test
public void test_reviewsV2() throws Exception {
Collection col = getColV2();
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
// set the card up as a review card, due 8 days ago
Card c = note.cards().get(0);
c.setType(CARD_TYPE_REV);
c.setQueue(QUEUE_TYPE_REV);
c.setDue(col.getSched().getToday() - 8);
c.setFactor(STARTING_FACTOR);
c.setReps(3);
c.setLapses(1);
c.setIvl(100);
c.startTimer();
c.flush();
// save it for later use as well
Card cardcopy = c.clone();
// try with an ease of 2
// //////////////////////////////////////////////////////////////////////////////////////////////////
c = cardcopy.clone();
c.flush();
col.reset();
col.getSched().answerCard(c, 2);
assertEquals(QUEUE_TYPE_REV, c.getQueue());
// the new interval should be (100) * 1.2 = 120
assertTrue(checkRevIvl(col, c, 120));
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
// factor should have been decremented
assertEquals(2350, c.getFactor());
// check counters
assertEquals(1, c.getLapses());
assertEquals(4, c.getReps());
// ease 3
// //////////////////////////////////////////////////////////////////////////////////////////////////
c = cardcopy.clone();
c.flush();
col.getSched().answerCard(c, 3);
// the new interval should be (100 + 8/2) * 2.5 = 260
assertTrue(checkRevIvl(col, c, 260));
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
// factor should have been left alone
assertEquals(STARTING_FACTOR, c.getFactor());
// ease 4
// //////////////////////////////////////////////////////////////////////////////////////////////////
c = cardcopy.clone();
c.flush();
col.getSched().answerCard(c, 4);
// the new interval should be (100 + 8) * 2.5 * 1.3 = 351
assertTrue(checkRevIvl(col, c, 351));
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
// factor should have been increased
assertEquals(2650, c.getFactor());
// leech handling
// //////////////////////////////////////////////////////////////////////////////////////////////////
DeckConfig conf = col.getDecks().getConf(1);
conf.getJSONObject("lapse").put("leechAction", LEECH_SUSPEND);
col.getDecks().save(conf);
c = cardcopy.clone();
c.setLapses(7);
c.flush();
/* todo hook
// steup hook
hooked = new [] {};
def onLeech(card):
hooked.append(1);
hooks.card_did_leech.append(onLeech);
col.getSched().answerCard(c, 1);
assertTrue(hooked);
assertEquals(QUEUE_TYPE_SUSPENDED, c.getQueue());
c.load();
assertEquals(QUEUE_TYPE_SUSPENDED, c.getQueue());
*/
}
use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_filt_keep_lrn_state.
@Test
public void test_filt_keep_lrn_state() throws Exception {
Collection col = getColV2();
Note note = col.newNote();
note.setItem("Front", "one");
col.addNote(note);
// fail the card outside filtered deck
Card c = col.getSched().getCard();
DeckConfig conf = col.getSched()._cardConf(c);
conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 10, 61 }));
col.getDecks().save(conf);
col.getSched().answerCard(c, 1);
assertEquals(CARD_TYPE_LRN, c.getQueue());
assertEquals(QUEUE_TYPE_LRN, c.getType());
assertEquals(3003, c.getLeft());
col.getSched().answerCard(c, 3);
assertEquals(CARD_TYPE_LRN, c.getQueue());
assertEquals(QUEUE_TYPE_LRN, c.getType());
// create a dynamic deck and refresh it
long did = col.getDecks().newDyn("Cram");
col.getSched().rebuildDyn(did);
col.reset();
// card should still be in learning state
c.load();
assertEquals(CARD_TYPE_LRN, c.getQueue());
assertEquals(QUEUE_TYPE_LRN, c.getType());
assertEquals(2002, c.getLeft());
// should be able to advance learning steps
col.getSched().answerCard(c, 3);
// should be due at least an hour in the future
assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(60 * 60L)));
// emptying the deck preserves learning state
col.getSched().emptyDyn(did);
c.load();
assertEquals(CARD_TYPE_LRN, c.getQueue());
assertEquals(QUEUE_TYPE_LRN, c.getType());
assertEquals(1001, c.getLeft());
assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(60 * 60L)));
}
use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_failmultV2.
@Test
public void test_failmultV2() throws Exception {
Collection col = getColV2();
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
Card c = note.cards().get(0);
c.setType(CARD_TYPE_REV);
c.setQueue(QUEUE_TYPE_REV);
c.setIvl(100);
c.setDue(col.getSched().getToday() - c.getIvl());
c.setFactor(STARTING_FACTOR);
c.setReps(3);
c.setLapses(1);
c.startTimer();
c.flush();
DeckConfig conf = col.getSched()._cardConf(c);
conf.getJSONObject("lapse").put("mult", 0.5);
col.getDecks().save(conf);
c = col.getSched().getCard();
col.getSched().answerCard(c, 1);
assertEquals(50, c.getIvl());
col.getSched().answerCard(c, 1);
assertEquals(25, c.getIvl());
}
Aggregations