use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class AbstractSchedTest method siblingCorrectlyBuried.
@Test
public void siblingCorrectlyBuried() {
// #6903
Collection col = getCol();
AbstractSched sched = col.getSched();
Models models = col.getModels();
DeckConfig dconf = col.getDecks().getConf(1);
dconf.getJSONObject("new").put("bury", true);
final int nbNote = 2;
Note[] notes = new Note[nbNote];
for (int i = 0; i < nbNote; i++) {
Note note = addNoteUsingBasicAndReversedModel("front", "back");
notes[i] = note;
}
col.reset();
for (int i = 0; i < nbNote; i++) {
Card card = sched.getCard();
assertArrayEquals(new int[] { nbNote * 2 - i, 0, 0 }, sched.counts(card));
assertEquals(notes[i].firstCard().getId(), card.getId());
assertEquals(Consts.QUEUE_TYPE_NEW, card.getQueue());
sched.answerCard(card, sched.answerButtons(card));
}
Card card = sched.getCard();
assertNull(card);
}
use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_ordcycleV2.
@Test
public void test_ordcycleV2() throws Exception {
Collection col = getColV2();
// add two more templates and set second active
Model m = col.getModels().current();
Models mm = col.getModels();
JSONObject t = mm.newTemplate("Reverse");
t.put("qfmt", "{{Back}}");
t.put("afmt", "{{Front}}");
mm.addTemplateModChanged(m, t);
t = mm.newTemplate("f2");
t.put("qfmt", "{{Front}}");
t.put("afmt", "{{Back}}");
mm.addTemplateModChanged(m, t);
mm.save(m);
// create a new note; it should have 3 cards
Note note = col.newNote();
note.setItem("Front", "1");
note.setItem("Back", "1");
col.addNote(note);
assertEquals(3, col.cardCount());
col.reset();
// ordinals should arrive in order
AbstractSched sched = col.getSched();
Card c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(0, c.getOrd());
c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(1, c.getOrd());
c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(2, c.getOrd());
}
use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_ordcycleV1.
@Test
public void test_ordcycleV1() throws Exception {
Collection col = getColV1();
// add two more templates and set second active
Model m = col.getModels().current();
Models mm = col.getModels();
JSONObject t = mm.newTemplate("Reverse");
t.put("qfmt", "{{Back}}");
t.put("afmt", "{{Front}}");
mm.addTemplateModChanged(m, t);
t = mm.newTemplate("f2");
t.put("qfmt", "{{Front}}");
t.put("afmt", "{{Back}}");
mm.addTemplateModChanged(m, t);
mm.save(m);
// create a new note; it should have 3 cards
Note note = col.newNote();
note.setItem("Front", "1");
note.setItem("Back", "1");
col.addNote(note);
assertEquals(3, col.cardCount());
col.reset();
// ordinals should arrive in order
AbstractSched sched = col.getSched();
Card c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(0, c.getOrd());
c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(1, c.getOrd());
c = sched.getCard();
// not upstream. But we are not expecting multiple getCard without review
sched.answerCard(c, sched.answerButtons(c) - 1);
assertEquals(2, c.getOrd());
}
use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class ModelTest method test_cloze_ordinals.
@Test
public void test_cloze_ordinals() throws ConfirmModSchemaException {
Collection col = getCol();
col.getModels().setCurrent(col.getModels().byName("Cloze"));
Model m = col.getModels().current();
Models mm = col.getModels();
// We replace the default Cloze template
JSONObject t = Models.newTemplate("ChainedCloze");
t.put("qfmt", "{{text:cloze:Text}}");
t.put("afmt", "{{text:cloze:Text}}");
mm.addTemplateModChanged(m, t);
mm.save(m);
col.getModels().remTemplate(m, m.getJSONArray("tmpls").getJSONObject(0));
Note note = col.newNote();
note.setItem("Text", "{{c1::firstQ::firstA}}{{c2::secondQ::secondA}}");
col.addNote(note);
assertEquals(2, col.cardCount());
List<Card> cards = note.cards();
assertEquals(2, cards.size());
Card c = cards.get(0);
Card c2 = cards.get(1);
// first card should have first ord
assertEquals(0, c.getOrd());
assertEquals(1, c2.getOrd());
}
use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class ModelTest method test_modelChange.
@Test
public void test_modelChange() throws ConfirmModSchemaException {
Collection col = getCol();
Model cloze = col.getModels().byName("Cloze");
// enable second template and add a note
Model m = col.getModels().current();
Models mm = col.getModels();
JSONObject t = Models.newTemplate("Reverse");
t.put("qfmt", "{{Back}}");
t.put("afmt", "{{Front}}");
mm.addTemplateModChanged(m, t);
mm.save(m);
Model basic = m;
Note note = col.newNote();
note.setItem("Front", "note");
note.setItem("Back", "b123");
col.addNote(note);
// switch fields
Map<Integer, Integer> map = new HashMap<>();
map.put(0, 1);
map.put(1, 0);
col.getModels().change(basic, new long[] { note.getId() }, basic, map, null);
note.load();
assertEquals("b123", note.getItem("Front"));
assertEquals("note", note.getItem("Back"));
// switch cards
Card c0 = note.cards().get(0);
Card c1 = note.cards().get(1);
assertThat(c0.q(), containsString("b123"));
assertThat(c1.q(), containsString("note"));
assertEquals(0, c0.getOrd());
assertEquals(1, c1.getOrd());
col.getModels().change(basic, new long[] { note.getId() }, basic, null, map);
note.load();
c0.load();
c1.load();
assertThat(c0.q(), containsString("note"));
assertThat(c1.q(), containsString("b123"));
assertEquals(1, c0.getOrd());
assertEquals(0, c1.getOrd());
// .cards() returns cards in order
assertEquals(c1.getId(), note.cards().get(0).getId());
// delete first card
map = new HashMap<>();
map.put(0, null);
map.put(1, 1);
// if (isWin) {
// // The low precision timer on Windows reveals a race condition
// time.sleep(0.05);
// }
col.getModels().change(basic, new long[] { note.getId() }, basic, null, map);
note.load();
c0.load();
// the card was deleted
// but we have two cards, as a new one was generated
assertEquals(2, note.numberOfCards());
// an unmapped field becomes blank
assertEquals("b123", note.getItem("Front"));
assertEquals("note", note.getItem("Back"));
col.getModels().change(basic, new long[] { note.getId() }, basic, map, null);
note.load();
assertEquals("", note.getItem("Front"));
assertEquals("note", note.getItem("Back"));
// another note to try model conversion
note = col.newNote();
note.setItem("Front", "f2");
note.setItem("Back", "b2");
col.addNote(note);
// counts = col.getModels().all_use_counts();
// Using older version of the test
assertEquals(2, col.getModels().useCount(basic));
assertEquals(0, col.getModels().useCount(cloze));
// Identity map
map = new HashMap<>();
map.put(0, 0);
map.put(1, 1);
col.getModels().change(basic, new long[] { note.getId() }, cloze, map, map);
note.load();
assertEquals("f2", note.getItem("Text"));
assertEquals(2, note.numberOfCards());
// back the other way, with deletion of second ord
col.getModels().remTemplate(basic, basic.getJSONArray("tmpls").getJSONObject(1));
assertEquals(2, col.getDb().queryScalar("select count() from cards where nid = ?", note.getId()));
map = new HashMap<>();
map.put(0, 0);
col.getModels().change(cloze, new long[] { note.getId() }, basic, map, map);
assertEquals(1, col.getDb().queryScalar("select count() from cards where nid = ?", note.getId()));
}
Aggregations