Search in sources :

Example 36 with Queue

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

the class SchedV2Test method test_counts_idxV2.

@Test
public void test_counts_idxV2() throws Exception {
    Collection col = getColV2();
    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, 1, 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, 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)

Example 37 with Queue

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

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 = col.getSched().getCard();
    assertTrue(c.q().endsWith("1"));
    // pass it so it's due in 10 minutes
    col.getSched().answerCard(c, 3);
    // get the other card
    c = col.getSched().getCard();
    assertTrue(c.q().endsWith("2"));
    // fail it so it's due in 1 minute
    col.getSched().answerCard(c, 1);
    // we shouldn't get the same card again
    c = col.getSched().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 38 with Queue

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

the class SchedV2Test method test_learn_dayV2.

@Test
public void test_learn_dayV2() throws Exception {
    Collection col = getColV2();
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    col.reset();
    Card c = col.getSched().getCard();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 10, 1440, 2880 }));
    col.getDecks().save(conf);
    // pass it
    col.getSched().answerCard(c, 3);
    // two reps to graduate, 1 more today
    assertEquals(3, c.getLeft() % 1000);
    assertEquals(1, c.getLeft() / 1000);
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    c = col.getSched().getCard();
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
    // answering it will place it in queue 3
    col.getSched().answerCard(c, 3);
    assertEquals(col.getSched().getToday() + 1, c.getDue());
    assertEquals(QUEUE_TYPE_DAY_LEARN_RELEARN, c.getQueue());
    assertNull(col.getSched().getCard());
    // for testing, move it back a day
    c.setDue(c.getDue() - 1);
    c.flush();
    col.reset();
    assertArrayEquals(new int[] { 0, 1, 0 }, col.getSched().counts());
    c = col.getSched().getCard();
    // nextIvl should work
    assertEquals(SECONDS_PER_DAY * 2, col.getSched().nextIvl(c, 3));
    // if we fail it, it should be back in the correct queue
    col.getSched().answerCard(c, 1);
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    col.undo();
    col.reset();
    c = col.getSched().getCard();
    col.getSched().answerCard(c, 3);
    // simulate the passing of another two days
    c.setDue(c.getDue() - 2);
    c.flush();
    col.reset();
    // the last pass should graduate it into a review card
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
    col.getSched().answerCard(c, 3);
    assertEquals(CARD_TYPE_REV, c.getType());
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    // if the lapse step is tomorrow, failing it should handle the counts
    // correctly
    c.setDue(0);
    c.flush();
    col.reset();
    assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
    conf = col.getSched()._cardConf(c);
    conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 1440 }));
    col.getDecks().save(conf);
    c = col.getSched().getCard();
    col.getSched().answerCard(c, 1);
    assertEquals(QUEUE_TYPE_DAY_LEARN_RELEARN, c.getQueue());
    assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
}
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 39 with Queue

use of com.ichi2.libanki.sched.Counts.Queue 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 40 with Queue

use of com.ichi2.libanki.sched.Counts.Queue 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)

Aggregations

Card (com.ichi2.libanki.Card)31 Test (org.junit.Test)30 RobolectricTest (com.ichi2.anki.RobolectricTest)29 Collection (com.ichi2.libanki.Collection)27 Note (com.ichi2.libanki.Note)24 JSONObject (com.ichi2.utils.JSONObject)20 JSONArray (com.ichi2.utils.JSONArray)17 DeckConfig (com.ichi2.libanki.DeckConfig)15 Cursor (android.database.Cursor)10 ArrayList (java.util.ArrayList)10 Deck (com.ichi2.libanki.Deck)6 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)4 JSONException (com.ichi2.utils.JSONException)3 Nullable (androidx.annotation.Nullable)2 SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)2 Model (com.ichi2.libanki.Model)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 SuppressLint (android.annotation.SuppressLint)1