diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt index c5c1e05c3263..73aa70ab8775 100644 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt +++ b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt @@ -1281,7 +1281,7 @@ class ContentProviderTest : InstrumentedTest() { ) for (c in newNote.cards()) { c.did = did - c.flush() + c.col.updateCard(c, skipUndoEntry = true) } return Uri.withAppendedPath( FlashCardsContract.Note.CONTENT_URI, diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt index 6fea8678c841..78d1ff9a7d0a 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt @@ -211,37 +211,6 @@ open class Card : Cloneable { return builder.build() } - fun flush(changeModUsn: Boolean = true) { - if (changeModUsn) { - mod = TimeManager.time.intTime() - usn = col.usn() - } - assert(due < "4294967296".toLong()) - col.db.execute( - "insert or replace into cards values " + - "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - this.id, - nid, - did, - ord, - mod, - usn, - this.type, - queue, - due, - ivl, - factor, - reps, - lapses, - left, - oDue, - oDid, - flags, - "" - ) - col.log(this) - } - fun question(reload: Boolean = false, browser: Boolean = false): String { return renderOutput(reload, browser).questionAndStyle() } diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt index b99d2df1907e..665027ec18cb 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt @@ -155,10 +155,26 @@ class CardBrowserTest : RobolectricTest() { browser.rerenderAllCards() // ASSERT assertThat(browser.cardCount(), equalTo(6L)) - assertThat("A checked card should have been removed", browser.checkedCardCount(), equalTo(3)) - assertThat("Checked card before should not have changed", browser.hasCheckedCardAtPosition(1), equalTo(true)) - assertThat("Checked card after should have changed by 2 places", browser.hasCheckedCardAtPosition(3), equalTo(true)) - assertThat("Checked card after should have changed by 2 places", browser.hasCheckedCardAtPosition(4), equalTo(true)) + assertThat( + "A checked card should have been removed", + browser.checkedCardCount(), + equalTo(3) + ) + assertThat( + "Checked card before should not have changed", + browser.hasCheckedCardAtPosition(1), + equalTo(true) + ) + assertThat( + "Checked card after should have changed by 2 places", + browser.hasCheckedCardAtPosition(3), + equalTo(true) + ) + assertThat( + "Checked card after should have changed by 2 places", + browser.hasCheckedCardAtPosition(4), + equalTo(true) + ) } @Test @@ -218,7 +234,11 @@ class CardBrowserTest : RobolectricTest() { val cardIds = b.checkedCardIds for (cardId in cardIds) { - assertThat("Deck should have been changed yet", col.getCard(cardId).did, not(deckIdToChangeTo)) + assertThat( + "Deck should have been changed yet", + col.getCard(cardId).did, + not(deckIdToChangeTo) + ) } // act @@ -269,19 +289,30 @@ class CardBrowserTest : RobolectricTest() { val cardPosition = random.nextInt(numberOfNotes) assumeThat("card position to select is 60", cardPosition, equalTo(60)) cardBrowser.checkCardsAtPositions(cardPosition) - assumeTrue("card at position 60 is selected", cardBrowser.hasCheckedCardAtPosition(cardPosition)) + assumeTrue( + "card at position 60 is selected", + cardBrowser.hasCheckedCardAtPosition(cardPosition) + ) // flag the selected card with flag = 1 val flag = 1 cardBrowser.updateSelectedCardsFlag(flag) // check if card flag turned to flag = 1 - assertThat("Card should be flagged", getCheckedCard(cardBrowser).card.userFlag(), equalTo(flag)) + assertThat( + "Card should be flagged", + getCheckedCard(cardBrowser).card.userFlag(), + equalTo(flag) + ) // unflag the selected card with flag = 0 val unflagFlag = 0 cardBrowser.updateSelectedCardsFlag(unflagFlag) // check if card flag actually changed from flag = 1 - assertThat("Card flag should be removed", getCheckedCard(cardBrowser).card.userFlag(), not(flag)) + assertThat( + "Card flag should be removed", + getCheckedCard(cardBrowser).card.userFlag(), + not(flag) + ) // deselect and select all cards cardBrowser.onSelectNone() @@ -321,7 +352,8 @@ class CardBrowserTest : RobolectricTest() { withNoWritePermission { val inputIntent = Intent("android.intent.action.PROCESS_TEXT") - val browserController = Robolectric.buildActivity(CardBrowser::class.java, inputIntent).create() + val browserController = + Robolectric.buildActivity(CardBrowser::class.java, inputIntent).create() val cardBrowser = browserController.get() saveControllerForCleanup(browserController) @@ -329,9 +361,17 @@ class CardBrowserTest : RobolectricTest() { val outputIntent = shadowActivity.nextStartedActivity val component = assertNotNull(outputIntent.component) - assertThat("Deck Picker currently handles permissions, so should be called", component.className, equalTo("com.ichi2.anki.DeckPicker")) + assertThat( + "Deck Picker currently handles permissions, so should be called", + component.className, + equalTo("com.ichi2.anki.DeckPicker") + ) assertThat("Activity should be finishing", cardBrowser.isFinishing) - assertThat("Activity should be cancelled as it did nothing", shadowActivity.resultCode, equalTo(Activity.RESULT_CANCELED)) + assertThat( + "Activity should be cancelled as it did nothing", + shadowActivity.resultCode, + equalTo(Activity.RESULT_CANCELED) + ) } } @@ -379,7 +419,11 @@ class CardBrowserTest : RobolectricTest() { b.checkCardsAtPositions(0) val previewIntent = b.previewIntent assertThat("before: index", previewIntent.getIntExtra("index", -100), equalTo(0)) - assertThat("before: cards", previewIntent.getLongArrayExtra("cardList"), equalTo(longArrayOf(cid1, cid2))) + assertThat( + "before: cards", + previewIntent.getLongArrayExtra("cardList"), + equalTo(longArrayOf(cid1, cid2)) + ) // reverse b.changeCardOrder(1) @@ -390,7 +434,11 @@ class CardBrowserTest : RobolectricTest() { b.replaceSelectionWith(intArrayOf(0)) val intentAfterReverse = b.previewIntent assertThat("after: index", intentAfterReverse.getIntExtra("index", -100), equalTo(0)) - assertThat("after: cards", intentAfterReverse.getLongArrayExtra("cardList"), equalTo(longArrayOf(cid2, cid1))) + assertThat( + "after: cards", + intentAfterReverse.getLongArrayExtra("cardList"), + equalTo(longArrayOf(cid2, cid1)) + ) } /** 7420 */ @@ -418,7 +466,11 @@ class CardBrowserTest : RobolectricTest() { val b = browserWithNoNewCards - assertThat("The target deck should not yet be selected", b.lastDeckId, not(equalTo(targetDid))) + assertThat( + "The target deck should not yet be selected", + b.lastDeckId, + not(equalTo(targetDid)) + ) b.selectDeckAndSave(targetDid) @@ -453,13 +505,21 @@ class CardBrowserTest : RobolectricTest() { val card = getCheckedCard(b) - assertThat("Initial position of checked card", card.getColumnHeaderText(CardBrowser.Column.DUE), equalTo("1")) + assertThat( + "Initial position of checked card", + card.getColumnHeaderText(CardBrowser.Column.DUE), + equalTo("1") + ) b.repositionCardsNoValidation(listOf(card.id), 2) card.reload() - assertThat("Position of checked card after reposition", card.getColumnHeaderText(CardBrowser.Column.DUE), equalTo("2")) + assertThat( + "Position of checked card after reposition", + card.getColumnHeaderText(CardBrowser.Column.DUE), + equalTo("2") + ) } @Test @@ -469,7 +529,7 @@ class CardBrowserTest : RobolectricTest() { due = 5 queue = Consts.QUEUE_TYPE_REV type = Consts.CARD_TYPE_REV - flush() + col.updateCard(this, skipUndoEntry = true) } val b = browserWithNoNewCards @@ -478,13 +538,21 @@ class CardBrowserTest : RobolectricTest() { val card = getCheckedCard(b) - assertThat("Initial due of checked card", card.getColumnHeaderText(CardBrowser.Column.DUE), equalTo("8/12/20")) + assertThat( + "Initial due of checked card", + card.getColumnHeaderText(CardBrowser.Column.DUE), + equalTo("8/12/20") + ) b.resetProgressNoConfirm(listOf(card.id)) card.reload() - assertThat("Position of checked card after reset", card.getColumnHeaderText(CardBrowser.Column.DUE), equalTo("2")) + assertThat( + "Position of checked card after reset", + card.getColumnHeaderText(CardBrowser.Column.DUE), + equalTo("2") + ) } @Test @@ -497,7 +565,11 @@ class CardBrowserTest : RobolectricTest() { val card = getCheckedCard(b) - assertThat("Initial position of checked card", card.getColumnHeaderText(CardBrowser.Column.DUE), equalTo("1")) + assertThat( + "Initial position of checked card", + card.getColumnHeaderText(CardBrowser.Column.DUE), + equalTo("1") + ) b.rescheduleWithoutValidation(listOf(card.id), 5) @@ -515,15 +587,27 @@ class CardBrowserTest : RobolectricTest() { val card = getCheckedCard(b) - assertThat("Initial position of checked card", card.getColumnHeaderText(CardBrowser.Column.DUE), equalTo("1")) + assertThat( + "Initial position of checked card", + card.getColumnHeaderText(CardBrowser.Column.DUE), + equalTo("1") + ) b.repositionCardsNoValidation(listOf(card.id), 2) - assertThat("Position of checked card after reposition", card.getColumnHeaderText(CardBrowser.Column.DUE), equalTo("2")) + assertThat( + "Position of checked card after reposition", + card.getColumnHeaderText(CardBrowser.Column.DUE), + equalTo("2") + ) b.onUndo() - assertThat("Position of checked card after undo should be reset", card.getColumnHeaderText(CardBrowser.Column.DUE), equalTo("1")) + assertThat( + "Position of checked card after undo should be reset", + card.getColumnHeaderText(CardBrowser.Column.DUE), + equalTo("1") + ) } @Test @@ -564,13 +648,21 @@ class CardBrowserTest : RobolectricTest() { col.decks.select(deck) val c2 = addNoteUsingBasicModel("New", "world").firstCard() c2.did = deck - c2.flush() + c2.col.updateCard(c2, skipUndoEntry = true) val cardBrowser = browserWithNoNewCards cardBrowser.searchCards("world or hello") - assertThat("Cardbrowser has Deck 1 as selected deck", cardBrowser.selectedDeckNameForUi, equalTo("Deck 1")) - assertThat("Results should only be from the selected deck", cardBrowser.cardCount, equalTo(1)) + assertThat( + "Cardbrowser has Deck 1 as selected deck", + cardBrowser.selectedDeckNameForUi, + equalTo("Deck 1") + ) + assertThat( + "Results should only be from the selected deck", + cardBrowser.cardCount, + equalTo(1) + ) } /** PR #8553 */ @@ -583,7 +675,11 @@ class CardBrowserTest : RobolectricTest() { saveControllerForCleanup(cardBrowserController) // Make sure card has default value in sortType field - assertThat("Initially Card Browser has order = noteFld", col.config.get("sortType"), equalTo("noteFld")) + assertThat( + "Initially Card Browser has order = noteFld", + col.config.get("sortType"), + equalTo("noteFld") + ) // Change the display order of the card browser cardBrowserController.get().changeCardOrder(7) // order no. 7 corresponds to "cardEase" @@ -592,13 +688,19 @@ class CardBrowserTest : RobolectricTest() { val outBundle = Bundle() cardBrowserController.saveInstanceState(outBundle) cardBrowserController.pause().stop().destroy() - cardBrowserController = Robolectric.buildActivity(CardBrowser::class.java).create(outBundle).start().resume().visible() + cardBrowserController = + Robolectric.buildActivity(CardBrowser::class.java).create(outBundle).start().resume() + .visible() saveControllerForCleanup(cardBrowserController) // Find the current (after database has been changed) Mod time val updatedMod = col.mod - assertThat("Card Browser has the new sortType field", col.config.get("sortType"), equalTo("cardEase")) + assertThat( + "Card Browser has the new sortType field", + col.config.get("sortType"), + equalTo("cardEase") + ) assertNotEquals(0, updatedMod) } @@ -618,11 +720,15 @@ class CardBrowserTest : RobolectricTest() { col.decks.select(deck) val c2 = addNoteUsingBasicModel("Front", "Back").firstCard() c2.did = deck - c2.flush() + c2.col.updateCard(c2, skipUndoEntry = true) val cardBrowser = browserWithNoNewCards cardBrowser.searchCards("Hello") - assertThat("Card browser should have Test Deck as the selected deck", cardBrowser.selectedDeckNameForUi, equalTo("Test Deck")) + assertThat( + "Card browser should have Test Deck as the selected deck", + cardBrowser.selectedDeckNameForUi, + equalTo("Test Deck") + ) assertThat("Result should be empty", cardBrowser.cardCount, equalTo(0)) cardBrowser.searchAllDecks() @@ -647,7 +753,10 @@ class CardBrowserTest : RobolectricTest() { val shadowActivity = shadowOf(browser) val item = shadowActivity.optionsMenu.findItem(R.id.action_undo) val expected = browser.getString(resId) - assertThat(item.title.toString(), not(containsString(expected.lowercase(Locale.getDefault())))) + assertThat( + item.title.toString(), + not(containsString(expected.lowercase(Locale.getDefault()))) + ) } private fun assertUndoContains(browser: CardBrowser, @StringRes resId: Int) { @@ -666,7 +775,7 @@ class CardBrowserTest : RobolectricTest() { private fun flagCardForNote(n: Note, flag: Int) { val c = n.firstCard() c.setUserFlag(flag) - c.flush() + c.col.updateCard(c, skipUndoEntry = true) } private fun selectDefaultDeck() { diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/PreviewerTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/PreviewerTest.kt index 82470123f95b..f3c4f96c96a4 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/PreviewerTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/PreviewerTest.kt @@ -40,11 +40,19 @@ class PreviewerTest : RobolectricTest() { val previewer = getPreviewerPreviewing(cardToPreview) - assertThat("Initially should be previewing selected card", previewer.currentCardId, equalTo(cardToPreview.id)) + assertThat( + "Initially should be previewing selected card", + previewer.currentCardId, + equalTo(cardToPreview.id) + ) previewer.saveEditedCard() - assertThat("Should be previewing selected card after edit", previewer.currentCardId, equalTo(cardToPreview.id)) + assertThat( + "Should be previewing selected card after edit", + previewer.currentCardId, + equalTo(cardToPreview.id) + ) } @Test @@ -63,7 +71,11 @@ class PreviewerTest : RobolectricTest() { previewer.saveEditedCard() - assertThat("Card content should be updated after editing", previewer.cardContent, containsString("Hi")) + assertThat( + "Card content should be updated after editing", + previewer.cardContent, + containsString("Hi") + ) } @Test @@ -81,7 +93,11 @@ class PreviewerTest : RobolectricTest() { val s = previewer.findViewById(R.id.preview_progress_seek_bar) val t = previewer.findViewById(R.id.preview_progress_text) assertThat("Progress is 0 at the beginning.", s.progress, equalTo(0)) - assertThat("Progress text at the beginning.", t.text, equalTo(previewer.getString(R.string.preview_progress_bar_text, 1, 6))) + assertThat( + "Progress text at the beginning.", + t.text, + equalTo(previewer.getString(R.string.preview_progress_bar_text, 1, 6)) + ) } @Test @@ -91,7 +107,11 @@ class PreviewerTest : RobolectricTest() { val s = previewer.findViewById(R.id.preview_progress_seek_bar) val t = previewer.findViewById(R.id.preview_progress_text) assertThat("Max value of seekbar", s.max, equalTo(5)) - assertThat("Progress text at the beginning.", t.text, equalTo(previewer.getString(R.string.preview_progress_bar_text, 1, 6))) + assertThat( + "Progress text at the beginning.", + t.text, + equalTo(previewer.getString(R.string.preview_progress_bar_text, 1, 6)) + ) } @Test @@ -104,7 +124,11 @@ class PreviewerTest : RobolectricTest() { previewer.changePreviewedCard(true) previewer.changePreviewedCard(true) assertThat("Seekbar value when you preview two cards", y, equalTo(s.progress - 2)) - assertThat("Progress text at the beginning.", t.text, equalTo(previewer.getString(R.string.preview_progress_bar_text, 3, 6))) + assertThat( + "Progress text at the beginning.", + t.text, + equalTo(previewer.getString(R.string.preview_progress_bar_text, 3, 6)) + ) } @Test @@ -117,10 +141,18 @@ class PreviewerTest : RobolectricTest() { previewer.changePreviewedCard(true) val y = s.progress previewer.changePreviewedCard(false) - assertThat("Progress text at the beginning.", t.text, equalTo(previewer.getString(R.string.preview_progress_bar_text, 2, 6))) + assertThat( + "Progress text at the beginning.", + t.text, + equalTo(previewer.getString(R.string.preview_progress_bar_text, 2, 6)) + ) previewer.changePreviewedCard(false) assertThat("Seekbar value when you go back two cards", s.progress, equalTo(y - 2)) - assertThat("Progress text at the beginning.", t.text, equalTo(previewer.getString(R.string.preview_progress_bar_text, 1, 6))) + assertThat( + "Progress text at the beginning.", + t.text, + equalTo(previewer.getString(R.string.preview_progress_bar_text, 1, 6)) + ) } private fun seekBarHelper(): Previewer { @@ -141,12 +173,15 @@ class PreviewerTest : RobolectricTest() { private fun setDeck(@Suppress("SameParameterValue") name: String, card: Card) { val did = addDeck(name) card.did = did - card.flush() + card.col.updateCard(card, skipUndoEntry = true) } private fun getPreviewerPreviewingList(cardIds: LongArray, c: Array): Previewer { val previewIntent = PreviewDestination(index = 0, cardIds).toIntent(targetContext) - val previewer = super.startActivityNormallyOpenCollectionWithIntent(Previewer::class.java, previewIntent) + val previewer = super.startActivityNormallyOpenCollectionWithIntent( + Previewer::class.java, + previewIntent + ) for (i in cardIds.indices) { AbstractFlashcardViewer.editorCard = c[i] } @@ -155,7 +190,10 @@ class PreviewerTest : RobolectricTest() { private fun getPreviewerPreviewing(usableCard: Card): Previewer { val previewIntent = PreviewDestination(index = 0, longArrayOf(usableCard.id)).toIntent(targetContext) - val previewer = super.startActivityNormallyOpenCollectionWithIntent(Previewer::class.java, previewIntent) + val previewer = super.startActivityNormallyOpenCollectionWithIntent( + Previewer::class.java, + previewIntent + ) AbstractFlashcardViewer.editorCard = usableCard return previewer } diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt index 878bd1f881d6..27cb4b83e2e9 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt @@ -49,14 +49,22 @@ class ReviewerTest : RobolectricTest() { @Test fun verifyStartupNoCollection() { enableNullCollection() - ActivityScenario.launch(Reviewer::class.java).use { scenario -> scenario.onActivity { reviewer: Reviewer -> assertFailsWith { reviewer.getColUnsafe } } } + ActivityScenario.launch(Reviewer::class.java) + .use { scenario -> scenario.onActivity { reviewer: Reviewer -> assertFailsWith { reviewer.getColUnsafe } } } } @Ignore("flaky") @Test @RunInBackground fun verifyNormalStartup() { - ActivityScenario.launch(Reviewer::class.java).use { scenario -> scenario.onActivity { reviewer: Reviewer -> assertNotNull("Collection should be non-null", reviewer.getColUnsafe) } } + ActivityScenario.launch(Reviewer::class.java).use { scenario -> + scenario.onActivity { reviewer: Reviewer -> + assertNotNull( + "Collection should be non-null", + reviewer.getColUnsafe + ) + } + } } @Ignore("flaky") @@ -95,7 +103,11 @@ class ReviewerTest : RobolectricTest() { val visibleButtons: List = reviewer.getVisibleButtonNames() - assertThat("No menu items should be visible if all are disabled in Settings - Reviewer - App Bar Buttons", visibleButtons, empty()) + assertThat( + "No menu items should be visible if all are disabled in Settings - Reviewer - App Bar Buttons", + visibleButtons, + empty() + ) } @Test @@ -108,7 +120,11 @@ class ReviewerTest : RobolectricTest() { val visibleButtons = reviewer.getVisibleButtonNamesExcept(R.id.action_toggle_whiteboard) - assertThat("No menu items should be visible if all are disabled in Settings - Reviewer - App Bar Buttons", visibleButtons, empty()) + assertThat( + "No menu items should be visible if all are disabled in Settings - Reviewer - App Bar Buttons", + visibleButtons, + empty() + ) } @Test @@ -178,7 +194,10 @@ class ReviewerTest : RobolectricTest() { time.addM(2) reviewer.answerCard(Consts.BUTTON_THREE) advanceRobolectricLooperWithSleep() - equalFirstField(cards[0], reviewer.currentCard!!) // This failed in #6898 because this card was not in the queue + equalFirstField( + cards[0], + reviewer.currentCard!! + ) // This failed in #6898 because this card was not in the queue } @Test @@ -296,7 +315,10 @@ class ReviewerTest : RobolectricTest() { revCount ) - assertThat(countList.toString(), equalTo(expected.toString())) // We use toString as hamcrest does not print the whole array and stops at [0]. + assertThat( + countList.toString(), + equalTo(expected.toString()) + ) // We use toString as hamcrest does not print the whole array and stops at [0]. } private fun answerCardOrdinalAsGood(r: Reviewer, i: Int) { @@ -359,7 +381,7 @@ class ReviewerTest : RobolectricTest() { reviewCard.queue = Consts.QUEUE_TYPE_REV reviewCard.type = Consts.CARD_TYPE_REV reviewCard.due = 0 - reviewCard.flush() + reviewCard.col.updateCard(reviewCard, skipUndoEntry = true) } private class ReviewerForMenuItems : Reviewer() { diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/services/NoteServiceTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/services/NoteServiceTest.kt index 5fc65de224d6..78a5f8321afa 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/services/NoteServiceTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/services/NoteServiceTest.kt @@ -254,7 +254,7 @@ class NoteServiceTest : RobolectricTest() { card.apply { type = Consts.CARD_TYPE_REV factor = 3000 / (i + 1) - flush() + col.updateCard(this, skipUndoEntry = true) } } // avg ease = (3000/10 + 1500/10 + 100/10 + 750/10) / 4 = [156.25] = 156 @@ -263,7 +263,7 @@ class NoteServiceTest : RobolectricTest() { // test case: one card is new note.cards()[2].apply { type = Consts.CARD_TYPE_NEW - flush() + col.updateCard(this, skipUndoEntry = true) } // avg ease = (3000/10 + 1500/10 + 750/10) / 3 = [175] = 175 assertEquals(175, NoteService.avgEase(note)) @@ -271,7 +271,7 @@ class NoteServiceTest : RobolectricTest() { // test case: all cards are new for (card in note.cards()) { card.type = Consts.CARD_TYPE_NEW - card.flush() + card.col.updateCard(card, skipUndoEntry = true) } // no cards are rev, so avg ease cannot be calculated assertEquals(null, NoteService.avgEase(note)) @@ -289,7 +289,7 @@ class NoteServiceTest : RobolectricTest() { card.apply { type = reviewOrRelearningList.shuffled().first() ivl = 3000 / (i + 1) - flush() + col.updateCard(this, skipUndoEntry = true) } } @@ -299,7 +299,7 @@ class NoteServiceTest : RobolectricTest() { // case: one card is new or learning note.cards()[2].apply { type = newOrLearningList.shuffled().first() - flush() + col.updateCard(this, skipUndoEntry = true) } // avg interval = (3000 + 1500 + 750) / 3 = [1750] = 1750 @@ -308,7 +308,7 @@ class NoteServiceTest : RobolectricTest() { // case: all cards are new or learning for (card in note.cards()) { card.type = newOrLearningList.shuffled().first() - card.flush() + card.col.updateCard(card, skipUndoEntry = true) } // no cards are rev or relearning, so avg interval cannot be calculated diff --git a/AnkiDroid/src/test/java/com/ichi2/libanki/CollectionTest.kt b/AnkiDroid/src/test/java/com/ichi2/libanki/CollectionTest.kt index e386272ba064..aa567dca021e 100644 --- a/AnkiDroid/src/test/java/com/ichi2/libanki/CollectionTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/libanki/CollectionTest.kt @@ -36,7 +36,7 @@ class CollectionTest : JvmTest() { val did = addDeck("Testing") for (c in n.cards()) { c.did = did - c.flush() + c.col.updateCard(c, skipUndoEntry = true) } assertThat("two cloze notes should be generated", n.numberOfCards(), equalTo(2)) diff --git a/AnkiDroid/src/test/java/com/ichi2/libanki/FinderTest.kt b/AnkiDroid/src/test/java/com/ichi2/libanki/FinderTest.kt index 37bd3a8e9760..dc9c2d667e0b 100644 --- a/AnkiDroid/src/test/java/com/ichi2/libanki/FinderTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/libanki/FinderTest.kt @@ -176,17 +176,17 @@ class FinderTest : JvmTest() { c.queue = QUEUE_TYPE_REV c.type = CARD_TYPE_REV assertEquals(0, col.findCards("is:review").size) - c.flush() + c.col.updateCard(c, skipUndoEntry = true) AnkiAssert.assertEqualsArrayList(arrayOf(c.id), col.findCards("is:review")) assertEquals(0, col.findCards("is:due").size) c.due = 0 c.queue = QUEUE_TYPE_REV - c.flush() + c.col.updateCard(c, skipUndoEntry = true) AnkiAssert.assertEqualsArrayList(arrayOf(c.id), col.findCards("is:due")) assertEquals(4, col.findCards("-is:due").size) c.queue = QUEUE_TYPE_SUSPENDED // ensure this card gets a later mod time - c.flush() + c.col.updateCard(c, skipUndoEntry = true) col.db.execute("update cards set mod = mod + 1 where id = ?", c.id) AnkiAssert.assertEqualsArrayList(arrayOf(c.id), col.findCards("is:suspended")) // nids diff --git a/AnkiDroid/src/test/java/com/ichi2/libanki/FlagTest.kt b/AnkiDroid/src/test/java/com/ichi2/libanki/FlagTest.kt index ab226a1a8be2..d1f56f286d7d 100644 --- a/AnkiDroid/src/test/java/com/ichi2/libanki/FlagTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/libanki/FlagTest.kt @@ -37,7 +37,7 @@ class FlagTest : JvmTest() { // make sure higher bits are preserved val origBits = 0b101 shl 3 c.setFlag(origBits) - c.flush() + c.col.updateCard(c, skipUndoEntry = true) // no flags to start with assertEquals(0, c.userFlag()) assertEquals(1, col.findCards("flag:0").size) diff --git a/AnkiDroid/src/test/java/com/ichi2/libanki/SchedulerTest.kt b/AnkiDroid/src/test/java/com/ichi2/libanki/SchedulerTest.kt index 3e129ce2c5c9..a2f5283933d9 100644 --- a/AnkiDroid/src/test/java/com/ichi2/libanki/SchedulerTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/libanki/SchedulerTest.kt @@ -290,7 +290,7 @@ open class SchedulerTest : JvmTest() { // or normal removal c.type = CARD_TYPE_NEW c.queue = QUEUE_TYPE_LRN - c.flush() + c.col.updateCard(c, skipUndoEntry = true) col.sched.answerCard(c, BUTTON_FOUR) Assert.assertEquals(CARD_TYPE_REV, c.type) Assert.assertEquals(QUEUE_TYPE_REV, c.queue) @@ -316,7 +316,7 @@ open class SchedulerTest : JvmTest() { queue = QUEUE_TYPE_REV type = CARD_TYPE_REV } - c.flush() + c.col.updateCard(c, skipUndoEntry = true) // fail the card c = col.sched.card!! @@ -346,7 +346,7 @@ open class SchedulerTest : JvmTest() { queue = QUEUE_TYPE_REV type = CARD_TYPE_REV } - c.flush() + c.col.updateCard(c, skipUndoEntry = true) val conf = col.decks.confForDid(1) conf.getJSONObject("lapse").put("delays", JSONArray(doubleArrayOf())) col.decks.save(conf) @@ -413,7 +413,7 @@ open class SchedulerTest : JvmTest() { assertNull(col.sched.card) // for testing, move it back a day c.due = c.due - 1 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) c = col.sched.card!! // nextIvl should work @@ -426,7 +426,7 @@ open class SchedulerTest : JvmTest() { col.sched.answerCard(c, BUTTON_THREE) // simulate the passing of another two days c.due = c.due - 2 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) // the last pass should graduate it into a review card Assert.assertEquals(SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_THREE)) col.sched.answerCard(c, BUTTON_THREE) @@ -435,7 +435,7 @@ open class SchedulerTest : JvmTest() { // if the lapse step is tomorrow, failing it should handle the counts // correctly c.due = 0 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) Assert.assertEquals(Counts(0, 0, 1), col.sched.counts()) conf = col.sched._cardConf(c) conf.getJSONObject("lapse").put("delays", JSONArray(doubleArrayOf(1440.0))) @@ -467,13 +467,13 @@ open class SchedulerTest : JvmTest() { ivl = 100 } c.startTimer() - c.flush() + c.col.updateCard(c, skipUndoEntry = true) // save it for later use as well val cardcopy = c.clone() // try with an ease of 2 // ////////////////////////////////////////////////////////////////////////////////////////////////// c = cardcopy.clone() - c.flush() + c.col.updateCard(c, skipUndoEntry = true) col.sched.answerCard(c, BUTTON_TWO) Assert.assertEquals(QUEUE_TYPE_REV, c.queue) // the new interval should be (100) * 1.2 = 120 @@ -487,7 +487,7 @@ open class SchedulerTest : JvmTest() { // ease 3 // ////////////////////////////////////////////////////////////////////////////////////////////////// c = cardcopy.clone() - c.flush() + c.col.updateCard(c, skipUndoEntry = true) col.sched.answerCard(c, BUTTON_THREE) // the new interval should be (100 + 8/2) * 2.5 = 260 Assert.assertTrue(AnkiAssert.checkRevIvl(c, 260)) @@ -497,7 +497,7 @@ open class SchedulerTest : JvmTest() { // ease 4 // ////////////////////////////////////////////////////////////////////////////////////////////////// c = cardcopy.clone() - c.flush() + c.col.updateCard(c, skipUndoEntry = true) col.sched.answerCard(c, BUTTON_FOUR) // the new interval should be (100 + 8) * 2.5 * 1.3 = 351 Assert.assertTrue(AnkiAssert.checkRevIvl(c, 351)) @@ -511,7 +511,7 @@ open class SchedulerTest : JvmTest() { col.decks.save(conf) c = cardcopy.clone() c.lapses = 7 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) /* todo hook // steup hook hooked = new [] {}; @@ -543,7 +543,7 @@ open class SchedulerTest : JvmTest() { c.setReps(1) c.ivl = 1 c.startTimer() - c.flush() + c.col.updateCard(c, skipUndoEntry = true) // Upstream, there is no space in 2d Assert.assertEquals( "2d", @@ -697,7 +697,7 @@ open class SchedulerTest : JvmTest() { c.type = CARD_TYPE_RELEARNING c.ivl = 100 c.factor = STARTING_FACTOR - c.flush() + c.col.updateCard(c, skipUndoEntry = true) Assert.assertEquals(60, col.sched.nextIvl(c, BUTTON_ONE)) Assert.assertEquals(100 * SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_THREE)) Assert.assertEquals(101 * SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_FOUR)) @@ -707,7 +707,7 @@ open class SchedulerTest : JvmTest() { c.queue = QUEUE_TYPE_REV c.ivl = 100 c.factor = STARTING_FACTOR - c.flush() + c.col.updateCard(c, skipUndoEntry = true) // failing it should put it at 60s Assert.assertEquals(60, col.sched.nextIvl(c, BUTTON_ONE)) // or 1 day if relearn is false @@ -784,7 +784,7 @@ open class SchedulerTest : JvmTest() { c.ivl = 100 c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV - c.flush() + c.col.updateCard(c, skipUndoEntry = true) c = col.sched.card!! col.sched.answerCard(c, BUTTON_ONE) MatcherAssert.assertThat( @@ -802,7 +802,7 @@ open class SchedulerTest : JvmTest() { Assert.assertEquals(due, c.due) // should cope with cards in cram decks c.due = 1 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) addDynamicDeck("tmp") col.sched.rebuildDyn() c.load() @@ -834,7 +834,7 @@ open class SchedulerTest : JvmTest() { } c.startTimer() - c.flush() + c.col.updateCard(c, skipUndoEntry = true) Assert.assertEquals(Counts(0, 0, 0), col.sched.counts()) // create a dynamic deck and refresh it val did = addDynamicDeck("Cram") @@ -852,7 +852,7 @@ open class SchedulerTest : JvmTest() { (75 * 1.2).roundToInt() * SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_TWO) ) - val toLong = fun (v: Double) = v.roundToLong() * SECONDS_PER_DAY + val toLong = fun(v: Double) = v.roundToLong() * SECONDS_PER_DAY MatcherAssert.assertThat( col.sched.nextIvl(c, BUTTON_THREE), equalTo(toLong(75 * 2.5)) @@ -878,7 +878,7 @@ open class SchedulerTest : JvmTest() { // due in 75 days, so it's been waiting 25 days c.ivl = 100 c.due = (col.sched.today + 75).toLong() - c.flush() + c.col.updateCard(c, skipUndoEntry = true) col.sched.rebuildDyn(did) c = col.sched.card!! Assert.assertEquals(60 * SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_TWO)) @@ -1101,7 +1101,7 @@ open class SchedulerTest : JvmTest() { c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV c.due = col.sched.today.toLong() - c.flush() + c.col.updateCard(c, skipUndoEntry = true) Assert.assertEquals(Counts(0, 0, 1), col.sched.counts()) col.sched.answerCard(col.sched.card!!, BUTTON_ONE) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) @@ -1120,7 +1120,7 @@ open class SchedulerTest : JvmTest() { c.type = CARD_TYPE_REV c.queue = QUEUE_TYPE_REV c.due = 0 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) } // fail the first one var c = col.sched.card!! @@ -1130,7 +1130,7 @@ open class SchedulerTest : JvmTest() { Assert.assertEquals(QUEUE_TYPE_REV, c2.queue) // if the failed card becomes due, it should show first c.due = time.intTime() - 1 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) c = col.sched.card!! Assert.assertEquals(QUEUE_TYPE_LRN, c.queue) } @@ -1169,7 +1169,7 @@ open class SchedulerTest : JvmTest() { val c = note.cards()[0] c.queue = QUEUE_TYPE_REV c.due = 0 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) // add one more with a new deck note = col.newNote() note.setItem("Front", "two") @@ -1195,7 +1195,7 @@ open class SchedulerTest : JvmTest() { Assert.assertEquals(0, value.newCount.toLong()) // code should not fail if a card has an invalid deck c.did = 12345 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) col.sched.deckDueTree() } @@ -1299,7 +1299,7 @@ open class SchedulerTest : JvmTest() { c.type = CARD_TYPE_REV c.ivl = 100 c.due = 0 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) Assert.assertEquals(Counts(0, 0, 1), col.sched.counts()) col.sched.forgetCards(listOf(c.id)) Assert.assertEquals(Counts(1, 0, 0), col.sched.counts()) @@ -1343,7 +1343,7 @@ open class SchedulerTest : JvmTest() { c.lapses = 1 c.ivl = 100 c.startTimer() - c.flush() + c.col.updateCard(c, skipUndoEntry = true) col.sched.answerCard(c, BUTTON_ONE) col.sched._cardConf(c).getJSONObject("lapse").put("delays", JSONArray(doubleArrayOf())) col.sched.answerCard(c, BUTTON_ONE) @@ -1366,7 +1366,7 @@ open class SchedulerTest : JvmTest() { c.setReps(3) c.lapses = 1 c.startTimer() - c.flush() + c.col.updateCard(c, skipUndoEntry = true) val conf = col.sched._cardConf(c) conf.getJSONObject("lapse").put("mult", 0.5) col.decks.save(conf) @@ -1393,7 +1393,7 @@ open class SchedulerTest : JvmTest() { c.due = -5 c.queue = QUEUE_TYPE_REV c.ivl = 5 - c.flush() + c.col.updateCard(c, skipUndoEntry = true) // into and out of filtered deck val did = addDynamicDeck("Cram")