use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_new_v2.
@Test
public void test_new_v2() throws Exception {
Collection col = getColV2();
col.reset();
assertEquals(0, col.getSched().counts()[0]);
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
col.reset();
assertEquals(1, col.getSched().counts()[0]);
// fetch it
Card c = col.getSched().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, 1);
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 = col.getSched().getCard()
// assertTrue(qs[n] in c.q())
// col.getSched().answerCard(c, 2)
// }
}
use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_new_v1.
public void test_new_v1() throws Exception {
Collection col = getColV1();
col.reset();
assertEquals(0, col.getSched().newDue());
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
col.reset();
assertEquals(1, col.getSched().counts()[0]);
// fetch it
Card c = col.getSched().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, 1);
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 = col.getSched().getCard()
// assertTrue(qs[n] in c.q())
// col.getSched().answerCard(c, 2)
// }
}
use of com.ichi2.libanki.Models in project Anki-Android by ankidroid.
the class SchedTest method test_new_v1.
public void test_new_v1() throws Exception {
Collection col = getColV1();
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().counts().getNew());
// 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, 2)
// }
}
use of com.ichi2.libanki.Models in project Anki-Android by ankidroid.
the class ModelTest method bigQuery.
@Test
public void bigQuery() {
assumeTrue("This test is flaky on API29, ignoring", Build.VERSION.SDK_INT != Build.VERSION_CODES.Q);
ModelManager models = mTestCol.getModels();
Model model = models.all().get(0);
final String testString = "test";
final int size = testString.length() * 1024 * 1024;
StringBuilder buf = new StringBuilder((int) (size * 1.01));
// * 1.01 for padding
for (int i = 0; i < 1024 * 1024; ++i) {
buf.append(testString);
}
model.put(testString, buf.toString());
// Buf should be more than 4MB, so at least two chunks from database.
models.flush();
// Reload models
mTestCol.load();
Model newModel = models.all().get(0);
assertEquals(newModel, model);
}
use of com.ichi2.libanki.Models in project Anki-Android by ankidroid.
the class Collection method addNote.
/**
* Add a note and cards to the collection. If allowEmpty, at least one card is generated.
* @param note The note to add to the collection
* @param allowEmpty Whether we accept to add it even if it should generate no card. Useful to import note even if buggy
* @return Number of card added
*/
public int addNote(@NonNull Note note, Models.AllowEmpty allowEmpty) {
// check we have card models available, then save
ArrayList<JSONObject> cms = findTemplates(note, allowEmpty);
// Todo: upstream, we accept to add a not even if it generates no card. Should be ported to ankidroid
if (cms.isEmpty()) {
return 0;
}
note.flush();
// deck conf governs which of these are used
int due = nextID("pos");
// add cards
int ncards = 0;
for (JSONObject template : cms) {
_newCard(note, template, due);
ncards += 1;
}
return ncards;
}
Aggregations