Search in sources :

Example 76 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedV2Test method test_button_spacingV2.

@Test
public void test_button_spacingV2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    // 1 day ivl review card due now
    Card c = note.cards().get(0);
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setDue(col.getSched().getToday());
    c.setReps(1);
    c.setIvl(1);
    c.startTimer();
    c.flush();
    col.reset();
    // Upstream, there is no space in 2d
    assertEquals("2 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, BUTTON_TWO)));
    assertEquals("3 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, BUTTON_THREE)));
    assertEquals("4 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, BUTTON_FOUR)));
    // if hard factor is <= 1, then hard may not increase
    DeckConfig conf = col.getDecks().confForDid(1);
    conf.getJSONObject("rev").put("hardFactor", 1);
    col.getDecks().save(conf);
    assertEquals("1 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, BUTTON_TWO)));
}
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 77 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedV2Test method test_learn_collapsedV2.

@Test
public void test_learn_collapsedV2() throws Exception {
    Collection col = getColV2();
    // add 2 notes
    Note note = col.newNote();
    note.setItem("Front", "1");
    col.addNote(note);
    note = col.newNote();
    note.setItem("Front", "2");
    col.addNote(note);
    // set as a learn card and rebuild queues
    col.getDb().execute("update cards set queue=0, type=0");
    col.reset();
    // should get '1' first
    Card c = getCard();
    assertTrue(c.q().endsWith("1"));
    // pass it so it's due in 10 minutes
    col.getSched().answerCard(c, BUTTON_THREE);
    // get the other card
    c = getCard();
    assertTrue(c.q().endsWith("2"));
    // fail it so it's due in 1 minute
    col.getSched().answerCard(c, BUTTON_ONE);
    // we shouldn't get the same card again
    c = getCard();
    assertFalse(c.q().endsWith("2"));
}
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 78 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedV2Test method test_filt_keep_lrn_state.

@Test
public void test_filt_keep_lrn_state() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    // fail the card outside filtered deck
    Card c = getCard();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 10, 61 }));
    col.getDecks().save(conf);
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(CARD_TYPE_LRN, c.getQueue());
    assertEquals(QUEUE_TYPE_LRN, c.getType());
    assertEquals(3003, c.getLeft());
    col.getSched().answerCard(c, BUTTON_THREE);
    assertEquals(CARD_TYPE_LRN, c.getQueue());
    assertEquals(QUEUE_TYPE_LRN, c.getType());
    // create a dynamic deck and refresh it
    long did = addDynamicDeck("Cram");
    col.getSched().rebuildDyn(did);
    col.reset();
    // card should still be in learning state
    c.load();
    assertEquals(CARD_TYPE_LRN, c.getQueue());
    assertEquals(QUEUE_TYPE_LRN, c.getType());
    assertEquals(2002, c.getLeft());
    // should be able to advance learning steps
    col.getSched().answerCard(c, BUTTON_THREE);
    // should be due at least an hour in the future
    assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(60 * 60L)));
    // emptying the deck preserves learning state
    col.getSched().emptyDyn(did);
    c.load();
    assertEquals(CARD_TYPE_LRN, c.getQueue());
    assertEquals(QUEUE_TYPE_LRN, c.getType());
    assertEquals(1001, c.getLeft());
    assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(60 * 60L)));
}
Also used : Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) 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 79 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedV2Test method test_negativeDueFilter.

// cards with a due date earlier than the collection should retain
// their due date when removed
@Test
public void test_negativeDueFilter() throws Exception {
    Collection col = getColV2();
    // card due prior to collection date
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    Card c = note.cards().get(0);
    c.setDue(-5);
    c.setQueue(QUEUE_TYPE_REV);
    c.setIvl(5);
    c.flush();
    // into and out of filtered deck
    long did = addDynamicDeck("Cram");
    col.getSched().rebuildDyn(did);
    col.getSched().emptyDyn(did);
    col.reset();
    c.load();
    assertEquals(-5, c.getDue());
}
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 80 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedV2Test method test_preview.

@Test
public void test_preview() throws Exception {
    // add cards
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    Card orig = c.clone();
    Note note2 = col.newNote();
    note2.setItem("Front", "two");
    col.addNote(note2);
    // cram deck
    long did = addDynamicDeck("Cram");
    Deck cram = col.getDecks().get(did);
    cram.put("resched", false);
    col.getDecks().save(cram);
    col.getSched().rebuildDyn(did);
    col.reset();
    // grab the first card
    c = getCard();
    assertEquals(2, col.getSched().answerButtons(c));
    assertEquals(600, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(0, col.getSched().nextIvl(c, BUTTON_TWO));
    // failing it will push its due time back
    long due = c.getDue();
    col.getSched().answerCard(c, BUTTON_ONE);
    assertNotEquals(c.getDue(), due);
    // the other card should come next
    Card c2 = getCard();
    assertNotEquals(c2.getId(), c.getId());
    // passing it will remove it
    col.getSched().answerCard(c2, BUTTON_TWO);
    assertEquals(QUEUE_TYPE_NEW, c2.getQueue());
    assertEquals(0, c2.getReps());
    assertEquals(CARD_TYPE_NEW, c2.getType());
    // the other card should appear again
    c = getCard();
    assertEquals(orig.getId(), c.getId());
    // emptying the filtered deck should restore card
    col.getSched().emptyDyn(did);
    c.load();
    assertEquals(QUEUE_TYPE_NEW, c.getQueue());
    assertEquals(0, c.getReps());
    assertEquals(CARD_TYPE_NEW, c.getType());
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)58 Collection (com.ichi2.libanki.Collection)57 Card (com.ichi2.libanki.Card)55 Note (com.ichi2.libanki.Note)52 RobolectricTest (com.ichi2.anki.RobolectricTest)51 JSONObject (com.ichi2.utils.JSONObject)25 DeckConfig (com.ichi2.libanki.DeckConfig)20 JSONArray (com.ichi2.utils.JSONArray)16 ArrayList (java.util.ArrayList)16 Cursor (android.database.Cursor)14 Deck (com.ichi2.libanki.Deck)10 ContentResolver (android.content.ContentResolver)6 ContentValues (android.content.ContentValues)6 Uri (android.net.Uri)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 SuppressLint (android.annotation.SuppressLint)5 FileNotFoundException (java.io.FileNotFoundException)5 Activity (android.app.Activity)4 WebView (android.webkit.WebView)4