Search in sources :

Example 76 with CARD

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

the class SchedTest method test_deckDueV1.

@Test
public void test_deckDueV1() throws Exception {
    Collection col = getColV1();
    // add a note with default deck
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    // and one that's a child
    note = col.newNote();
    note.setItem("Front", "two");
    long default1 = col.getDecks().id("Default::1");
    note.model().put("did", default1);
    col.addNote(note);
    // make it a review card
    Card c = note.cards().get(0);
    c.setQueue(QUEUE_TYPE_REV);
    c.setDue(0);
    c.flush();
    // add one more with a new deck
    note = col.newNote();
    note.setItem("Front", "two");
    JSONObject foobar = note.model().put("did", col.getDecks().id("foo::bar"));
    col.addNote(note);
    // and one that's a sibling
    note = col.newNote();
    note.setItem("Front", "three");
    JSONObject foobaz = note.model().put("did", col.getDecks().id("foo::baz"));
    col.addNote(note);
    col.reset();
    assertEquals(5, col.getDecks().allSortedNames().size());
    DeckDueTreeNode tree = col.getSched().deckDueTree().get(0);
    assertEquals("Default", tree.getLastDeckNameComponent());
    // sum of child and parent
    assertEquals(1, tree.getDid());
    assertEquals(1, tree.getRevCount());
    assertEquals(1, tree.getNewCount());
    // child count is just review
    DeckDueTreeNode child = tree.getChildren().get(0);
    assertEquals("1", child.getLastDeckNameComponent());
    assertEquals(default1, child.getDid());
    assertEquals(1, child.getRevCount());
    assertEquals(0, child.getNewCount());
    // code should not fail if a card has an invalid deck
    c.setDid(12345);
    c.flush();
    col.getSched().deckDueTree();
}
Also used : DeckDueTreeNode(com.ichi2.libanki.sched.DeckDueTreeNode) JSONObject(com.ichi2.utils.JSONObject) 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 77 with CARD

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

the class SchedTest method test_failmultV1.

@Test
public void test_failmultV1() throws Exception {
    Collection col = getColV1();
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    Card c = note.cards().get(0);
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setIvl(100);
    c.setDue(col.getSched().getToday() - c.getIvl());
    c.setFactor(STARTING_FACTOR);
    c.setReps(3);
    c.setLapses(1);
    c.startTimer();
    c.flush();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("lapse").put("mult", 0.5);
    col.getDecks().save(conf);
    c = col.getSched().getCard();
    col.getSched().answerCard(c, 1);
    assertEquals(50, c.getIvl());
    col.getSched().answerCard(c, 1);
    assertEquals(25, c.getIvl());
}
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 78 with CARD

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

the class SchedTest method test_forgetV1.

