use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_nextIvlV2.
@Test
public void test_nextIvlV2() throws Exception {
Collection col = getColV2();
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((30 + 180) / 2, col.getSched().nextIvl(c, 2));
assertEquals(180, col.getSched().nextIvl(c, 3));
assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
col.getSched().answerCard(c, 1);
// cards in learning
// //////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals(30, col.getSched().nextIvl(c, 1));
assertEquals((30 + 180) / 2, col.getSched().nextIvl(c, 2));
assertEquals(180, col.getSched().nextIvl(c, 3));
assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
col.getSched().answerCard(c, 3);
assertEquals(30, col.getSched().nextIvl(c, 1));
assertEquals((180 + 600) / 2, col.getSched().nextIvl(c, 2));
assertEquals(600, col.getSched().nextIvl(c, 3));
assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
col.getSched().answerCard(c, 3);
// normal graduation is tomorrow
assertEquals(1 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
assertEquals(4 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
// 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, 3));
assertEquals(101 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
// 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"));
}
use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_learn_dayV2.
@Test
public void test_learn_dayV2() throws Exception {
Collection col = getColV2();
// 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, 3);
// 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, 3));
// answering it will place it in queue 3
col.getSched().answerCard(c, 3);
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, 3));
// 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, 3);
// 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, 3));
col.getSched().answerCard(c, 3);
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(QUEUE_TYPE_DAY_LEARN_RELEARN, c.getQueue());
assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
}
use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_newBoxes_v2.
@Test
public void test_newBoxes_v2() throws Exception {
Collection col = getColV2();
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, 2, 3, 4, 5 }));
col.getDecks().save(conf);
col.getSched().answerCard(c, 2);
// should handle gracefully
conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1 }));
col.getDecks().save(conf);
col.getSched().answerCard(c, 2);
}
use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_newBoxes_v1.
@Test
public void test_newBoxes_v1() throws Exception {
Collection col = getColV1();
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, 2, 3, 4, 5 }));
col.getDecks().save(conf);
col.getSched().answerCard(c, 2);
// should handle gracefully
conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1 }));
col.getDecks().save(conf);
col.getSched().answerCard(c, 2);
}
use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.
the class Syncer method mergeDecks.
private void mergeDecks(JSONArray rchg) {
JSONArray decks = rchg.getJSONArray(0);
for (JSONObject deck : decks.jsonObjectIterable()) {
Deck r = new Deck(deck);
Deck l = mCol.getDecks().get(r.getLong("id"), false);
// if missing locally or server is newer, update
if (l == null || r.getLong("mod") > l.getLong("mod")) {
mCol.getDecks().update(r);
}
}
JSONArray confs = rchg.getJSONArray(1);
for (JSONObject deckConfig : confs.jsonObjectIterable()) {
DeckConfig r = new DeckConfig(deckConfig, DeckConfig.Source.DECK_CONFIG);
DeckConfig l = mCol.getDecks().getConf(r.getLong("id"));
// if missing locally or server is newer, update
if (l == null || r.getLong("mod") > l.getLong("mod")) {
mCol.getDecks().updateConf(r);
}
}
}
Aggregations