Search in sources :

Example 31 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project AnkiChinaAndroid by ankichinateam.

the class SchedV2Test method test_finishedV2.

@Test
public void test_finishedV2() throws Exception {
    Collection col = getColV2();
    // nothing due
    assertThat(col.getSched().finishedMsg(getTargetContext()).toString(), containsString("Congratulations"));
    assertThat(col.getSched().finishedMsg(getTargetContext()).toString(), not(containsString("limit")));
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    // have a new card
    assertThat(col.getSched().finishedMsg(getTargetContext()).toString(), containsString("new cards available"));
    // turn it into a review
    col.reset();
    Card c = note.cards().get(0);
    c.startTimer();
    col.getSched().answerCard(c, 3);
    // nothing should be due tomorrow, as it's due in a week
    assertThat(col.getSched().finishedMsg(getTargetContext()).toString(), containsString("Congratulations"));
    assertThat(col.getSched().finishedMsg(getTargetContext()).toString(), not(containsString("limit")));
}
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 32 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project AnkiChinaAndroid by ankichinateam.

the class ImportUtilsTest method fileNamesAreLimitedTo100Chars.

@Test
public void fileNamesAreLimitedTo100Chars() {
    // #6137 - We URLEncode due to the above. Therefore: 好 -> %E5%A5%BD
    // This caused filenames to be too long.
    String inputFileName = "好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好好.apkg";
    String actualFilePath = importValidFile(inputFileName);
    assertThat(actualFilePath, endsWith(".apkg"));
    assertThat(actualFilePath, containsString("..."));
    // Obtain the filename from the path
    assertThat(actualFilePath, containsString("%E5%A5%BD"));
    String fileName = actualFilePath.substring(actualFilePath.indexOf("%E5%A5%BD"));
    assertThat(fileName.length(), lessThanOrEqualTo(100));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 33 with DUE

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

the class SchedV2Test method test_learnV2.

@Test
public void test_learnV2() throws Exception {
    Collection col = getColV2();
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    // set as a learn card and rebuild queues
    col.getDb().execute("update cards set queue=0, type=0");
    col.reset();
    // sched.getCard should return it, since it's due in the past
    Card c = getCard();
    assertNotNull(c);
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 0.5, 3, 10 }));
    col.getDecks().save(conf);
    // fail it
    col.getSched().answerCard(c, BUTTON_ONE);
    // it should have three reps left to graduation
    assertEquals(3, c.getLeft() % 1000);
    assertEquals(3, c.getLeft() / 1000);
    // it should be due in 30 seconds
    long t = Math.round(c.getDue() - col.getTime().intTime());
    assertThat(t, is(greaterThanOrEqualTo(25L)));
    assertThat(t, is(lessThanOrEqualTo(40L)));
    // pass it once
    col.getSched().answerCard(c, BUTTON_THREE);
    // it should be due in 3 minutes
    long dueIn = c.getDue() - col.getTime().intTime();
    assertThat(dueIn, is(greaterThanOrEqualTo(178L)));
    assertThat(dueIn, is(lessThanOrEqualTo((long) (180 * 1.25))));
    assertEquals(2, c.getLeft() % 1000);
    assertEquals(2, c.getLeft() / 1000);
    // check log is accurate
    Cursor log = col.getDb().getDatabase().query("select * from revlog order by id desc");
    assertTrue(log.moveToFirst());
    assertEquals(3, log.getInt(3));
    assertEquals(-180, log.getInt(4));
    assertEquals(-30, log.getInt(5));
    // pass again
    col.getSched().answerCard(c, BUTTON_THREE);
    // it should be due in 10 minutes
    dueIn = c.getDue() - col.getTime().intTime();
    assertThat(dueIn, is(greaterThanOrEqualTo(599L)));
    assertThat(dueIn, is(lessThanOrEqualTo((long) (600 * 1.25))));
    assertEquals(1, c.getLeft() % 1000);
    assertEquals(1, c.getLeft() / 1000);
    // the next pass should graduate the card
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    assertEquals(CARD_TYPE_LRN, c.getType());
    col.getSched().answerCard(c, BUTTON_THREE);
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    assertEquals(CARD_TYPE_REV, c.getType());
    // should be due tomorrow, with an interval of 1
    assertEquals(col.getSched().getToday() + 1, c.getDue());
    assertEquals(1, c.getIvl());
    // or normal removal
    c.setType(CARD_TYPE_NEW);
    c.setQueue(QUEUE_TYPE_LRN);
    col.getSched().answerCard(c, BUTTON_FOUR);
    assertEquals(CARD_TYPE_REV, c.getType());
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    assertTrue(checkRevIvl(col, c, 4));
    // revlog should have been updated each time
    assertEquals(5, col.getDb().queryScalar("select count() from revlog where type = 0"));
}
Also used : Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) Cursor(android.database.Cursor) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 34 with DUE

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

the class SchedV2Test method test_suspendv2.