@Test
public void test_forgetV1() throws Exception {
    Collection col = getColV1();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Card c = note.cards().get(0);
    c.setQueue(QUEUE_TYPE_REV);
    c.setType(CARD_TYPE_REV);
    c.setIvl(100);
    c.setDue(0);
    c.flush();
    col.reset();
    assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
    col.getSched().forgetCards(new long[] { c.getId() });
    col.reset();
    assertArrayEquals(new int[] { 1, 0, 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 79 with CARD

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

the class CardBrowserTest method tagWithBracketsDisplaysProperly.

@Test
public void tagWithBracketsDisplaysProperly() {
    Note n = addNoteUsingBasicModel("Hello", "World");
    n.addTag("sketchy::(1)");
    n.flush();
    CardBrowser b = getBrowserWithNoNewCards();
    b.filterByTag("sketchy::(1)");
    assertThat("tagged card should be returned", b.getCardCount(), is(1));
}
Also used : Note(com.ichi2.libanki.Note) Test(org.junit.Test)

Example 80 with CARD

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

the class CardTemplateEditorTest method testDeleteTemplate.

@Test
public void testDeleteTemplate() {
    String modelName = "Basic (and reversed card)";
    // Start the CardTemplateEditor with a specific model, and make sure the model starts unchanged
    JSONObject collectionBasicModelOriginal = getCurrentDatabaseModelCopy(modelName);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.putExtra("modelId", collectionBasicModelOriginal.getLong("id"));
    ActivityController<CardTemplateEditor> templateEditorController = Robolectric.buildActivity(CardTemplateEditor.class, intent).create().start().resume().visible();
    saveControllerForCleanup(templateEditorController);
    CardTemplateEditor testEditor = (CardTemplateEditor) templateEditorController.get();
    Assert.assertFalse("Model should not have changed yet", testEditor.modelHasChanged());
    Assert.assertEquals("Model should have 2 templates now", 2, testEditor.getTempModel().getTemplateCount());
    // Try to delete the template - click delete, click confirm for card delete, click confirm again for full sync
    ShadowActivity shadowTestEditor = shadowOf(testEditor);
    Assert.assertTrue("Unable to click?", shadowTestEditor.clickMenuItem(R.id.action_delete));
    advanceRobolectricLooper();
    Assert.assertEquals("Wrong dialog shown?", "Delete the “Card 1” card type, and its 0 cards?", getDialogText(true));
    clickDialogButton(DialogAction.POSITIVE, true);
    advanceRobolectricLooper();
    Assert.assertTrue("Model should have changed", testEditor.modelHasChanged());
    Assert.assertEquals("Model should have 1 template now", 1, testEditor.getTempModel().getTemplateCount());
    // Try to delete the template again, but there's only one
    Assert.assertTrue("Unable to click?", shadowTestEditor.clickMenuItem(R.id.action_delete));
    advanceRobolectricLooper();
    Assert.assertEquals("Did not show dialog about deleting only card?", getResourceString(R.string.card_template_editor_cant_delete), getDialogText(true));
    Assert.assertEquals("Change already in database?", collectionBasicModelOriginal.toString().trim(), getCurrentDatabaseModelCopy(modelName).toString().trim());
    // Save the change to the database and make sure there's only one template after
    JSONObject testEditorModelEdited = testEditor.getTempModel().getModel();
    Assert.assertTrue("Unable to click?", shadowTestEditor.clickMenuItem(R.id.action_confirm));
    advanceRobolectricLooper();
    JSONObject collectionBasicModelCopyEdited = getCurrentDatabaseModelCopy(modelName);
    Assert.assertNotEquals("model is unchanged?", collectionBasicModelOriginal, collectionBasicModelCopyEdited);
    Assert.assertEquals("model did not save?", testEditorModelEdited.toString().trim(), collectionBasicModelCopyEdited.toString().trim());
}
Also used : JSONObject(com.ichi2.utils.JSONObject) ShadowActivity(org.robolectric.shadows.ShadowActivity) ShadowIntent(org.robolectric.shadows.ShadowIntent) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

Card (com.ichi2.libanki.Card)222 Test (org.junit.Test)212 Collection (com.ichi2.libanki.Collection)179 Note (com.ichi2.libanki.Note)173 RobolectricTest (com.ichi2.anki.RobolectricTest)168 JSONObject (com.ichi2.utils.JSONObject)114 JSONArray (com.ichi2.utils.JSONArray)80 DeckConfig (com.ichi2.libanki.DeckConfig)72 ArrayList (java.util.ArrayList)48 NonNull (androidx.annotation.NonNull)33 Deck (com.ichi2.libanki.Deck)32 Intent (android.content.Intent)29 JSONException (com.ichi2.utils.JSONException)27 Model (com.ichi2.libanki.Model)26 Context (android.content.Context)23 SuppressLint (android.annotation.SuppressLint)22 Cursor (android.database.Cursor)22 HashMap (java.util.HashMap)21 Matchers.containsString (org.hamcrest.Matchers.containsString)20 List (java.util.List)17