Search in sources :

Example 56 with Counts

use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.

the class SchedTest method test_deckFlowV1.

@Test
public void test_deckFlowV1() throws Exception {
    Collection col = getColV1();
    // add a note with default deck
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    // and one that's a child
    note = col.newNote();
    note.setItem("Front", "two");
    JSONObject default1 = note.model().put("did", col.getDecks().id("Default::2"));
    col.addNote(note);
    // and another that's higher up
    note = col.newNote();
    note.setItem("Front", "three");
    default1 = note.model().put("did", col.getDecks().id("Default::1"));
    col.addNote(note);
    // should get top level one first, then ::1, then ::2
    col.reset();
    assertArrayEquals(new int[] { 3, 0, 0 }, col.getSched().counts());
    for (String i : new String[] { "one", "three", "two" }) {
        Card c = col.getSched().getCard();
        assertEquals(c.note().getItem("Front"), i);
        col.getSched().answerCard(c, 2);
    }
}
Also used : JSONObject(com.ichi2.utils.JSONObject) Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Matchers.containsString(org.hamcrest.Matchers.containsString) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 57 with Counts

use of com.ichi2.libanki.sched.Counts 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());
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 58 with Counts

use of com.ichi2.libanki.sched.Counts 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()));
}
Also used : JSONObject(com.ichi2.utils.JSONObject) HashMap(java.util.HashMap) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 59 with Counts

use of com.ichi2.libanki.sched.Counts in project Anki-Android by ankidroid.

the class SchedV2Test method test_bury.

@Test
public void test_bury() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    note = col.newNote();
    note.setItem("Front", "two");
    col.addNote(note);
    Card c2 = note.cards().get(0);
    // burying
    col.getSched().buryCards(new long[] { c.getId() }, true);
    c.load();
    assertEquals(QUEUE_TYPE_MANUALLY_BURIED, c.getQueue());
    col.getSched().buryCards(new long[] { c2.getId() }, false);
    c2.load();
    assertEquals(QUEUE_TYPE_SIBLING_BURIED, c2.getQueue());
    col.reset();
    assertNull(getCard());
    col.getSched().unburyCardsForDeck(AbstractSched.UnburyType.MANUAL);
    c.load();
    assertEquals(QUEUE_TYPE_NEW, c.getQueue());
    c2.load();
    assertEquals(QUEUE_TYPE_SIBLING_BURIED, c2.getQueue());
    col.getSched().unburyCardsForDeck(AbstractSched.UnburyType.SIBLINGS);
    c2.load();
    assertEquals(QUEUE_TYPE_NEW, c2.getQueue());
    col.getSched().buryCards(new long[] { c.getId(), c2.getId() });
    col.getSched().unburyCardsForDeck(AbstractSched.UnburyType.ALL);
    col.reset();
    assertEquals(new Counts(2, 0, 0), col.getSched().counts());
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 60 with Counts

use of com.ichi2.libanki.sched.Counts in project Anki-Android by ankidroid.

the class SchedV2Test method test_repCountsV2.

@Test
public void test_repCountsV2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    col.reset();
    // lrnReps should be accurate on pass/fail
    assertEquals(new Counts(1, 0, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_ONE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_ONE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_THREE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_ONE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_THREE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_THREE);
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    note = col.newNote();
    note.setItem("Front", "two");
    col.addNote(note);
    col.reset();
    // initial pass should be correct too
    col.getSched().answerCard(getCard(), BUTTON_THREE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_ONE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_FOUR);
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    // immediate graduate should work
    note = col.newNote();
    note.setItem("Front", "three");
    col.addNote(note);
    col.reset();
    col.getSched().answerCard(getCard(), BUTTON_FOUR);
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    // and failing a review should too
    note = col.newNote();
    note.setItem("Front", "three");
    col.addNote(note);
    Card c = note.cards().get(0);
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setDue(col.getSched().getToday());
    c.flush();
    col.reset();
    assertEquals(new Counts(0, 0, 1), col.getSched().counts());
    col.getSched().answerCard(getCard(), BUTTON_ONE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

Collection (com.ichi2.libanki.Collection)47 Card (com.ichi2.libanki.Card)43 Test (org.junit.Test)39 RobolectricTest (com.ichi2.anki.RobolectricTest)38 Note (com.ichi2.libanki.Note)38 Deck (com.ichi2.libanki.Deck)12 DeckConfig (com.ichi2.libanki.DeckConfig)11 JSONArray (com.ichi2.utils.JSONArray)11 JSONObject (com.ichi2.utils.JSONObject)10 JSONException (com.ichi2.utils.JSONException)6 HashMap (java.util.HashMap)6 Resources (android.content.res.Resources)4 Nullable (androidx.annotation.Nullable)4 Model (com.ichi2.libanki.Model)4 AbstractDeckTreeNode (com.ichi2.libanki.sched.AbstractDeckTreeNode)4 IOException (java.io.IOException)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 JSONObject (org.json.JSONObject)4 Cursor (android.database.Cursor)3 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)3