use of com.ichi2.utils.JSONArray in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_reviewsV1.
@Test
public void test_reviewsV1() throws Exception {
Collection col = getColV1();
// 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();
// failing it should put it in the learn queue with the default options
// //////////////////////////////////////////////////////////////////////////////////////////////////
// different delay to new
col.reset();
DeckConfig conf = col.getSched()._cardConf(c);
conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 2, 20 }));
col.getDecks().save(conf);
col.getSched().answerCard(c, 1);
assertEquals(QUEUE_TYPE_LRN, c.getQueue());
// it should be due tomorrow, with an interval of 1
assertEquals(col.getSched().getToday() + 1, c.getODue());
assertEquals(1, c.getIvl());
// but because it's in the learn queue, its current due time should be in
// the future
assertThat(c.getDue(), is(greaterThanOrEqualTo(col.getTime().intTime())));
assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(118L)));
// factor should have been decremented
assertEquals(2300, c.getFactor());
// check counters
assertEquals(2, c.getLapses());
assertEquals(4, c.getReps());
// check ests.
assertEquals(120, col.getSched().nextIvl(c, 1));
assertEquals(20 * 60, col.getSched().nextIvl(c, 2));
// try again with an ease of 2 instead
// //////////////////////////////////////////////////////////////////////////////////////////////////
c = cardcopy.clone();
c.flush();
col.getSched().answerCard(c, 2);
assertEquals(QUEUE_TYPE_REV, c.getQueue());
// the new interval should be (100 + 8/4) * 1.2 = 122
assertTrue(checkRevIvl(col, c, 122));
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());
}
use of com.ichi2.utils.JSONArray in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_learnV1.
@Test
public void test_learnV1() throws Exception {
Collection col = getColV1();
// 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, 2);
// it should be due in 3 minutes
assertEquals(Math.round(c.getDue() - col.getTime().intTime()), 179, 1);
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(2, log.getInt(3));
assertEquals(-180, log.getInt(4));
assertEquals(-30, log.getInt(5));
// pass again
col.getSched().answerCard(c, 2);
// it should be due in 10 minutes
assertEquals(c.getDue() - col.getTime().intTime(), 599, 1);
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, 2);
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, 3);
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"));
// now failed card handling
c.setType(CARD_TYPE_REV);
c.setQueue(QUEUE_TYPE_LRN);
c.setODue(123);
col.getSched().answerCard(c, 3);
assertEquals(123, c.getDue());
assertEquals(CARD_TYPE_REV, c.getType());
assertEquals(QUEUE_TYPE_REV, c.getQueue());
// we should be able to remove manually, too
c.setType(CARD_TYPE_REV);
c.setQueue(QUEUE_TYPE_LRN);
c.setODue(321);
c.flush();
((Sched) col.getSched()).removeLrn();
c.load();
assertEquals(QUEUE_TYPE_REV, c.getQueue());
assertEquals(321, c.getDue());
}
use of com.ichi2.utils.JSONArray in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_norelearnV1.
@Test
public void test_norelearnV1() throws Exception {
Collection col = getColV1();
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
col.addNote(note);
Card c = note.cards().get(0);
c.setType(CARD_TYPE_REV);
c.setQueue(QUEUE_TYPE_REV);
c.setDue(0);
c.setFactor(STARTING_FACTOR);
c.setReps(3);
c.setLapses(1);
c.setIvl(100);
c.startTimer();
c.flush();
col.reset();
col.getSched().answerCard(c, 1);
col.getSched()._cardConf(c).getJSONObject("lapse").put("delays", new JSONArray(new double[] {}));
col.getSched().answerCard(c, 1);
}
use of com.ichi2.utils.JSONArray in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_learn_dayV1.
@Test
public void test_learn_dayV1() throws Exception {
Collection col = getColV1();
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
col.addNote(note);
col.reset();
Card c = col.getSched().getCard();
DeckConfig conf = col.getSched()._cardConf(c);
conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 10, 1440, 2880 }));
col.getDecks().save(conf);
// pass it
col.getSched().answerCard(c, 2);
// two reps to graduate, 1 more today
assertEquals(3, c.getLeft() % 1000);
assertEquals(1, c.getLeft() / 1000);
assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
c = col.getSched().getCard();
assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, 2));
// answering it will place it in queue 3
col.getSched().answerCard(c, 2);
assertEquals(col.getSched().getToday() + 1, c.getDue());
assertEquals(QUEUE_TYPE_DAY_LEARN_RELEARN, c.getQueue());
assertNull(col.getSched().getCard());
// for testing, move it back a day
c.setDue(c.getDue() - 1);
c.flush();
col.reset();
assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
c = col.getSched().getCard();
// nextIvl should work
assertEquals(SECONDS_PER_DAY * 2, col.getSched().nextIvl(c, 2));
// if we fail it, it should be back in the correct queue
col.getSched().answerCard(c, 1);
assertEquals(QUEUE_TYPE_LRN, c.getQueue());
col.undo();
col.reset();
c = col.getSched().getCard();
col.getSched().answerCard(c, 2);
// simulate the passing of another two days
c.setDue(c.getDue() - 2);
c.flush();
col.reset();
// the last pass should graduate it into a review card
assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, 2));
col.getSched().answerCard(c, 2);
assertEquals(CARD_TYPE_REV, c.getType());
assertEquals(QUEUE_TYPE_REV, c.getQueue());
// if the lapse step is tomorrow, failing it should handle the counts
// correctly
c.setDue(0);
c.flush();
col.reset();
assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
conf = col.getSched()._cardConf(c);
conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 1440 }));
col.getDecks().save(conf);
c = col.getSched().getCard();
col.getSched().answerCard(c, 1);
assertEquals(CARD_TYPE_RELEARNING, c.getQueue());
assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
}
use of com.ichi2.utils.JSONArray in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_nextIvlV1.
@Test
public void test_nextIvlV1() throws Exception {
Collection col = getColV1();
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
col.reset();
DeckConfig conf = col.getDecks().confForDid(1);
conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 0.5, 3, 10 }));
conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 1, 5, 9 }));
col.getDecks().save(conf);
Card c = col.getSched().getCard();
// new cards
// //////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(30, col.getSched().nextIvl(c, 1));
assertEquals(180, col.getSched().nextIvl(c, 2));
assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
col.getSched().answerCard(c, 1);
// cards in learning
// //////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(30, col.getSched().nextIvl(c, 1));
assertEquals(180, col.getSched().nextIvl(c, 2));
assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
col.getSched().answerCard(c, 2);
assertEquals(30, col.getSched().nextIvl(c, 1));
assertEquals(600, col.getSched().nextIvl(c, 2));
assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
col.getSched().answerCard(c, 2);
// normal graduation is tomorrow
assertEquals(1 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 2));
assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
// lapsed cards
// //////////////////////////////////////////////////////////////////////////////////////////////////
c.setType(CARD_TYPE_REV);
c.setIvl(100);
c.setFactor(STARTING_FACTOR);
assertEquals(60, col.getSched().nextIvl(c, 1));
assertEquals(100 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 2));
assertEquals(100 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
// review cards
// //////////////////////////////////////////////////////////////////////////////////////////////////
c.setQueue(QUEUE_TYPE_REV);
c.setIvl(100);
c.setFactor(STARTING_FACTOR);
// failing it should put it at 60s
assertEquals(60, col.getSched().nextIvl(c, 1));
// or 1 day if relearn is false
conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] {}));
col.getDecks().save(conf);
assertEquals(1 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 1));
// (* 100 1.2 SECONDS_PER_DAY)10368000.0
assertEquals(10368000, col.getSched().nextIvl(c, 2));
// (* 100 2.5 SECONDS_PER_DAY)21600000.0
assertEquals(21600000, col.getSched().nextIvl(c, 3));
// (* 100 2.5 1.3 SECONDS_PER_DAY)28080000.0
assertEquals(28080000, col.getSched().nextIvl(c, 4));
assertThat(without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 4)), is("10.8 mo"));
}
Aggregations