Search in sources :

Example 21 with Time

use of com.ichi2.libanki.utils.Time in project AnkiChinaAndroid by ankichinateam.

the class SchedTest method test_timingV1.

@Test
public void test_timingV1() throws Exception {
    Collection col = getColV1();
    // add a few review cards, due today
    for (int i = 0; i < 5; i++) {
        Note note = col.newNote();
        note.setItem("Front", "num" + i);
        col.addNote(note);
        Card c = note.cards().get(0);
        c.setType(CARD_TYPE_REV);
        c.setQueue(QUEUE_TYPE_REV);
        c.setDue(0);
        c.flush();
    }
    // fail the first one
    col.reset();
    Card c = col.getSched().getCard();
    // set a a fail delay of 4 seconds
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("lapse").getJSONArray("delays").put(0, 1 / 15.0);
    col.getDecks().save(conf);
    col.getSched().answerCard(c, 1);
    // the next card should be another review
    c = col.getSched().getCard();
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
/* TODO time
        // but if we wait for a few seconds, the failed card should come back
        orig_time = time.time;

        def adjusted_time():
        return orig_time() + 5;

        time.time = adjusted_time;
        c = col.getSched().getCard();
        assertEquals(QUEUE_TYPE_LRN, c.getQueue());
        time.time = orig_time;

        */
}
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 22 with Time

use of com.ichi2.libanki.utils.Time in project AnkiChinaAndroid by ankichinateam.

the class ReviewerTest method jsTime4ShouldBeBlankIfButtonUnavailable.

@Test
public void jsTime4ShouldBeBlankIfButtonUnavailable() {
    // #6623 - easy should be blank when displaying a card with 3 buttons (after displaying a review)
    Note firstNote = addNoteUsingBasicModel("Hello", "World");
    moveToReviewQueue(firstNote.firstCard());
    addNoteUsingBasicModel("Hello", "World2");
    Reviewer reviewer = startReviewer();
    JavaScriptFunction javaScriptFunction = reviewer.javaScriptFunction();
    // The answer needs to be displayed to be able to get the time.
    displayAnswer(reviewer);
    assertThat("4 buttons should be displayed", reviewer.getAnswerButtonCount(), is(4));
    String nextTime = javaScriptFunction.ankiGetNextTime4();
    assertThat(nextTime, not(isEmptyString()));
    // Display the next answer
    reviewer.answerCard(EASE_4);
    displayAnswer(reviewer);
    if (schedVersion == 1) {
        assertThat("The 4th button should not be visible", reviewer.getAnswerButtonCount(), is(3));
        String learnTime = javaScriptFunction.ankiGetNextTime4();
        assertThat("If the 4th button is not visible, there should be no time4 in JS", learnTime, isEmptyString());
    }
}
Also used : Note(com.ichi2.libanki.Note) JavaScriptFunction(com.ichi2.anki.AbstractFlashcardViewer.JavaScriptFunction) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test)

Example 23 with Time

use of com.ichi2.libanki.utils.Time in project AnkiChinaAndroid by ankichinateam.

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 = col.getSched().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, 1);
    // 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, 3);
    // 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, 3);
    // 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, 3);
    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, 4);
    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 24 with Time

use of com.ichi2.libanki.utils.Time in project AnkiChinaAndroid by ankichinateam.

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 = col.getDecks().newDyn("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 = col.getSched().getCard();
    assertEquals(2, col.getSched().answerButtons(c));
    assertEquals(600, col.getSched().nextIvl(c, 1));
    assertEquals(0, col.getSched().nextIvl(c, 2));
    // failing it will push its due time back
    long due = c.getDue();
    col.getSched().answerCard(c, 1);
    assertNotEquals(c.getDue(), due);
    // the other card should come next
    Card c2 = col.getSched().getCard();
    assertNotEquals(c2.getId(), c.getId());
    // passing it will remove it
    col.getSched().answerCard(c2, 2);
    assertEquals(QUEUE_TYPE_NEW, c2.getQueue());
    assertEquals(0, c2.getReps());
    assertEquals(CARD_TYPE_NEW, c2.getType());
    // the other card should appear again
    c = col.getSched().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)

Example 25 with Time

use of com.ichi2.libanki.utils.Time 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)

Aggregations

Test (org.junit.Test)27 Collection (com.ichi2.libanki.Collection)26 JSONObject (com.ichi2.utils.JSONObject)26 RobolectricTest (com.ichi2.anki.RobolectricTest)19 Card (com.ichi2.libanki.Card)19 Note (com.ichi2.libanki.Note)15 JSONArray (com.ichi2.utils.JSONArray)15 Deck (com.ichi2.libanki.Deck)11 ArrayList (java.util.ArrayList)11 DeckConfig (com.ichi2.libanki.DeckConfig)10 IOException (java.io.IOException)10 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)9 HashMap (java.util.HashMap)9 Cursor (android.database.Cursor)8 Nullable (androidx.annotation.Nullable)8 JSONException (com.ichi2.utils.JSONException)8 SharedPreferences (android.content.SharedPreferences)7 Resources (android.content.res.Resources)7 File (java.io.File)7 View (android.view.View)5