Search in sources :

Example 86 with CARD

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

the class MathJaxClozeTest method verifyMathJaxClozeCards.

@Test
public void verifyMathJaxClozeCards() {
    final Context context = ApplicationProvider.getApplicationContext();
    Collection c = getCol();
    Note f = c.newNote(c.getModels().byName("Cloze"));
    f.setItem("Text", "{{c1::ok}} \\(2^2\\) {{c2::not ok}} \\(2^{{c3::2}}\\) \\(x^3\\) {{c4::blah}} {{c5::text with \\(x^2\\) jax}}");
    c.addNote(f);
    assertEquals(5, f.numberOfCards());
    ArrayList<Card> cards = f.cards();
    assertThat(cards.get(0).q(), containsString("class=cloze"));
    assertThat(cards.get(1).q(), containsString("class=cloze"));
    String s = cards.get(2).q();
    assertThat(cards.get(2).q(), not(containsString("class=cloze")));
    assertThat(cards.get(3).q(), containsString("class=cloze"));
    assertThat(cards.get(4).q(), containsString("class=cloze"));
}
Also used : Context(android.content.Context) Matchers.containsString(org.hamcrest.Matchers.containsString) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 87 with CARD

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

the class MathJaxClozeTest method verifyMathJaxInCloze.

@Test
public void verifyMathJaxInCloze() {
    final Context context = ApplicationProvider.getApplicationContext();
    Collection c = getCol();
    {
        Note f = c.newNote(c.getModels().byName("Cloze"));
        f.setItem("Text", "\\(1 \\div 2 =\\){{c1::\\(\\frac{1}{2}\\)}}");
        c.addNote(f);
        ArrayList<Card> cards = f.cards();
        Card c2 = cards.get(0);
        String q = c2.q();
        String a = c2.a();
        assertThat(q, containsString("\\(1 \\div 2 =\\)"));
        assertThat(a, containsString("\\(1 \\div 2 =\\)"));
        assertThat(a, containsString("<span class=cloze>\\(\\frac{1}{2}\\)</span>"));
    }
    {
        Note f = c.newNote(c.getModels().byName("Cloze"));
        f.setItem("Text", "\\(a\\) {{c1::b}} \\[ {{c1::c}} \\]");
        c.addNote(f);
        ArrayList<Card> cards = f.cards();
        Card c2 = cards.get(0);
        String q = c2.q();
        assertThat(q, containsString("\\(a\\) <span class=cloze>[...]</span> \\[ [...] \\]"));
    }
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 88 with CARD

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

the class ModelTest method test_templates.

@Test
public void test_templates() throws ConfirmModSchemaException {
    Collection col = getCol();
    Model m = col.getModels().current();
    Models mm = col.getModels();
    JSONObject t = Models.newTemplate("Reverse");
    t.put("qfmt", "{{Back}}");
    t.put("afmt", "{{Front}}");
    mm.addTemplateModChanged(m, t);
    mm.save(m);
    Note note = col.newNote();
    note.setItem("Front", "1");
    note.setItem("Back", "2");
    col.addNote(note);
    assertEquals(2, col.cardCount());
    List<Card> cards = note.cards();
    assertEquals(2, cards.size());
    Card c = cards.get(0);
    Card c2 = cards.get(1);
    // first card should have first ord
    assertEquals(0, c.getOrd());
    assertEquals(1, c2.getOrd());
    // switch templates
    col.getModels().moveTemplate(m, c.template(), 1);
    c.load();
    c2.load();
    assertEquals(1, c.getOrd());
    assertEquals(0, c2.getOrd());
    // removing a template should delete its cards
    col.getModels().remTemplate(m, m.getJSONArray("tmpls").getJSONObject(0));
    assertEquals(1, col.cardCount());
    // and should have updated the other cards' ordinals
    c = note.cards().get(0);
    assertEquals(0, c.getOrd());
    assertEquals("1", stripHTML(c.q()));
    // it shouldn't be possible to orphan notes by removing templates
    t = Models.newTemplate("template name");
    mm.addTemplateModChanged(m, t);
    col.getModels().remTemplate(m, m.getJSONArray("tmpls").getJSONObject(0));
    assertEquals(0, col.getDb().queryLongScalar("select count() from cards where nid not in (select id from notes)"));
}
Also used : JSONObject(com.ichi2.utils.JSONObject) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 89 with CARD

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

the class AbstractFlashcardViewerCommandTest method cardWith.

private Card cardWith(@FlagDef int flag) {
    Card c = mock(Card.class);
    int[] flags = new int[] { flag };
    when(c.userFlag()).then((invocation) -> flags[0]);
    doAnswer(invocation -> {
        flags[0] = invocation.getArgument(0);
        return null;
    }).when(c).setUserFlag(anyInt());
    return c;
}
Also used : Card(com.ichi2.libanki.Card)

Example 90 with CARD

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

the class SchedV2Test method test_button_spacingV2.

@Test
public void test_button_spacingV2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    // 1 day ivl review card due now
    Card c = note.cards().get(0);
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setDue(col.getSched().getToday());
    c.setReps(1);
    c.setIvl(1);
    c.startTimer();
    c.flush();
    col.reset();
    // Upstream, there is no space in 2d
    assertEquals("2 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 2)));
    assertEquals("3 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 3)));
    assertEquals("4 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 4)));
    // if hard factor is <= 1, then hard may not increase
    DeckConfig conf = col.getDecks().confForDid(1);
    conf.getJSONObject("rev").put("hardFactor", 1);
    col.getDecks().save(conf);
    assertEquals("1 d", without_unicode_isolation(col.getSched().nextIvlStr(getTargetContext(), c, 2)));
}
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)

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