use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.
the class AbstractSchedTest method testUndoResetsCardCountsToCorrectValue.
@Test
public void testUndoResetsCardCountsToCorrectValue() throws InterruptedException {
// #6587
addNoteUsingBasicModel("Hello", "World");
Collection col = getCol();
AbstractSched sched = col.getSched();
col.reset();
Card cardBeforeUndo = sched.getCard();
int[] countsBeforeUndo = sched.counts();
// Not shown in the UI, but there is a state where the card has been removed from the queue, but not answered
// where the counts are decremented.
assertThat(countsBeforeUndo, is(new int[] { 0, 0, 0 }));
sched.answerCard(cardBeforeUndo, EASE_3);
waitForTask(UNDO, 5000);
int[] countsAfterUndo = sched.counts();
assertThat("Counts after an undo should be the same as before an undo", countsAfterUndo, is(countsBeforeUndo));
}
use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_repCountsV1.
@Test
public void test_repCountsV1() throws Exception {
Collection col = getColV1();
Note note = col.newNote();
note.setItem("Front", "one");
col.addNote(note);
col.reset();
// lrnReps should be accurate on pass/fail
assertArrayEquals(new int[] { 1, 0, 0 }, col.getSched().counts());
col.getSched().answerCard(col.getSched().getCard(), 1);
assertArrayEquals(new int[] { 0, 2, 0 }, col.getSched().counts());
col.getSched().answerCard(col.getSched().getCard(), 1);
assertArrayEquals(new int[] { 0, 2, 0 }, col.getSched().counts());
col.getSched().answerCard(col.getSched().getCard(), 2);
assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
col.getSched().answerCard(col.getSched().getCard(), 1);
assertArrayEquals(new int[] { 0, 2, 0 }, col.getSched().counts());
col.getSched().answerCard(col.getSched().getCard(), 2);
assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
col.getSched().answerCard(col.getSched().getCard(), 2);
assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
note = col.newNote();
note.setItem("Front", "two");
col.addNote(note);
col.reset();
// initial pass should be correct too
col.getSched().answerCard(col.getSched().getCard(), 2);
assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
col.getSched().answerCard(col.getSched().getCard(), 1);
assertArrayEquals(new int[] { 0, 2, 0 }, col.getSched().counts());
col.getSched().answerCard(col.getSched().getCard(), 3);
assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
// immediate graduate should work
note = col.newNote();
note.setItem("Front", "three");
col.addNote(note);
col.reset();
col.getSched().answerCard(col.getSched().getCard(), 3);
assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
// and failing a review should too
note = col.newNote();
note.setItem("Front", "three");
col.addNote(note);
Card c = note.cards().get(0);
c.setType(CARD_TYPE_REV);
c.setQueue(QUEUE_TYPE_REV);
c.setDue(col.getSched().getToday());
c.flush();
col.reset();
assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
col.getSched().answerCard(col.getSched().getCard(), 1);
assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
}
use of com.ichi2.libanki.sched.Counts 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.sched.Counts in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_cram.
@Test
public void test_cram() throws Exception {
Collection col = getColV1();
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());
Card cardcopy = c.clone();
// create a dynamic deck and refresh it
long did = col.getDecks().newDyn("Cram");
col.getSched().rebuildDyn(did);
col.reset();
// should appear as new in the deck list
// todo: which sort
// and should appear in the counts
assertArrayEquals(new int[] { 1, 0, 0 }, col.getSched().counts());
// grab it and check estimates
c = col.getSched().getCard();
assertEquals(2, col.getSched().answerButtons(c));
assertEquals(600, col.getSched().nextIvl(c, 1));
assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, 2));
Deck cram = col.getDecks().get(did);
cram.put("delays", new JSONArray(new double[] { 1, 10 }));
col.getDecks().save(cram);
assertEquals(3, col.getSched().answerButtons(c));
assertEquals(60, col.getSched().nextIvl(c, 1));
assertEquals(600, col.getSched().nextIvl(c, 2));
assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, 3));
col.getSched().answerCard(c, 2);
// elapsed time was 75 days
// factor = 2.5+1.2/2 = 1.85
// int(75*1.85) = 138
assertEquals(138, c.getIvl());
assertEquals(138, c.getODue());
assertEquals(QUEUE_TYPE_LRN, c.getQueue());
// should be logged as a cram rep
assertEquals(3, col.getDb().queryLongScalar("select type from revlog order by id desc limit 1"));
// check ivls again
assertEquals(60, col.getSched().nextIvl(c, 1));
assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, 2));
assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, 3));
// when it graduates, due is updated
c = col.getSched().getCard();
col.getSched().answerCard(c, 2);
assertEquals(138, c.getIvl());
assertEquals(138, c.getDue());
assertEquals(QUEUE_TYPE_REV, c.getQueue());
// and it will have moved back to the previous deck
assertEquals(1, c.getDid());
// cram the deck again
col.getSched().rebuildDyn(did);
col.reset();
c = col.getSched().getCard();
// check ivls again - passing should be idempotent
assertEquals(60, col.getSched().nextIvl(c, 1));
assertEquals(600, col.getSched().nextIvl(c, 2));
assertEquals(138 * 60 * 60 * 24, col.getSched().nextIvl(c, 3));
col.getSched().answerCard(c, 2);
assertEquals(138, c.getIvl());
assertEquals(138, c.getODue());
// fail
col.getSched().answerCard(c, 1);
assertEquals(60, col.getSched().nextIvl(c, 1));
assertEquals(600, col.getSched().nextIvl(c, 2));
assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
// delete the deck, returning the card mid-study
col.getDecks().rem(col.getDecks().selected());
assertEquals(1, col.getSched().deckDueTree().size());
c.load();
assertEquals(1, c.getIvl());
assertEquals(col.getSched().getToday() + 1, c.getDue());
// make it due
col.reset();
assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
c.setDue(-5);
c.setIvl(100);
c.flush();
col.reset();
assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
// cram again
did = col.getDecks().newDyn("Cram");
col.getSched().rebuildDyn(did);
col.reset();
assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
c.load();
assertEquals(4, col.getSched().answerButtons(c));
// add a sibling so we can test minSpace, etc
Card c2 = c.clone();
c2.setId(0);
c2.setOrd(1);
c2.setDue(325);
c2.flush();
// should be able to answer it
c = col.getSched().getCard();
col.getSched().answerCard(c, 4);
// it should have been moved back to the original deck
assertEquals(1, c.getDid());
}
use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_counts_idxV2.
@Test
public void test_counts_idxV2() throws Exception {
Collection col = getColV2();
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
col.reset();
assertArrayEquals(new int[] { 1, 0, 0 }, col.getSched().counts());
Card c = col.getSched().getCard();
// counter's been decremented but idx indicates 1
assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
assertEquals(0, col.getSched().countIdx(c));
// answer to move to learn queue
col.getSched().answerCard(c, 1);
assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
// fetching again will decrement the count
c = col.getSched().getCard();
assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
assertEquals(1, col.getSched().countIdx(c));
// answering should add it back again
col.getSched().answerCard(c, 1);
assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
}
Aggregations