Ejemplo n.º 1
0
  /** Test giving the answer for a reviewed card */
  public void testAnswerCard() {
    Collection col;
    col = CollectionHelper.getInstance().getCol(getContext());
    Sched sched = col.getSched();
    long deckId = mTestDeckIds[0];
    col.getDecks().select(deckId);
    Card card = sched.getCard();

    ContentResolver cr = getContext().getContentResolver();
    Uri reviewInfoUri = FlashCardsContract.ReviewInfo.CONTENT_URI;
    ContentValues values = new ContentValues();
    long noteId = card.note().getId();
    int cardOrd = card.getOrd();
    int ease = AbstractFlashcardViewer.EASE_3; // <- insert real ease here

    values.put(FlashCardsContract.ReviewInfo.NOTE_ID, noteId);
    values.put(FlashCardsContract.ReviewInfo.CARD_ORD, cardOrd);
    values.put(FlashCardsContract.ReviewInfo.EASE, ease);
    int updateCount = cr.update(reviewInfoUri, values, null, null);

    assertEquals("Check if update returns 1", 1, updateCount);

    sched.reset();
    Card newCard = sched.getCard();
    if (newCard != null) {
      if (newCard.note().getId() == card.note().getId() && newCard.getOrd() == card.getOrd()) {
        fail("Next scheduled card has not changed");
      }
    } else {
      // We expected this
    }
  }
Ejemplo n.º 2
0
  /**
   * Test that query for the next card in the schedule returns a valid result WITH a deck selector
   */
  public void testQueryCardFromCertainDeck() {
    long deckToTest = mTestDeckIds[0];
    String deckSelector = "deckID=?";
    String deckArguments[] = {Long.toString(deckToTest)};
    Collection col;
    col = CollectionHelper.getInstance().getCol(getContext());
    Sched sched = col.getSched();
    long selectedDeckBeforeTest = col.getDecks().selected();
    col.getDecks().select(1); // select Default deck

    Cursor reviewInfoCursor =
        getContext()
            .getContentResolver()
            .query(
                FlashCardsContract.ReviewInfo.CONTENT_URI, null, deckSelector, deckArguments, null);
    assertNotNull(reviewInfoCursor);
    assertEquals("Check that we actually received one card", 1, reviewInfoCursor.getCount());
    try {
      reviewInfoCursor.moveToFirst();
      int cardOrd =
          reviewInfoCursor.getInt(
              reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.CARD_ORD));
      long noteID =
          reviewInfoCursor.getLong(
              reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.NOTE_ID));
      assertEquals("Check that the selected deck has not changed", 1, col.getDecks().selected());

      col.getDecks().select(deckToTest);
      Card nextCard = null;
      for (int i = 0;
          i < 10;
          i++) { // minimizing fails, when sched.reset() randomly chooses between multiple cards
        sched.reset();
        nextCard = sched.getCard();
        if (nextCard.note().getId() == noteID && nextCard.getOrd() == cardOrd) break;
      }
      assertNotNull("Check that there actually is a next scheduled card", nextCard);
      assertEquals(
          "Check that received card and actual card have same note id",
          nextCard.note().getId(),
          noteID);
      assertEquals(
          "Check that received card and actual card have same card ord",
          nextCard.getOrd(),
          cardOrd);
    } finally {
      reviewInfoCursor.close();
    }

    col.getDecks().select(selectedDeckBeforeTest);
  }
Ejemplo n.º 3
0
  /**
   * Test that query for the next card in the schedule returns a valid result without any deck
   * selector
   */
  public void testQueryNextCard() {
    Collection col;
    col = CollectionHelper.getInstance().getCol(getContext());
    Sched sched = col.getSched();

    Cursor reviewInfoCursor =
        getContext()
            .getContentResolver()
            .query(FlashCardsContract.ReviewInfo.CONTENT_URI, null, null, null, null);
    assertNotNull(reviewInfoCursor);
    assertEquals("Check that we actually received one card", 1, reviewInfoCursor.getCount());

    reviewInfoCursor.moveToFirst();
    int cardOrd =
        reviewInfoCursor.getInt(
            reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.CARD_ORD));
    long noteID =
        reviewInfoCursor.getLong(
            reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.NOTE_ID));

    Card nextCard = null;
    for (int i = 0;
        i < 10;
        i++) { // minimizing fails, when sched.reset() randomly chooses between multiple cards
      sched.reset();
      nextCard = sched.getCard();
      if (nextCard.note().getId() == noteID && nextCard.getOrd() == cardOrd) break;
    }
    assertNotNull("Check that there actually is a next scheduled card", nextCard);
    assertEquals(
        "Check that received card and actual card have same note id",
        nextCard.note().getId(),
        noteID);
    assertEquals(
        "Check that received card and actual card have same card ord", nextCard.getOrd(), cardOrd);
  }