Search in sources :

Example 1 with MockTime

use of com.ichi2.testutils.MockTime in project Anki-Android by ankidroid.

the class ReviewerTest method testMultipleCards.

@Test
public synchronized void testMultipleCards() throws ConfirmModSchemaException {
    addNoteWithThreeCards();
    Collection col = getCol();
    JSONObject nw = col.getDecks().confForDid(1).getJSONObject("new");
    MockTime time = getCollectionTime();
    nw.put("delays", new JSONArray(new int[] { 1, 10, 60, 120 }));
    waitForAsyncTasksToComplete();
    Reviewer reviewer = startReviewer();
    waitForAsyncTasksToComplete();
    assertCounts(reviewer, 3, 0, 0);
    // card 1 is shown
    answerCardOrdinalAsGood(reviewer, 1);
    // card get scheduler in [10, 12.5] minutes
    time.addM(3);
    // We wait 3 minutes to ensure card 2 is scheduled after card 1
    // card 2 is shown
    answerCardOrdinalAsGood(reviewer, 2);
    // Same as above
    time.addM(3);
    // card 3 is shown
    answerCardOrdinalAsGood(reviewer, 3);
    undo(reviewer);
    assertCurrentOrdIs(reviewer, 3);
    // card 3 is shown
    answerCardOrdinalAsGood(reviewer, 3);
    // Anki Desktop shows "1"
    assertCurrentOrdIsNot(reviewer, 3);
}
Also used : JSONObject(com.ichi2.utils.JSONObject) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) MockTime(com.ichi2.testutils.MockTime) Test(org.junit.Test)

Example 2 with MockTime

use of com.ichi2.testutils.MockTime in project AnkiChinaAndroid by ankichinateam.

the class ReviewerTest method testMultipleCards.

@Test
public synchronized void testMultipleCards() throws ConfirmModSchemaException, InterruptedException {
    addNoteWithThreeCards();
    Collection col = getCol();
    JSONObject nw = col.getDecks().confForDid(1).getJSONObject("new");
    MockTime time = getCollectionTime();
    nw.put("delays", new JSONArray(new int[] { 1, 10, 60, 120 }));
    waitForAsyncTasksToComplete();
    Reviewer reviewer = startReviewer();
    waitForAsyncTasksToComplete();
    assertCounts(reviewer, 3, 0, 0);
    // card 1 is shown
    answerCardOrdinalAsGood(reviewer, 1);
    // card get scheduler in [10, 12.5] minutes
    time.addM(3);
    // We wait 3 minutes to ensure card 2 is scheduled after card 1
    // card 2 is shown
    answerCardOrdinalAsGood(reviewer, 2);
    // Same as above
    time.addM(3);
    // card 3 is shown
    answerCardOrdinalAsGood(reviewer, 3);
    undo(reviewer);
    assertCurrentOrdIs(reviewer, 3);
    // card 3 is shown
    answerCardOrdinalAsGood(reviewer, 3);
    // Anki Desktop shows "1"
    assertCurrentOrdIsNot(reviewer, 3);
}
Also used : JSONObject(com.ichi2.utils.JSONObject) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) MockTime(com.ichi2.testutils.MockTime) Test(org.junit.Test)

Example 3 with MockTime

use of com.ichi2.testutils.MockTime in project Anki-Android by ankidroid.

the class MockTimeTest method DateTest.

@Test
public void DateTest() {
    MockTime time = new MockTime(2020, 7, 7, 7, 0, 0, 0, 0);
    Assert.assertEquals(1596783600000L, time.intTimeMS());
    Assert.assertEquals(1596783600000L, MockTime.timeStamp(2020, 7, 7, 7, 0, 0));
}
Also used : MockTime(com.ichi2.testutils.MockTime) Test(org.junit.Test)

Example 4 with MockTime

use of com.ichi2.testutils.MockTime in project Anki-Android by ankidroid.

the class ReviewerTest method testLrnQueueAfterUndo.

@Test
public void testLrnQueueAfterUndo() {
    Collection col = getCol();
    JSONObject nw = col.getDecks().confForDid(1).getJSONObject("new");
    MockTime time = (MockTime) col.getTime();
    nw.put("delays", new JSONArray(new int[] { 1, 10, 60, 120 }));
    Card[] cards = new Card[4];
    cards[0] = addRevNoteUsingBasicModelDueToday("1", "bar").firstCard();
    cards[1] = addNoteUsingBasicModel("2", "bar").firstCard();
    cards[2] = addNoteUsingBasicModel("3", "bar").firstCard();
    waitForAsyncTasksToComplete();
    Reviewer reviewer = startReviewer();
    waitForAsyncTasksToComplete();
    equalFirstField(cards[0], reviewer.mCurrentCard);
    reviewer.answerCard(Consts.BUTTON_ONE);
    waitForAsyncTasksToComplete();
    equalFirstField(cards[1], reviewer.mCurrentCard);
    reviewer.answerCard(Consts.BUTTON_ONE);
    waitForAsyncTasksToComplete();
    undo(reviewer);
    waitForAsyncTasksToComplete();
    equalFirstField(cards[1], reviewer.mCurrentCard);
    reviewer.answerCard(getCol().getSched().getGoodNewButton());
    waitForAsyncTasksToComplete();
    equalFirstField(cards[2], reviewer.mCurrentCard);
    time.addM(2);
    reviewer.answerCard(getCol().getSched().getGoodNewButton());
    advanceRobolectricLooperWithSleep();
    // This failed in #6898 because this card was not in the queue
    equalFirstField(cards[0], reviewer.mCurrentCard);
}
Also used : JSONObject(com.ichi2.utils.JSONObject) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) MockTime(com.ichi2.testutils.MockTime) Card(com.ichi2.libanki.Card) Test(org.junit.Test)

Aggregations

MockTime (com.ichi2.testutils.MockTime)4 Test (org.junit.Test)4 Collection (com.ichi2.libanki.Collection)3 JSONArray (com.ichi2.utils.JSONArray)3 JSONObject (com.ichi2.utils.JSONObject)3 Card (com.ichi2.libanki.Card)1