use of com.ichi2.anki.CardBrowser.Column.ANSWER 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.anki.CardBrowser.Column.ANSWER 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());
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_counts_idxV1.
@Test
public void test_counts_idxV1() throws Exception {
Collection col = getColV1();
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, 2, 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, 2, 0 }, col.getSched().counts());
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project AnkiChinaAndroid by ankichinateam.
the class ModelTest method test_req.
@Test
public void test_req() {
Collection col = getCol();
Models mm = col.getModels();
Model basic = mm.byName("Basic");
assertTrue(basic.has("req"));
reqSize(basic);
JSONArray r = basic.getJSONArray("req").getJSONArray(0);
assertEquals(0, r.getInt(0));
assertTrue(Arrays.asList(new String[] { "any", "all" }).contains(r.getString(1)));
assertEquals(1, r.getJSONArray(2).length());
assertEquals(0, r.getJSONArray(2).getInt(0));
Model opt = mm.byName("Basic (optional reversed card)");
reqSize(opt);
r = opt.getJSONArray("req").getJSONArray(0);
assertTrue(Arrays.asList(new String[] { "any", "all" }).contains(r.getString(1)));
assertEquals(1, r.getJSONArray(2).length());
assertEquals(0, r.getJSONArray(2).getInt(0));
assertEquals(new JSONArray("[1,\"all\",[1,2]]"), opt.getJSONArray("req").getJSONArray(1));
// testing any
opt.getJSONArray("tmpls").getJSONObject(1).put("qfmt", "{{Back}}{{Add Reverse}}");
mm.save(opt, true);
assertEquals(new JSONArray("[1, \"any\", [1, 2]]"), opt.getJSONArray("req").getJSONArray(1));
// testing null
opt.getJSONArray("tmpls").getJSONObject(1).put("qfmt", "{{^Add Reverse}}{{/Add Reverse}}");
mm.save(opt, true);
assertEquals(new JSONArray("[1, \"none\", []]"), opt.getJSONArray("req").getJSONArray(1));
opt = mm.byName("Basic (type in the answer)");
reqSize(opt);
r = opt.getJSONArray("req").getJSONArray(0);
assertTrue(Arrays.asList(new String[] { "any", "all" }).contains(r.getString(1)));
// TODO: Port anki@4e33775ed4346ef136ece6ef5efec5ba46057c6b
assertEquals(new JSONArray("[0]"), r.getJSONArray(2));
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.
the class AbstractFlashcardViewerTest method noAutomaticAnswerAfterRenderProcessGoneAndPaused_issue9632.
@Test
public void noAutomaticAnswerAfterRenderProcessGoneAndPaused_issue9632() {
ActivityController<NonAbstractFlashcardViewer> controller = getViewerController(true);
NonAbstractFlashcardViewer viewer = controller.get();
viewer.mAutomaticAnswer = new AutomaticAnswer(viewer, new AutomaticAnswerSettings(AutomaticAnswerAction.BURY_CARD, true, 5, 5));
viewer.executeCommand(ViewerCommand.COMMAND_SHOW_ANSWER);
assertThat("messages after flipping card", viewer.hasAutomaticAnswerQueued(), equalTo(true));
controller.pause();
assertThat("disabled after pause", viewer.mAutomaticAnswer.isDisabled(), is(true));
assertThat("no auto answer after pause", viewer.hasAutomaticAnswerQueued(), equalTo(false));
viewer.mOnRenderProcessGoneDelegate.onRenderProcessGone(viewer.getWebView(), mock(RenderProcessGoneDetail.class));
assertThat("no auto answer after onRenderProcessGone when paused", viewer.hasAutomaticAnswerQueued(), equalTo(false));
}
Aggregations