@Test
public void test_suspendv2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    // suspending
    col.reset();
    assertNotNull(getCard());
    col.getSched().suspendCards(new long[] { c.getId() });
    col.reset();
    assertNull(getCard());
    // unsuspending
    col.getSched().unsuspendCards(new long[] { c.getId() });
    col.reset();
    assertNotNull(getCard());
    // should cope with rev cards being relearnt
    c.setDue(0);
    c.setIvl(100);
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.flush();
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    assertThat(c.getDue(), is(greaterThanOrEqualTo(col.getTime().intTime())));
    long due = c.getDue();
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    assertEquals(CARD_TYPE_RELEARNING, c.getType());
    col.getSched().suspendCards(new long[] { c.getId() });
    col.getSched().unsuspendCards(new long[] { c.getId() });
    c.load();
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    assertEquals(CARD_TYPE_RELEARNING, c.getType());
    assertEquals(due, c.getDue());
    // should cope with cards in cram decks
    c.setDue(1);
    c.flush();
    addDynamicDeck("tmp");
    col.getSched().rebuildDyn();
    c.load();
    assertNotEquals(1, c.getDue());
    assertNotEquals(1, c.getDid());
    col.getSched().suspendCards(new long[] { c.getId() });
    c.load();
    assertNotEquals(1, c.getDue());
    assertNotEquals(1, c.getDid());
    assertEquals(1, c.getODue());
}
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 35 with DUE

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

the class SchedV2Test method filteredDeckSchedulingOptionsRegressionTest.

/**
 * Reported by /u/CarelessSecretary9 on reddit:
 */
@Test
public void filteredDeckSchedulingOptionsRegressionTest() {
    Collection col = getCol();
    col.setCrt(1587852900L);
    // 30 minutes learn ahead. required as we have 20m delay
    col.set_config("collapseTime", 1800);
    long homeDeckId = addDeck("Poorretention");
    DeckConfig homeDeckConf = col.getDecks().confForDid(homeDeckId);
    JSONObject lapse = homeDeckConf.getJSONObject("lapse");
    lapse.put("minInt", 2);
    lapse.put("mult", 0.7d);
    lapse.put("delays", new JSONArray("[20]"));
    col.getDecks().save(homeDeckConf);
    ensureLapseMatchesSppliedAnkiDesktopConfig(lapse);
    col.flush();
    long dynId = addDynamicDeck("Dyn");
    /*
        >>> pp(self.reviewer.card)
        {'data': '', 'did': 1587939535230, 'due': 0, 'factor': 1300, 'flags': 0, 'id': 1510928829863, 'ivl': 25,
        'lapses': 5, 'left': 1004, 'mod': 1587921512, 'nid': 1510928805161, 'odid': 1587920944107,
        'odue': 0, 'ord': 0, 'queue': 2, 'reps': 22, 'type': 2, 'usn': -1}

         */
    Note n = addNoteUsingBasicModel("Hello", "World");
    Card c = getOnlyElement(n.cards());
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setIvl(25);
    c.setDue(0);
    c.setLapses(5);
    c.setFactor(1300);
    c.setLeft(1004);
    c.setODid(homeDeckId);
    c.setDid(dynId);
    c.flush();
    SchedV2 v2 = new SchedV2(col);
    Card schedCard = v2.getCard();
    assertThat(schedCard, Matchers.notNullValue());
    v2.answerCard(schedCard, BUTTON_ONE);
    assertThat("The lapsed card should now be counted as lrn", v2.mLrnCount, is(1));
    Card after = v2.getCard();
    assertThat("A card should be returned ", after, Matchers.notNullValue());
    /* Data from Anki - pp(self.reviewer.card)
        {'data': '', 'did': 1587939535230, 'due': 1587941137, 'factor': 1300,
        'flags': 0, 'id': 1510928829863, 'ivl': 17, 'lapses': 6, 'left': 1001,
        'mod': 1587939720, 'nid': 1510928805161, 'odid': 1587920944107, 'odue': 0,
        'ord': 0, 'queue': 1, 'reps': 23, 'type': 3, 'usn': -1}
         */
    assertThat(after.getType(), is(Consts.CARD_TYPE_RELEARNING));
    assertThat(after.getQueue(), is(Consts.QUEUE_TYPE_LRN));
    assertThat(after.getLeft(), is(1001));
    assertThat("ivl is reduced by 70%", after.getIvl(), is(17));
    assertThat("One lapse is added", after.getLapses(), is(6));
    assertThat(v2.answerButtons(after), is(4));
    long one = v2.nextIvl(after, BUTTON_ONE);
    long two = v2.nextIvl(after, BUTTON_TWO);
    long three = v2.nextIvl(after, BUTTON_THREE);
    long four = v2.nextIvl(after, BUTTON_FOUR);
    // 20 mins
    assertThat("Again should pick the current step", one, is(1200L));
    // 30 mins
    assertThat("Repeating single step - 20 minutes * 1.5", two, is(1800L));
    // 17 days
    assertThat("Good should take the reduced interval (25 * 0.7)", three, is(1468800L));
    // 18 days
    assertThat("Easy should have a bonus day over good", four, is(1555200L));
}
Also used : JSONObject(com.ichi2.utils.JSONObject) 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)

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