use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.
the class CardTemplatePreviewerTest method testPreviewNormal.
@Test
public void testPreviewNormal() {
// Make sure we test previewing a new card template
String modelName = "Basic (and reversed card)";
Model collectionBasicModelOriginal = getCurrentDatabaseModelCopy(modelName);
Card testCard1 = getSavedCard(collectionBasicModelOriginal, 0);
Card testCard2 = getSavedCard(collectionBasicModelOriginal, 1);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("cardList", new long[] { testCard1.getId(), testCard2.getId() });
intent.putExtra("index", 0);
ActivityController<TestCardTemplatePreviewer> previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class, intent).create().start().resume().visible();
saveControllerForCleanup(previewerController);
// Take it through a destroy/re-create lifecycle in order to test instance state persistence
Bundle outBundle = new Bundle();
previewerController.saveInstanceState(outBundle);
previewerController.pause().stop().destroy();
previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class).create(outBundle).start().resume().visible();
saveControllerForCleanup((previewerController));
TestCardTemplatePreviewer testCardTemplatePreviewer = previewerController.get();
// Make sure we can click
Assert.assertFalse("Showing the answer already?", testCardTemplatePreviewer.getShowingAnswer());
testCardTemplatePreviewer.disableDoubleClickPrevention();
View showAnswerButton = testCardTemplatePreviewer.findViewById(R.id.preview_buttons_layout);
showAnswerButton.performClick();
Assert.assertTrue("Not showing the answer?", testCardTemplatePreviewer.getShowingAnswer());
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.
the class CardTemplatePreviewerTest method testPreviewUnsavedTemplate.
@Test
public void testPreviewUnsavedTemplate() {
String modelName = "Basic";
Model collectionBasicModelOriginal = getCurrentDatabaseModelCopy(modelName);
JSONObject template = collectionBasicModelOriginal.getJSONArray("tmpls").getJSONObject(0);
template.put("qfmt", template.getString("qfmt") + "PREVIEWER_TEST");
String tempModelPath = TemporaryModel.saveTempModel(getTargetContext(), collectionBasicModelOriginal);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(TemporaryModel.INTENT_MODEL_FILENAME, tempModelPath);
intent.putExtra("index", 0);
ActivityController<TestCardTemplatePreviewer> previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class, intent).create().start().resume().visible();
saveControllerForCleanup((previewerController));
TestCardTemplatePreviewer testCardTemplatePreviewer = previewerController.get();
Assert.assertTrue("model change did not show up?", testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).q().contains("PREVIEWER_TEST") && testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).a().contains("PREVIEWER_TEST"));
// Take it through a destroy/re-create lifecycle in order to test instance state persistence
Bundle outBundle = new Bundle();
previewerController.saveInstanceState(outBundle);
previewerController.pause().stop().destroy();
previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class).create(outBundle).start().resume().visible();
saveControllerForCleanup(previewerController);
testCardTemplatePreviewer = previewerController.get();
Assert.assertTrue("model change not preserved in lifecycle??", testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).q().contains("PREVIEWER_TEST") && testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).a().contains("PREVIEWER_TEST"));
// Make sure we can click
Assert.assertFalse("Showing the answer already?", testCardTemplatePreviewer.getShowingAnswer());
testCardTemplatePreviewer.disableDoubleClickPrevention();
View showAnswerButton = testCardTemplatePreviewer.findViewById(R.id.preview_buttons_layout);
showAnswerButton.performClick();
Assert.assertTrue("Not showing the answer?", testCardTemplatePreviewer.getShowingAnswer());
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.
the class CardTemplatePreviewerTest method testPreviewUnsavedTemplate_basic_answer.
@Test
@Config(qualifiers = "en")
public void testPreviewUnsavedTemplate_basic_answer() {
String modelName = "Basic (type in the answer)";
Model collectionBasicModelOriginal = getCurrentDatabaseModelCopy(modelName);
List<String> fields = collectionBasicModelOriginal.getFieldsNames();
JSONObject template = collectionBasicModelOriginal.getJSONArray("tmpls").getJSONObject(0);
template.put("qfmt", template.getString("qfmt") + "PREVIEWER_TEST");
String tempModelPath = TemporaryModel.saveTempModel(getTargetContext(), collectionBasicModelOriginal);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(TemporaryModel.INTENT_MODEL_FILENAME, tempModelPath);
intent.putExtra("index", 0);
ActivityController<TestCardTemplatePreviewer> previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class, intent).create().start().resume().visible();
saveControllerForCleanup((previewerController));
TestCardTemplatePreviewer testCardTemplatePreviewer = previewerController.get();
String[] arr = testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).note().getFields();
assertThat(arr[0], is("(" + fields.get(0) + ")"));
assertThat(arr[1], is(testCardTemplatePreviewer.getString(R.string.basic_answer_sample_text)));
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.
the class SchedV2Test method test_new_v2.
@Test
public void test_new_v2() throws Exception {
Collection col = getColV2();
col.reset();
assertEquals(0, col.getSched().newCount());
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
col.reset();
assertEquals(1, col.getSched().newCount());
// fetch it
Card c = getCard();
assertNotNull(c);
assertEquals(QUEUE_TYPE_NEW, c.getQueue());
assertEquals(CARD_TYPE_NEW, c.getType());
// if we answer it, it should become a learn card
long t = col.getTime().intTime();
col.getSched().answerCard(c, BUTTON_ONE);
assertEquals(QUEUE_TYPE_LRN, c.getQueue());
assertEquals(CARD_TYPE_LRN, c.getType());
assertThat(c.getDue(), is(greaterThanOrEqualTo(t)));
// disabled for now, as the learn fudging makes this randomly fail
// // the default order should ensure siblings are not seen together, and
// // should show all cards
// Model m = col.getModels().current(); Models mm = col.getModels()
// JSONObject t = mm.newTemplate("Reverse")
// t['qfmt'] = "{{Back}}"
// t['afmt'] = "{{Front}}"
// mm.addTemplateModChanged(m, t)
// mm.save(m)
// note = col.newNote()
// note['Front'] = u"2"; note['Back'] = u"2"
// col.addNote(note)
// note = col.newNote()
// note['Front'] = u"3"; note['Back'] = u"3"
// col.addNote(note)
// col.reset()
// qs = ("2", "3", "2", "3")
// for (int n = 0; n < 4; n++) {
// c = getCard()
// assertTrue(qs[n] in c.q())
// col.getSched().answerCard(c, BUTTON_TWO)
// }
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.
the class SchedV2Test method test_filt_reviewing_early_normal.
@Test
public void test_filt_reviewing_early_normal() throws Exception {
Collection col = getColV2();
Note note = col.newNote();
note.setItem("Front", "one");
col.addNote(note);
Card c = note.cards().get(0);
c.setIvl(100);
c.setQueue(QUEUE_TYPE_REV);
c.setType(CARD_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();
assertEquals(new Counts(0, 0, 0), col.getSched().counts());
// create a dynamic deck and refresh it
long did = addDynamicDeck("Cram");
col.getSched().rebuildDyn(did);
col.reset();
// should appear as normal in the deck list
/* todo sort
assertEquals(1, sorted(col.getSched().deckDueTree().getChildren())[0].review_count);
*/
// and should appear in the counts
assertEquals(new Counts(0, 0, 1), col.getSched().counts());
// grab it and check estimates
c = getCard();
assertEquals(4, col.getSched().answerButtons(c));
assertEquals(600, col.getSched().nextIvl(c, BUTTON_ONE));
assertEquals(Math.round(75 * 1.2) * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_TWO));
assertThat(col.getSched().nextIvl(c, BUTTON_THREE), is((long) (75 * 2.5) * SECONDS_PER_DAY));
assertThat(col.getSched().nextIvl(c, BUTTON_FOUR), is((long) (75 * 2.5 * 1.15) * SECONDS_PER_DAY));
// answer 'good'
col.getSched().answerCard(c, BUTTON_THREE);
checkRevIvl(col, c, 90);
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
assertEquals(0L, c.getODue());
// should not be in learning
assertEquals(QUEUE_TYPE_REV, c.getQueue());
// should be logged as a cram rep
assertEquals(3, col.getDb().queryLongScalar("select type from revlog order by id desc limit 1"));
// due in 75 days, so it's been waiting 25 days
c.setIvl(100);
c.setDue(col.getSched().getToday() + 75);
c.flush();
col.getSched().rebuildDyn(did);
col.reset();
c = getCard();
assertEquals(60 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_TWO));
assertEquals(100 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_THREE));
assertEquals(114 * SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_FOUR));
}
Aggregations