Search in sources :

Example 81 with Deck

use of com.ichi2.libanki.Deck in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method test_newLimits_V2.

@Test
public void test_newLimits_V2() throws Exception {
    Collection col = getColV2();
    // add some notes
    long deck2 = col.getDecks().id("Default::foo");
    for (int i = 0; i < 30; i++) {
        Note note = col.newNote();
        note.setItem("Front", Integer.toString(i));
        if (i > 4) {
            note.model().put("did", deck2);
        }
        col.addNote(note);
    }
    // give the child deck a different configuration
    long c2 = col.getDecks().confId("new conf");
    col.getDecks().setConf(col.getDecks().get(deck2), c2);
    col.reset();
    // both confs have defaulted to a limit of 20
    assertEquals(20, col.getSched().counts()[0]);
    // first card we get comes from parent
    Card c = col.getSched().getCard();
    assertEquals(1, c.getDid());
    // limit the parent to 10 cards, meaning we get 10 in total
    DeckConfig conf1 = col.getDecks().confForDid(1);
    conf1.getJSONObject("new").put("perDay", 10);
    col.getDecks().save(conf1);
    col.reset();
    assertEquals(10, col.getSched().counts()[0]);
    // if we limit child to 4, we should get 9
    DeckConfig conf2 = col.getDecks().confForDid(deck2);
    conf2.getJSONObject("new").put("perDay", 4);
    col.getDecks().save(conf2);
    col.reset();
    assertEquals(9, col.getSched().counts()[0]);
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 82 with Deck

use of com.ichi2.libanki.Deck in project AnkiChinaAndroid by ankichinateam.

the class SchedTest method test_reorderV1.

@Test
public void test_reorderV1() throws Exception {
    Collection col = getColV1();
    // add a note with default deck
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Note note2 = col.newNote();
    note2.setItem("Front", "two");
    col.addNote(note2);
    assertEquals(2, note2.cards().get(0).getDue());
    boolean found = false;
    // 50/50 chance of being reordered
    for (int i = 0; i < 20; i++) {
        col.getSched().randomizeCards(1);
        if (note.cards().get(0).getDue() != note.getId()) {
            found = true;
            break;
        }
    }
    assertTrue(found);
    col.getSched().orderCards(1);
    assertEquals(1, note.cards().get(0).getDue());
    // shifting
    Note note3 = col.newNote();
    note3.setItem("Front", "three");
    col.addNote(note3);
    Note note4 = col.newNote();
    note4.setItem("Front", "four");
    col.addNote(note4);
    assertEquals(1, note.cards().get(0).getDue());
    assertEquals(2, note2.cards().get(0).getDue());
    assertEquals(3, note3.cards().get(0).getDue());
    assertEquals(4, note4.cards().get(0).getDue());
/* todo sortCard
           col.getSched().sortCards(new long [] {note3.cards().get(0).getId(), note4.cards().get(0).getId()}, start=1, shift=true);
           assertEquals(3, note.cards().get(0).getDue());
           assertEquals(4, note2.cards().get(0).getDue());
           assertEquals(1, note3.cards().get(0).getDue());
           assertEquals(2, note4.cards().get(0).getDue());
        */
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 83 with Deck

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

the class SchedV2Test method test_review_limits.

@Test
public void test_review_limits() throws Exception {
    Collection col = getColV2();
    Deck parent = col.getDecks().get(addDeck("parent"));
    Deck child = col.getDecks().get(addDeck("parent::child"));
    DeckConfig pconf = col.getDecks().getConf(col.getDecks().confId("parentConf"));
    DeckConfig cconf = col.getDecks().getConf(col.getDecks().confId("childConf"));
    pconf.getJSONObject("rev").put("perDay", 5);
    col.getDecks().updateConf(pconf);
    col.getDecks().setConf(parent, pconf.getLong("id"));
    cconf.getJSONObject("rev").put("perDay", 10);
    col.getDecks().updateConf(cconf);
    col.getDecks().setConf(child, cconf.getLong("id"));
    Model m = col.getModels().current();
    m.put("did", child.getLong("id"));
    col.getModels().save(m, false);
    // add some cards
    for (int i = 0; i < 20; i++) {
        Note note = col.newNote();
        note.setItem("Front", "one");
        note.setItem("Back", "two");
        col.addNote(note);
        // make them reviews
        Card c = note.cards().get(0);
        c.setQueue(QUEUE_TYPE_REV);
        c.setType(CARD_TYPE_REV);
        c.setDue(0);
        c.flush();
    }
    // position 0 is default deck. Different from upstream
    DeckDueTreeNode tree = col.getSched().deckDueTree().get(1);
    // (('parent', 1514457677462, 5, 0, 0, (('child', 1514457677463, 5, 0, 0, ()),)))
    assertEquals("parent", tree.getFullDeckName());
    // paren, tree.review_count)t
    assertEquals(5, tree.getRevCount());
    assertEquals(10, tree.getChildren().get(0).getRevCount());
    // .counts() should match
    col.getDecks().select(child.getLong("id"));
    col.reset();
    assertEquals(new Counts(0, 0, 10), col.getSched().counts());
    // answering a card in the child should decrement parent count
    Card c = getCard();
    col.getSched().answerCard(c, BUTTON_THREE);
    assertEquals(new Counts(0, 0, 9), col.getSched().counts());
    tree = col.getSched().deckDueTree().get(1);
    assertEquals(4, tree.getRevCount());
    assertEquals(9, tree.getChildren().get(0).getRevCount());
}
Also used : Note(com.ichi2.libanki.Note) Model(com.ichi2.libanki.Model) Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 84 with Deck

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

the class SchedV2Test method test_newLimits_V2.

@Test
public void test_newLimits_V2() throws Exception {
    Collection col = getColV2();
    // add some notes
    long deck2 = addDeck("Default::foo");
    for (int i = 0; i < 30; i++) {
        Note note = col.newNote();
        note.setItem("Front", Integer.toString(i));
        if (i > 4) {
            note.model().put("did", deck2);
        }
        col.addNote(note);
    }
    // give the child deck a different configuration
    long c2 = col.getDecks().confId("new conf");
    col.getDecks().setConf(col.getDecks().get(deck2), c2);
    col.reset();
    // both confs have defaulted to a limit of 20
    assertEquals(20, col.getSched().newCount());
    // first card we get comes from parent
    Card c = getCard();
    assertEquals(1, c.getDid());
    // limit the parent to 10 cards, meaning we get 10 in total
    DeckConfig conf1 = col.getDecks().confForDid(1);
    conf1.getJSONObject("new").put("perDay", 10);
    col.getDecks().save(conf1);
    col.reset();
    assertEquals(10, col.getSched().newCount());
    // if we limit child to 4, we should get 9
    DeckConfig conf2 = col.getDecks().confForDid(deck2);
    conf2.getJSONObject("new").put("perDay", 4);
    col.getDecks().save(conf2);
    col.reset();
    assertEquals(9, col.getSched().newCount());
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 85 with Deck

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

the class SchedTest method test_newLimits_V1.

@Test
public void test_newLimits_V1() throws Exception {
    Collection col = getColV1();
    // add some notes
    long deck2 = addDeck("Default::foo");
    Note note;
    for (int i = 0; i < 30; i++) {
        note = col.newNote();
        note.setItem("Front", Integer.toString(i));
        if (i > 4) {
            note.model().put("did", deck2);
        }
        col.addNote(note);
    }
    // give the child deck a different configuration
    long c2 = col.getDecks().confId("new conf");
    col.getDecks().setConf(col.getDecks().get(deck2), c2);
    col.reset();
    // both confs have defaulted to a limit of 20
    assertEquals("both confs have defaulted to a limit of 20", 20, col.getSched().counts().getNew());
    // first card we get comes from parent
    Card c = getCard();
    assertEquals(1, c.getDid());
    // limit the parent to 10 cards, meaning we get 10 in total
    DeckConfig conf1 = col.getDecks().confForDid(1);
    conf1.getJSONObject("new").put("perDay", 10);
    col.getDecks().save(conf1);
    col.reset();
    assertEquals(10, col.getSched().counts().getNew());
    // if we limit child to 4, we should get 9
    DeckConfig conf2 = col.getDecks().confForDid(deck2);
    conf2.getJSONObject("new").put("perDay", 4);
    col.getDecks().save(conf2);
    col.reset();
    assertEquals(9, col.getSched().counts().getNew());
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

Deck (com.ichi2.libanki.Deck)100 Collection (com.ichi2.libanki.Collection)97 JSONObject (com.ichi2.utils.JSONObject)88 Test (org.junit.Test)80 JSONArray (com.ichi2.utils.JSONArray)55 Card (com.ichi2.libanki.Card)53 Note (com.ichi2.libanki.Note)50 ArrayList (java.util.ArrayList)47 RobolectricTest (com.ichi2.anki.RobolectricTest)44 DeckConfig (com.ichi2.libanki.DeckConfig)37 JSONException (com.ichi2.utils.JSONException)34 NonNull (androidx.annotation.NonNull)30 HashMap (java.util.HashMap)29 Model (com.ichi2.libanki.Model)23 Map (java.util.Map)22 Intent (android.content.Intent)21 Resources (android.content.res.Resources)18 TextView (android.widget.TextView)18 SharedPreferences (android.content.SharedPreferences)17 Cursor (android.database.Cursor)17