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 b0cc47dccf3b..5abac67fefc9 100644 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt +++ b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt @@ -24,8 +24,8 @@ import android.content.ContentValues import android.database.CursorWindow import android.net.Uri import anki.notetypes.StockNotetype -import com.ichi2.anki.AbstractFlashcardViewer import com.ichi2.anki.CollectionManager +import com.ichi2.anki.Ease import com.ichi2.anki.FlashCardsContract import com.ichi2.anki.provider.pureAnswer import com.ichi2.anki.testutil.DatabaseUtils.cursorFillWindow @@ -1066,12 +1066,12 @@ class ContentProviderTest : InstrumentedTest() { val reviewInfoUri = FlashCardsContract.ReviewInfo.CONTENT_URI val noteId = card.nid val cardOrd = card.ord - val earlyGraduatingEase = AbstractFlashcardViewer.EASE_4 + val earlyGraduatingEase = Ease.EASY val values = ContentValues().apply { val timeTaken: Long = 5000 // 5 seconds put(FlashCardsContract.ReviewInfo.NOTE_ID, noteId) put(FlashCardsContract.ReviewInfo.CARD_ORD, cardOrd) - put(FlashCardsContract.ReviewInfo.EASE, earlyGraduatingEase) + put(FlashCardsContract.ReviewInfo.EASE, earlyGraduatingEase.value) put(FlashCardsContract.ReviewInfo.TIME_TAKEN, timeTaken) } val updateCount = cr.update(reviewInfoUri, values, null, null) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt index 61c54f2d197b..5c677fc1f01d 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt @@ -132,7 +132,6 @@ import com.ichi2.libanki.CardId import com.ichi2.libanki.ChangeManager import com.ichi2.libanki.Collection import com.ichi2.libanki.Consts -import com.ichi2.libanki.Consts.ButtonType import com.ichi2.libanki.DeckId import com.ichi2.libanki.Decks import com.ichi2.libanki.Sound.getAvTag @@ -252,7 +251,7 @@ abstract class AbstractFlashcardViewer : private val clipboard: ClipboardManager? = null private var previousAnswerIndicator: PreviousAnswerIndicator? = null - private var currentEase = 0 + private var currentEase: Ease? = null private var initialFlipCardHeight = 0 private var buttonHeightSet = false @@ -416,26 +415,26 @@ abstract class AbstractFlashcardViewer : automaticAnswer.onSelectEase() when (view.id) { R.id.flashcard_layout_ease1 -> { - Timber.i("AbstractFlashcardViewer:: EASE_1 pressed") - answerCard(Consts.BUTTON_ONE) + Timber.i("AbstractFlashcardViewer:: Ease_1 pressed") + answerCard(Ease.AGAIN) } R.id.flashcard_layout_ease2 -> { - Timber.i("AbstractFlashcardViewer:: EASE_2 pressed") - answerCard(Consts.BUTTON_TWO) + Timber.i("AbstractFlashcardViewer:: Ease_2 pressed") + answerCard(Ease.HARD) } R.id.flashcard_layout_ease3 -> { - Timber.i("AbstractFlashcardViewer:: EASE_3 pressed") - answerCard(Consts.BUTTON_THREE) + Timber.i("AbstractFlashcardViewer:: Ease_3 pressed") + answerCard(Ease.GOOD) } R.id.flashcard_layout_ease4 -> { - Timber.i("AbstractFlashcardViewer:: EASE_4 pressed") - answerCard(Consts.BUTTON_FOUR) + Timber.i("AbstractFlashcardViewer:: Ease_4 pressed") + answerCard(Ease.EASY) } - else -> currentEase = 0 + else -> currentEase = null } if (!hasBeenTouched) { view.isPressed = false @@ -856,7 +855,7 @@ abstract class AbstractFlashcardViewer : } } - open fun answerCard(@ButtonType ease: Int) = preventSimultaneousExecutions(ANSWER_CARD) { + open fun answerCard(ease: Ease) = preventSimultaneousExecutions(ANSWER_CARD) { launchCatchingTask { if (inAnswer) { return@launchCatchingTask @@ -876,7 +875,7 @@ abstract class AbstractFlashcardViewer : } } - open suspend fun answerCardInner(@ButtonType ease: Int) { + open suspend fun answerCardInner(ease: Ease) { // Legacy tests assume they can call answerCard() even outside of Reviewer withCol { sched.answerCard(currentCard!!, ease) @@ -897,25 +896,25 @@ abstract class AbstractFlashcardViewer : gestureDetector = GestureDetector(this, gestureDetectorImpl) easeButtonsLayout = findViewById(R.id.ease_buttons) easeButton1 = EaseButton( - EASE_1, + Ease.AGAIN, findViewById(R.id.flashcard_layout_ease1), findViewById(R.id.ease1), findViewById(R.id.nextTime1) ).apply { setListeners(easeHandler) } easeButton2 = EaseButton( - EASE_2, + Ease.HARD, findViewById(R.id.flashcard_layout_ease2), findViewById(R.id.ease2), findViewById(R.id.nextTime2) ).apply { setListeners(easeHandler) } easeButton3 = EaseButton( - EASE_3, + Ease.GOOD, findViewById(R.id.flashcard_layout_ease3), findViewById(R.id.ease3), findViewById(R.id.nextTime3) ).apply { setListeners(easeHandler) } easeButton4 = EaseButton( - EASE_4, + Ease.EASY, findViewById(R.id.flashcard_layout_ease4), findViewById(R.id.ease4), findViewById(R.id.nextTime4) @@ -1059,7 +1058,7 @@ abstract class AbstractFlashcardViewer : } /** If a card is displaying the question, flip it, otherwise answer it */ - internal open fun flipOrAnswerCard(cardOrdinal: Int) { + internal open fun flipOrAnswerCard(cardOrdinal: Ease) { if (!displayAnswer) { displayCardAnswer() return @@ -1624,22 +1623,22 @@ abstract class AbstractFlashcardViewer : } ViewerCommand.FLIP_OR_ANSWER_EASE1 -> { - flipOrAnswerCard(EASE_1) + flipOrAnswerCard(Ease.AGAIN) true } ViewerCommand.FLIP_OR_ANSWER_EASE2 -> { - flipOrAnswerCard(EASE_2) + flipOrAnswerCard(Ease.HARD) true } ViewerCommand.FLIP_OR_ANSWER_EASE3 -> { - flipOrAnswerCard(EASE_3) + flipOrAnswerCard(Ease.GOOD) true } ViewerCommand.FLIP_OR_ANSWER_EASE4 -> { - flipOrAnswerCard(EASE_4) + flipOrAnswerCard(Ease.EASY) true } @@ -1793,13 +1792,13 @@ abstract class AbstractFlashcardViewer : } } - protected open fun performClickWithVisualFeedback(ease: Int) { + protected open fun performClickWithVisualFeedback(ease: Ease) { // Delay could potentially be lower - testing with 20 left a visible "click" when (ease) { - EASE_1 -> easeButton1!!.performClickWithVisualFeedback() - EASE_2 -> easeButton2!!.performClickWithVisualFeedback() - EASE_3 -> easeButton3!!.performClickWithVisualFeedback() - EASE_4 -> easeButton4!!.performClickWithVisualFeedback() + Ease.AGAIN -> easeButton1!!.performClickWithVisualFeedback() + Ease.HARD -> easeButton2!!.performClickWithVisualFeedback() + Ease.GOOD -> easeButton3!!.performClickWithVisualFeedback() + Ease.EASY -> easeButton4!!.performClickWithVisualFeedback() } } @@ -2418,22 +2417,22 @@ abstract class AbstractFlashcardViewer : } WebViewSignalParserUtils.ANSWER_ORDINAL_1 -> { - flipOrAnswerCard(EASE_1) + flipOrAnswerCard(Ease.AGAIN) return true } WebViewSignalParserUtils.ANSWER_ORDINAL_2 -> { - flipOrAnswerCard(EASE_2) + flipOrAnswerCard(Ease.HARD) return true } WebViewSignalParserUtils.ANSWER_ORDINAL_3 -> { - flipOrAnswerCard(EASE_3) + flipOrAnswerCard(Ease.GOOD) return true } WebViewSignalParserUtils.ANSWER_ORDINAL_4 -> { - flipOrAnswerCard(EASE_4) + flipOrAnswerCard(Ease.EASY) return true } @@ -2639,14 +2638,6 @@ abstract class AbstractFlashcardViewer : const val RESULT_NO_MORE_CARDS = 52 const val RESULT_ABORT_AND_SYNC = 53 - /** - * Available options performed by other activities. - */ - const val EASE_1 = 1 - const val EASE_2 = 2 - const val EASE_3 = 3 - const val EASE_4 = 4 - /** * Time to wait in milliseconds before resuming fullscreen mode * diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt b/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt index d16eac520e61..f218a3494c60 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt @@ -318,19 +318,19 @@ open class AnkiDroidJsAPI(private val activity: AbstractFlashcardViewer) { convertToByteArray(apiContract, true) } "answerEase1" -> { - activity.flipOrAnswerCard(AbstractFlashcardViewer.EASE_1) + activity.flipOrAnswerCard(Ease.AGAIN) convertToByteArray(apiContract, true) } "answerEase2" -> { - activity.flipOrAnswerCard(AbstractFlashcardViewer.EASE_2) + activity.flipOrAnswerCard(Ease.HARD) convertToByteArray(apiContract, true) } "answerEase3" -> { - activity.flipOrAnswerCard(AbstractFlashcardViewer.EASE_3) + activity.flipOrAnswerCard(Ease.GOOD) convertToByteArray(apiContract, true) } "answerEase4" -> { - activity.flipOrAnswerCard(AbstractFlashcardViewer.EASE_4) + activity.flipOrAnswerCard(Ease.EASY) convertToByteArray(apiContract, true) } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/Ease.kt b/AnkiDroid/src/main/java/com/ichi2/anki/Ease.kt index 632fd2ec7b45..e6eff9c38a35 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/Ease.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/Ease.kt @@ -17,10 +17,17 @@ package com.ichi2.anki /** * [value] should be kept in sync with the [com.ichi2.anki.api.Ease] enum. + * + * @param value The so called value of the button. For the sake of consistency with upstream and our API + * the buttons are numbered from 1 to 4. */ enum class Ease(val value: Int) { AGAIN(1), HARD(2), GOOD(3), EASY(4); + + companion object { + fun Int.toEase() = entries.first { this == it.value } + } } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt b/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt index 0155f76eac5f..b144dd3dc4b9 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt @@ -1064,7 +1064,7 @@ open class Reviewer : queueState = state } - override suspend fun answerCardInner(ease: Int) { + override suspend fun answerCardInner(ease: Ease) { val state = queueState!! Timber.d("answerCardInner: ${currentCard!!.id} $ease") var wasLeech = false @@ -1073,7 +1073,7 @@ open class Reviewer : wasLeech = sched.stateIsLeech(state.states.again) } }.also { - if (ease == Consts.BUTTON_ONE && wasLeech) { + if (ease == Ease.AGAIN && wasLeech) { state.topCard.load(getColUnsafe) val leechMessage: String = if (state.topCard.queue < 0) { resources.getString(R.string.leech_suspend_notification) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/provider/CardContentProvider.kt b/AnkiDroid/src/main/java/com/ichi2/anki/provider/CardContentProvider.kt index d4c8fea50294..9503ecce7ebc 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/provider/CardContentProvider.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/provider/CardContentProvider.kt @@ -32,12 +32,13 @@ import com.ichi2.anki.AnkiDroidApp import com.ichi2.anki.BuildConfig import com.ichi2.anki.CollectionManager import com.ichi2.anki.CrashReportService +import com.ichi2.anki.Ease +import com.ichi2.anki.Ease.Companion.toEase import com.ichi2.anki.FlashCardsContract import com.ichi2.anki.utils.ext.description import com.ichi2.libanki.Card import com.ichi2.libanki.Collection import com.ichi2.libanki.Consts -import com.ichi2.libanki.Consts.ButtonType import com.ichi2.libanki.Deck import com.ichi2.libanki.DeckId import com.ichi2.libanki.Decks @@ -346,7 +347,7 @@ class CardContentProvider : ContentProvider() { val buttonTexts = JSONArray() var i = 0 while (i < buttonCount) { - buttonTexts.put(col.sched.nextIvlStr(currentCard, i + 1)) + buttonTexts.put(col.sched.nextIvlStr(currentCard, (i + 1).toEase())) i++ } addReviewInfoToCursor(currentCard, buttonTexts, buttonCount, rv, col, columns) @@ -590,7 +591,7 @@ class CardContentProvider : ContentProvider() { val valueSet = values!!.valueSet() var cardOrd = -1 var noteID: Long = -1 - var ease = -1 + var ease: Ease? = null var timeTaken: Long = -1 var bury = -1 var suspend = -1 @@ -598,7 +599,10 @@ class CardContentProvider : ContentProvider() { when (key) { FlashCardsContract.ReviewInfo.NOTE_ID -> noteID = values.getAsLong(key) FlashCardsContract.ReviewInfo.CARD_ORD -> cardOrd = values.getAsInteger(key) - FlashCardsContract.ReviewInfo.EASE -> ease = values.getAsInteger(key) + FlashCardsContract.ReviewInfo.EASE -> { + // The value corresponds to + ease = values.getAsInteger(key).toEase() + } FlashCardsContract.ReviewInfo.TIME_TAKEN -> timeTaken = values.getAsLong(key) @@ -619,7 +623,7 @@ class CardContentProvider : ContentProvider() { // suspend card buryOrSuspendCard(col, cardToAnswer, false) } else { - answerCard(col, cardToAnswer, ease, timeTaken) + answerCard(col, cardToAnswer, ease!!, timeTaken) } updated++ } else { @@ -1080,7 +1084,7 @@ class CardContentProvider : ContentProvider() { } } - private fun answerCard(col: Collection, cardToAnswer: Card?, @ButtonType ease: Int, timeTaken: Long) { + private fun answerCard(col: Collection, cardToAnswer: Card?, ease: Ease, timeTaken: Long) { try { if (cardToAnswer != null) { if (timeTaken != -1L) { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/reviewer/EaseButton.kt b/AnkiDroid/src/main/java/com/ichi2/anki/reviewer/EaseButton.kt index 2596b442c472..60326ba9e975 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/reviewer/EaseButton.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/reviewer/EaseButton.kt @@ -23,6 +23,8 @@ import android.widget.LinearLayout import android.widget.TextView import androidx.annotation.StringRes import com.ichi2.anki.AbstractFlashcardViewer +import com.ichi2.anki.Ease +import com.ichi2.utils.KotlinCleanup /** * The UI of an ease button @@ -31,7 +33,7 @@ import com.ichi2.anki.AbstractFlashcardViewer * * [nextTime] is used by the API * * [canPerformClick] is used to determine if the answer is being shown and the button isn't blocked */ -class EaseButton(private val ease: Int, private val layout: LinearLayout, private val easeTextView: TextView, private val easeTimeView: TextView) { +class EaseButton(private val ease: Ease, private val layout: LinearLayout, private val easeTextView: TextView, private val easeTimeView: TextView) { var height: Int get() = layout.layoutParams.height @@ -97,7 +99,8 @@ class EaseButton(private val ease: Int, private val layout: LinearLayout, privat * * @param currentEase The current ease of the card */ - fun unblockBasedOnEase(currentEase: Int) { + @KotlinCleanup("Make the type non nullable.") + fun unblockBasedOnEase(currentEase: Ease?) { if (this.ease == currentEase) { layout.isClickable = true } else { @@ -110,7 +113,7 @@ class EaseButton(private val ease: Int, private val layout: LinearLayout, privat * * @param currentEase The current ease of the card */ - fun blockBasedOnEase(currentEase: Int) { + fun blockBasedOnEase(currentEase: Ease) { if (this.ease == currentEase) { layout.isClickable = false } else { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/reviewer/PreviousAnswerIndicator.kt b/AnkiDroid/src/main/java/com/ichi2/anki/reviewer/PreviousAnswerIndicator.kt index 378497ccc145..cc26b4200798 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/reviewer/PreviousAnswerIndicator.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/reviewer/PreviousAnswerIndicator.kt @@ -17,11 +17,9 @@ package com.ichi2.anki.reviewer import android.widget.TextView -import com.ichi2.anki.AbstractFlashcardViewer +import com.ichi2.anki.Ease import com.ichi2.anki.R -import com.ichi2.anki.reviewer.PreviousAnswerIndicator.Companion.CHOSEN_ANSWER_DURATION_MS import com.ichi2.utils.HandlerUtils.newHandler -import timber.log.Timber /** * A visual element in the top bar showing a number of colored dots based on the previous answer @@ -49,25 +47,24 @@ class PreviousAnswerIndicator(private val chosenAnswerText: TextView) { * * @param ease The ordinal of the button answered */ - fun displayAnswerIndicator(ease: Int) { + fun displayAnswerIndicator(ease: Ease) { when (ease) { - AbstractFlashcardViewer.EASE_1 -> { + Ease.AGAIN -> { chosenAnswerText.text = "\u2022" chosenAnswerText.setTextColor(getColor(R.color.material_red_500)) } - AbstractFlashcardViewer.EASE_2 -> { + Ease.HARD -> { chosenAnswerText.text = "\u2022\u2022" chosenAnswerText.setTextColor(getColor(R.color.material_blue_grey_600)) } - AbstractFlashcardViewer.EASE_3 -> { + Ease.GOOD -> { chosenAnswerText.text = "\u2022\u2022\u2022" chosenAnswerText.setTextColor(getColor(R.color.material_green_500)) } - AbstractFlashcardViewer.EASE_4 -> { + Ease.EASY -> { chosenAnswerText.text = "\u2022\u2022\u2022\u2022" chosenAnswerText.setTextColor(getColor(R.color.material_light_blue_500)) } - else -> Timber.w("Unknown easy type %s", ease) } // remove chosen answer hint after a while diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt index 569f18c8bdcc..d238ca142ad4 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt @@ -356,7 +356,7 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : private fun answerCard(ease: Ease) { launchCatchingIO { queueState.await()?.let { - undoableOp { sched.answerCard(it, ease.value) } + undoableOp { sched.answerCard(it, ease) } updateCurrentCard() } } diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt index 2bf49224a917..1c5271939e69 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt @@ -77,16 +77,6 @@ object Consts { // Leech actions const val LEECH_SUSPEND = 0 - // Buttons - const val BUTTON_ONE = 1 - const val BUTTON_TWO = 2 - const val BUTTON_THREE = 3 - const val BUTTON_FOUR = 4 - - @Retention(AnnotationRetention.SOURCE) - @IntDef(BUTTON_ONE, BUTTON_TWO, BUTTON_THREE, BUTTON_FOUR) - annotation class ButtonType - // The labels defined in consts.py are in AnkiDroid's resources files. const val DEFAULT_DECK_ID: Long = 1 diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DummyScheduler.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DummyScheduler.kt index f50ce9d6e2da..d0522206a971 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DummyScheduler.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DummyScheduler.kt @@ -18,6 +18,7 @@ package com.ichi2.libanki.sched +import com.ichi2.anki.Ease import com.ichi2.libanki.Card import com.ichi2.libanki.Collection import java.lang.Exception @@ -25,7 +26,7 @@ import java.lang.Exception class DummyScheduler(col: Collection) : Scheduler(col) { override val card: Card? = null - override fun answerCard(card: Card, ease: Int) { + override fun answerCard(card: Card, ease: Ease) { throw Exception("v1/v2 scheduler not supported") } } diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Scheduler.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Scheduler.kt index db1ccca73347..706e7a96f45b 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Scheduler.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Scheduler.kt @@ -40,6 +40,7 @@ import anki.scheduler.SchedulingStates import anki.scheduler.UnburyDeckRequest import anki.scheduler.cardAnswer import anki.scheduler.scheduleCardsAsNewRequest +import com.ichi2.anki.Ease import com.ichi2.anki.utils.SECONDS_PER_DAY import com.ichi2.libanki.Card import com.ichi2.libanki.CardId @@ -132,14 +133,14 @@ open class Scheduler(val col: Collection) { private val queuedCards: QueuedCards get() = col.backend.getQueuedCards(fetchLimit = 1, intradayLearningOnly = false) - open fun answerCard(info: CurrentQueueState, ease: Int): OpChanges { + open fun answerCard(info: CurrentQueueState, ease: Ease): OpChanges { return col.backend.answerCard(buildAnswer(info.topCard, info.states, ease)).also { reps += 1 } } /** Legacy path, used by tests. */ - open fun answerCard(card: Card, ease: Int) { + open fun answerCard(card: Card, ease: Ease) { val top = queuedCards.cardsList.first() val answer = buildAnswer(card, top.states, ease) col.backend.answerCard(answer) @@ -154,7 +155,7 @@ open class Scheduler(val col: Collection) { return col.backend.stateIsLeech(state) } - fun buildAnswer(card: Card, states: SchedulingStates, ease: Int): CardAnswer { + fun buildAnswer(card: Card, states: SchedulingStates, ease: Ease): CardAnswer { return cardAnswer { cardId = card.id currentState = states.current @@ -165,13 +166,12 @@ open class Scheduler(val col: Collection) { } } - private fun ratingFromEase(ease: Int): CardAnswer.Rating { + private fun ratingFromEase(ease: Ease): CardAnswer.Rating { return when (ease) { - 1 -> CardAnswer.Rating.AGAIN - 2 -> CardAnswer.Rating.HARD - 3 -> CardAnswer.Rating.GOOD - 4 -> CardAnswer.Rating.EASY - else -> TODO("invalid ease: $ease") + Ease.AGAIN -> CardAnswer.Rating.AGAIN + Ease.HARD -> CardAnswer.Rating.HARD + Ease.GOOD -> CardAnswer.Rating.GOOD + Ease.EASY -> CardAnswer.Rating.EASY } } @@ -214,7 +214,7 @@ open class Scheduler(val col: Collection) { var reps: Int = 0 /** Only provided for legacy unit tests. */ - fun nextIvl(card: Card, ease: Int): Long { + fun nextIvl(card: Card, ease: Ease): Long { val states = col.backend.getSchedulingStates(card.id) val state = stateFromEase(states, ease) return intervalForState(state) @@ -684,7 +684,7 @@ open class Scheduler(val col: Collection) { * @param ease The button number (easy, good etc.) * @return A string like “1 min” or “1.7 mo” */ - open fun nextIvlStr(card: Card, @Consts.ButtonType ease: Int): String { + open fun nextIvlStr(card: Card, ease: Ease): String { val secs = nextIvl(card, ease) return col.backend.formatTimespan(secs.toFloat(), FormatTimespanRequest.Context.ANSWER_BUTTONS) } @@ -700,13 +700,12 @@ open class Scheduler(val col: Collection) { const val REPORT_LIMIT = 99999 -private fun stateFromEase(states: SchedulingStates, ease: Int): SchedulingState { +private fun stateFromEase(states: SchedulingStates, ease: Ease): SchedulingState { return when (ease) { - 1 -> states.again - 2 -> states.hard - 3 -> states.good - 4 -> states.easy - else -> TODO("invalid ease: $ease") + Ease.AGAIN -> states.again + Ease.HARD -> states.hard + Ease.GOOD -> states.good + Ease.EASY -> states.easy } } diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/AbstractFlashcardViewerTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/AbstractFlashcardViewerTest.kt index eaf38c266d18..caf29ebf1a5c 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/AbstractFlashcardViewerTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/AbstractFlashcardViewerTest.kt @@ -61,7 +61,7 @@ import com.ichi2.anim.ActivityTransitionAnimation.Direction as Direction @RunWith(AndroidJUnit4::class) class AbstractFlashcardViewerTest : RobolectricTest() { class NonAbstractFlashcardViewer : AbstractFlashcardViewer() { - var answered: Int? = null + var answered: Ease? = null private var lastTime = 0 override fun performReload() { // intentionally blank @@ -69,7 +69,7 @@ class AbstractFlashcardViewerTest : RobolectricTest() { val typedInput get() = typedInputText - override fun answerCard(ease: Int) { + override fun answerCard(ease: Ease) { super.answerCard(ease) answered = ease } diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerTest.kt index 0aef8c1ae9ea..40d59a10e600 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerTest.kt @@ -13,7 +13,6 @@ import androidx.core.content.pm.ShortcutManagerCompat import androidx.core.view.children import androidx.fragment.app.FragmentManager import androidx.test.core.app.ActivityScenario -import com.ichi2.anki.AbstractFlashcardViewer.Companion.EASE_4 import com.ichi2.anki.dialogs.DatabaseErrorDialog.DatabaseErrorDialogType import com.ichi2.anki.dialogs.DeckPickerContextMenu import com.ichi2.anki.dialogs.DeckPickerContextMenu.DeckPickerContextMenuOption @@ -670,7 +669,7 @@ class DeckPickerTest : RobolectricTest() { // Answer 'Easy' for one of the cards, burying the other col.decks.select(deckWithCards) col.sched.deckDueTree() // ? if not called, decks.select(toSelect) un-buries a card - col.sched.answerCard(col.sched.card!!, EASE_4) + col.sched.answerCard(col.sched.card!!, Ease.EASY) assertThat("the other card is buried", col.sched.card, nullValue()) // select a deck with no cards diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerKeyboardInputTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerKeyboardInputTest.kt index fa6aef390279..d8662c01863a 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerKeyboardInputTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerKeyboardInputTest.kt @@ -34,14 +34,13 @@ import android.view.KeyEvent.KEYCODE_Z import androidx.annotation.CheckResult import androidx.test.ext.junit.runners.AndroidJUnit4 import com.ibm.icu.impl.Assert -import com.ichi2.anki.AbstractFlashcardViewer.Companion.EASE_1 -import com.ichi2.anki.AbstractFlashcardViewer.Companion.EASE_2 -import com.ichi2.anki.AbstractFlashcardViewer.Companion.EASE_3 -import com.ichi2.anki.AbstractFlashcardViewer.Companion.EASE_4 import com.ichi2.anki.AnkiDroidApp.Companion.sharedPrefs +import com.ichi2.anki.Ease.AGAIN +import com.ichi2.anki.Ease.EASY +import com.ichi2.anki.Ease.GOOD +import com.ichi2.anki.Ease.HARD import com.ichi2.anki.cardviewer.Gesture import com.ichi2.anki.cardviewer.ViewerCommand -import com.ichi2.anki.preferences.sharedPrefs import com.ichi2.anki.reviewer.Binding.Companion.keyCode import com.ichi2.anki.reviewer.Binding.ModifierKeys import com.ichi2.anki.reviewer.CardSide @@ -71,28 +70,28 @@ class ReviewerKeyboardInputTest : RobolectricTest() { fun whenDisplayingAnswerTyping1AnswersFarLeftButton() { val underTest = KeyboardInputTestReviewer.displayingAnswer() underTest.handleAndroidKeyPress(KEYCODE_1) - assertThat(underTest.processedAnswer(), equalTo(EASE_1)) + assertThat(underTest.processedAnswer(), equalTo(AGAIN)) } @Test fun whenDisplayingAnswerTyping2AnswersSecondButton() { val underTest = KeyboardInputTestReviewer.displayingAnswer() underTest.handleAndroidKeyPress(KEYCODE_2) - assertThat(underTest.processedAnswer(), equalTo(EASE_2)) + assertThat(underTest.processedAnswer(), equalTo(HARD)) } @Test fun whenDisplayingAnswerTyping3AnswersThirdButton() { val underTest = KeyboardInputTestReviewer.displayingAnswer() underTest.handleAndroidKeyPress(KEYCODE_3) - assertThat(underTest.processedAnswer(), equalTo(EASE_3)) + assertThat(underTest.processedAnswer(), equalTo(GOOD)) } @Test fun whenDisplayingAnswerTyping4AnswersFarRightButton() { val underTest = KeyboardInputTestReviewer.displayingAnswer() underTest.handleAndroidKeyPress(KEYCODE_4) - assertThat(underTest.processedAnswer(), equalTo(EASE_4)) + assertThat(underTest.processedAnswer(), equalTo(EASY)) } /** START: DEFAULT IS "GOOD" */ @@ -100,28 +99,28 @@ class ReviewerKeyboardInputTest : RobolectricTest() { fun spaceAnswersThirdButtonWhenFourButtonsShowing() { val underTest = KeyboardInputTestReviewer.displayingAnswer().withButtons(4) underTest.handleSpacebar() - assertThat(underTest.processedAnswer(), equalTo(EASE_3)) + assertThat(underTest.processedAnswer(), equalTo(GOOD)) } /** END: DEFAULT IS "GOOD" */ @Test fun gamepadAAnswerFourthButtonOrShowsAnswer() { - assertGamepadButtonAnswers(KEYCODE_BUTTON_A, EASE_4) + assertGamepadButtonAnswers(KEYCODE_BUTTON_A, EASY) } @Test fun gamepadBAnswersThirdButtonOrShowsAnswer() { - assertGamepadButtonAnswers(KEYCODE_BUTTON_B, EASE_3) + assertGamepadButtonAnswers(KEYCODE_BUTTON_B, GOOD) } @Test fun gamepadXAnswersSecondButtonOrShowsAnswer() { - assertGamepadButtonAnswers(KEYCODE_BUTTON_X, EASE_2) + assertGamepadButtonAnswers(KEYCODE_BUTTON_X, HARD) } @Test fun gamepadYAnswersFirstButtonOrShowsAnswer() { - assertGamepadButtonAnswers(KEYCODE_BUTTON_Y, EASE_1) + assertGamepadButtonAnswers(KEYCODE_BUTTON_Y, AGAIN) } @Test @@ -219,7 +218,7 @@ class ReviewerKeyboardInputTest : RobolectricTest() { assertThat("After a second keypress the question should be displayed", !underTest.testIsDisplayingAnswer()) } - private fun assertGamepadButtonAnswers(keycodeButton: Int, ease: Int) { + private fun assertGamepadButtonAnswers(keycodeButton: Int, ease: Ease) { val underTest = KeyboardInputTestReviewer.displayingQuestion() assertThat("Assume: Initially should not display answer", !underTest.didDisplayAnswer()) underTest.handleGamepadPress(keycodeButton) @@ -231,7 +230,7 @@ class ReviewerKeyboardInputTest : RobolectricTest() { internal class KeyboardInputTestReviewer : Reviewer() { private var focusTextField = false - private var answered: Int? = null + private var answered: Ease? = null private var answerButtonCount = 4 var editCardCalled = false private set @@ -264,7 +263,7 @@ class ReviewerKeyboardInputTest : RobolectricTest() { displayAnswer = false } - override fun flipOrAnswerCard(cardOrdinal: Int) { + override fun flipOrAnswerCard(cardOrdinal: Ease) { if (displayAnswer) { answerCard(cardOrdinal) displayCardQuestion() @@ -353,12 +352,12 @@ class ReviewerKeyboardInputTest : RobolectricTest() { return this } - override fun answerCard(ease: Int) { + override fun answerCard(ease: Ease) { super.answerCard(ease) answered = ease } - fun processedAnswer(): Int { + fun processedAnswer(): Ease { if (answered == null) { Assert.fail("No card was answered") } @@ -426,7 +425,7 @@ class ReviewerKeyboardInputTest : RobolectricTest() { return answered != null } - override fun performClickWithVisualFeedback(ease: Int) { + override fun performClickWithVisualFeedback(ease: Ease) { answerCard(ease) } diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerNoParamTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerNoParamTest.kt index 600a8d81e731..1c7b0fea1f84 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerNoParamTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerNoParamTest.kt @@ -149,7 +149,7 @@ class ReviewerNoParamTest : RobolectricTest() { val hideCount = reviewer.delayedHideCount - reviewer.answerCard(Consts.BUTTON_ONE) + reviewer.answerCard(Ease.AGAIN) advanceRobolectricLooperWithSleep() assertThat("Hide should be called after answering a card", reviewer.delayedHideCount, greaterThan(hideCount)) @@ -163,7 +163,7 @@ class ReviewerNoParamTest : RobolectricTest() { reviewer.displayCardAnswer() advanceRobolectricLooperWithSleep() - reviewer.answerCard(Consts.BUTTON_ONE) + reviewer.answerCard(Ease.AGAIN) advanceRobolectricLooperWithSleep() val hideCount = reviewer.delayedHideCount diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt index 9fe2d609973c..13dc5bef560a 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt @@ -25,7 +25,6 @@ import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import com.ichi2.anim.ActivityTransitionAnimation -import com.ichi2.anki.AbstractFlashcardViewer.Companion.EASE_3 import com.ichi2.anki.AnkiDroidJsAPITest.Companion.formatApiResult import com.ichi2.anki.AnkiDroidJsAPITest.Companion.getDataFromRequest import com.ichi2.anki.AnkiDroidJsAPITest.Companion.jsApiContract @@ -240,23 +239,23 @@ class ReviewerTest : RobolectricTest() { waitForAsyncTasksToComplete() equalFirstField(cards[0], reviewer.currentCard!!) - reviewer.answerCard(Consts.BUTTON_ONE) + reviewer.answerCard(Ease.AGAIN) waitForAsyncTasksToComplete() equalFirstField(cards[1], reviewer.currentCard!!) - reviewer.answerCard(Consts.BUTTON_ONE) + reviewer.answerCard(Ease.AGAIN) waitForAsyncTasksToComplete() undo(reviewer) waitForAsyncTasksToComplete() equalFirstField(cards[1], reviewer.currentCard!!) - reviewer.answerCard(Consts.BUTTON_THREE) + reviewer.answerCard(Ease.GOOD) waitForAsyncTasksToComplete() equalFirstField(cards[2], reviewer.currentCard!!) time.addM(2) - reviewer.answerCard(Consts.BUTTON_THREE) + reviewer.answerCard(Ease.GOOD) advanceRobolectricLooperWithSleep() equalFirstField( cards[0], @@ -302,7 +301,7 @@ class ReviewerTest : RobolectricTest() { val cardBeforeUndo = sched.card val countsBeforeUndo = sched.counts() - sched.answerCard(cardBeforeUndo!!, Consts.BUTTON_THREE) + sched.answerCard(cardBeforeUndo!!, Ease.GOOD) reviewer.undoAndShowSnackbar() @@ -341,15 +340,15 @@ class ReviewerTest : RobolectricTest() { fun `changing deck refreshes card`() = runReviewer(cards = listOf("One", "Two")) { val nonDefaultDeck = addDeck("Hello") assertThat("first card is shown", this.cardContent, containsString("One")) - flipOrAnswerCard(EASE_3) - // answer good, 'EASE_3' should now be < 10m + flipOrAnswerCard(Ease.GOOD) + // answer good, 'Ease.GOOD' should now be < 10m assertThat("initial time is 10m", this.getCardDataForJsApi().nextTime3, equalTo("<\u206810\u2069m")) - flipOrAnswerCard(EASE_3) + flipOrAnswerCard(Ease.GOOD) assertThat("next card is shown", this.cardContent, containsString("Two")) undoableOp { col.setDeck(listOf(currentCard!!.id), nonDefaultDeck) } - flipOrAnswerCard(EASE_3) + flipOrAnswerCard(Ease.GOOD) assertThat("buttons should be updated", this.getCardDataForJsApi().nextTime3, equalTo("\u20681\u2069d")) assertThat("content should be updated", this.cardContent, containsString("One")) } @@ -407,7 +406,7 @@ class ReviewerTest : RobolectricTest() { private fun answerCardOrdinalAsGood(r: Reviewer, i: Int) { assertCurrentOrdIs(r, i) - r.answerCard(Consts.BUTTON_THREE) + r.answerCard(Ease.GOOD) waitForAsyncTasksToComplete() } diff --git a/AnkiDroid/src/test/java/com/ichi2/libanki/AbstractSchedTest.kt b/AnkiDroid/src/test/java/com/ichi2/libanki/AbstractSchedTest.kt index d819cbb20713..eb2b8952fa6a 100644 --- a/AnkiDroid/src/test/java/com/ichi2/libanki/AbstractSchedTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/libanki/AbstractSchedTest.kt @@ -16,6 +16,7 @@ package com.ichi2.libanki import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.ichi2.anki.Ease import com.ichi2.libanki.sched.Counts import com.ichi2.testutils.JvmTest import org.hamcrest.MatcherAssert.assertThat @@ -46,7 +47,7 @@ class AbstractSchedTest : JvmTest() { val card = sched.card assertThat(sched.newCount(), equalTo(10)) assertThat(sched.counts().new, equalTo(10)) - sched.answerCard(card!!, 3) + sched.answerCard(card!!, Ease.GOOD) sched.card col.undo() assertThat(sched.newCount(), equalTo(10)) @@ -66,7 +67,7 @@ class AbstractSchedTest : JvmTest() { assertNotNull(card) assertEquals(Counts(1, 0, 0), sched.counts()) - sched.answerCard(card, 3) + sched.answerCard(card, Ease.GOOD) card = sched.card assertNotNull(card) @@ -75,7 +76,7 @@ class AbstractSchedTest : JvmTest() { sched.counts() ) - sched.answerCard(card, 3) + sched.answerCard(card, Ease.GOOD) card = sched.card assertNotNull(card) @@ -92,7 +93,7 @@ class AbstractSchedTest : JvmTest() { ) card = sched.card!! - sched.answerCard(card, 3) + sched.answerCard(card, Ease.GOOD) card = sched.card assertNotNull(card) assertEquals( diff --git a/AnkiDroid/src/test/java/com/ichi2/libanki/CardTest.kt b/AnkiDroid/src/test/java/com/ichi2/libanki/CardTest.kt index 7882321a5179..3caff94ad0ad 100644 --- a/AnkiDroid/src/test/java/com/ichi2/libanki/CardTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/libanki/CardTest.kt @@ -17,6 +17,7 @@ package com.ichi2.libanki import android.annotation.SuppressLint import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.ichi2.anki.Ease import com.ichi2.libanki.exception.ConfirmModSchemaException import com.ichi2.testutils.JvmTest import org.hamcrest.Matchers.equalTo @@ -39,7 +40,7 @@ class CardTest : JvmTest() { note.setItem("Back", "2") col.addNote(note) val cid = note.cards()[0].id - col.sched.answerCard(col.sched.card!!, Consts.BUTTON_TWO) + col.sched.answerCard(col.sched.card!!, Ease.HARD) col.removeCardsAndOrphanedNotes(listOf(cid)) assertEquals(0, col.cardCount()) assertEquals(0, col.noteCount()) diff --git a/AnkiDroid/src/test/java/com/ichi2/libanki/FinderTest.kt b/AnkiDroid/src/test/java/com/ichi2/libanki/FinderTest.kt index 8fec85ca0c96..591d5e30be85 100644 --- a/AnkiDroid/src/test/java/com/ichi2/libanki/FinderTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/libanki/FinderTest.kt @@ -16,6 +16,7 @@ package com.ichi2.libanki import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.ichi2.anki.Ease import com.ichi2.libanki.Consts.CARD_TYPE_REV import com.ichi2.libanki.Consts.QUEUE_TYPE_REV import com.ichi2.libanki.Consts.QUEUE_TYPE_SUSPENDED @@ -83,7 +84,7 @@ class FinderTest : JvmTest() { } private fun burySiblings(sched: Scheduler, toManuallyBury: Card): Card { - sched.answerCard(toManuallyBury, Consts.BUTTON_ONE) + sched.answerCard(toManuallyBury, Ease.AGAIN) val siblingBuried = Note(col, toManuallyBury.nid).cards()[1] assertThat(siblingBuried.queue, equalTo(Consts.QUEUE_TYPE_SIBLING_BURIED)) return siblingBuried @@ -327,11 +328,11 @@ class FinderTest : JvmTest() { assertEquals(0, col.findCards("rated:1:1").size) assertEquals(0, col.findCards("rated:1:2").size) c = col.sched.card!! - col.sched.answerCard(c, Consts.BUTTON_TWO) + col.sched.answerCard(c, Ease.HARD) assertEquals(0, col.findCards("rated:1:1").size) assertEquals(1, col.findCards("rated:1:2").size) c = col.sched.card!! - col.sched.answerCard(c, Consts.BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) assertEquals(1, col.findCards("rated:1:1").size) assertEquals(1, col.findCards("rated:1:2").size) assertEquals(2, col.findCards("rated:1").size) diff --git a/AnkiDroid/src/test/java/com/ichi2/libanki/SchedulerTest.kt b/AnkiDroid/src/test/java/com/ichi2/libanki/SchedulerTest.kt index f88313733f4c..59eeeda852e2 100644 --- a/AnkiDroid/src/test/java/com/ichi2/libanki/SchedulerTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/libanki/SchedulerTest.kt @@ -17,11 +17,8 @@ package com.ichi2.libanki import androidx.test.ext.junit.runners.AndroidJUnit4 import anki.scheduler.UnburyDeckRequest +import com.ichi2.anki.Ease import com.ichi2.anki.utils.SECONDS_PER_DAY -import com.ichi2.libanki.Consts.BUTTON_FOUR -import com.ichi2.libanki.Consts.BUTTON_ONE -import com.ichi2.libanki.Consts.BUTTON_THREE -import com.ichi2.libanki.Consts.BUTTON_TWO import com.ichi2.libanki.Consts.CARD_TYPE_LRN import com.ichi2.libanki.Consts.CARD_TYPE_NEW import com.ichi2.libanki.Consts.CARD_TYPE_RELEARNING @@ -70,7 +67,7 @@ open class SchedulerTest : JvmTest() { .put("delays", JSONArray(listOf(0.01, 10))) val c = col.sched.card MatcherAssert.assertThat(c, Matchers.notNullValue()) - col.sched.answerCard(c!!, BUTTON_ONE) + col.sched.answerCard(c!!, Ease.AGAIN) } @Test @@ -96,7 +93,7 @@ open class SchedulerTest : JvmTest() { Assert.assertEquals(CARD_TYPE_NEW, c.type) // if we answer it, it should become a learn card val t = time.intTime().toInt() - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) Assert.assertEquals(QUEUE_TYPE_LRN, c.queue) Assert.assertEquals(CARD_TYPE_LRN, c.type) MatcherAssert.assertThat(c.due, Matchers.greaterThanOrEqualTo(t)) @@ -121,7 +118,7 @@ open class SchedulerTest : JvmTest() { // for (int n = 0; n < 4; n++) { // c = getCard() // assertTrue(qs[n] in c.q()) - // col.getSched().answerCard(c, BUTTON_TWO) + // col.getSched().answerCard(c, Ease.HARD) // } } @@ -168,11 +165,11 @@ open class SchedulerTest : JvmTest() { val conf = col.sched.cardConf(c) conf.getJSONObject("new").put("delays", JSONArray(doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0))) col.decks.save(conf) - col.sched.answerCard(c, BUTTON_TWO) + col.sched.answerCard(c, Ease.HARD) // should handle gracefully conf.getJSONObject("new").put("delays", JSONArray(doubleArrayOf(1.0))) col.decks.save(conf) - col.sched.answerCard(c, BUTTON_TWO) + col.sched.answerCard(c, Ease.HARD) } @Test @@ -199,7 +196,7 @@ open class SchedulerTest : JvmTest() { conf.getJSONObject("new").put("delays", JSONArray(doubleArrayOf(0.5, 3.0, 10.0))) col.decks.save(conf) // fail it - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) // it should have three reps left to graduation Assert.assertEquals(3, (c.left % 1000).toLong()) // it should be due in 30 seconds @@ -207,7 +204,7 @@ open class SchedulerTest : JvmTest() { MatcherAssert.assertThat(t, Matchers.greaterThanOrEqualTo(25L)) MatcherAssert.assertThat(t, Matchers.lessThanOrEqualTo(40L)) // pass it once - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) // it should be due in 3 minutes var dueIn = c.due - time.intTime() MatcherAssert.assertThat(dueIn, Matchers.greaterThanOrEqualTo(178L)) @@ -223,7 +220,7 @@ open class SchedulerTest : JvmTest() { Assert.assertEquals(-180, log.getInt(4).toLong()) Assert.assertEquals(-30, log.getInt(5).toLong()) // pass again - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) // it should be due in 10 minutes dueIn = c.due - time.intTime() MatcherAssert.assertThat(dueIn, Matchers.greaterThanOrEqualTo(599L)) @@ -235,7 +232,7 @@ open class SchedulerTest : JvmTest() { // the next pass should graduate the card Assert.assertEquals(QUEUE_TYPE_LRN, c.queue) Assert.assertEquals(CARD_TYPE_LRN, c.type) - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) Assert.assertEquals(QUEUE_TYPE_REV, c.queue) Assert.assertEquals(CARD_TYPE_REV, c.type) // should be due tomorrow, with an interval of 1 @@ -246,7 +243,7 @@ open class SchedulerTest : JvmTest() { type = CARD_TYPE_NEW queue = QUEUE_TYPE_LRN } - col.sched.answerCard(c, BUTTON_FOUR) + col.sched.answerCard(c, Ease.EASY) Assert.assertEquals(CARD_TYPE_REV, c.type) Assert.assertEquals(QUEUE_TYPE_REV, c.queue) Assert.assertTrue(AnkiAssert.checkRevIvl(c, 4)) @@ -274,13 +271,13 @@ open class SchedulerTest : JvmTest() { // fail the card c = col.sched.card!! - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) Assert.assertEquals(QUEUE_TYPE_LRN, c.queue) Assert.assertEquals(CARD_TYPE_RELEARNING, c.type) Assert.assertEquals(1, c.ivl) // immediately graduate it - col.sched.answerCard(c, BUTTON_FOUR) + col.sched.answerCard(c, Ease.EASY) Assert.assertEquals(CARD_TYPE_REV, c.type) Assert.assertEquals(QUEUE_TYPE_REV, c.queue) Assert.assertEquals(2, c.ivl) @@ -306,7 +303,7 @@ open class SchedulerTest : JvmTest() { // fail the card c = col.sched.card!! - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) Assert.assertEquals(CARD_TYPE_REV, c.type) Assert.assertEquals(QUEUE_TYPE_REV, c.queue) } @@ -327,12 +324,12 @@ open class SchedulerTest : JvmTest() { var c = col.sched.card!! Assert.assertTrue(c.question().endsWith("1")) // pass it so it's due in 10 minutes - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) // get the other card c = col.sched.card!! Assert.assertTrue(c.question().endsWith("2")) // fail it so it's due in 1 minute - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) // we shouldn't get the same card again c = col.sched.card!! Assert.assertFalse(c.question().endsWith("2")) @@ -351,14 +348,14 @@ open class SchedulerTest : JvmTest() { conf.getJSONObject("new").put("delays", JSONArray(doubleArrayOf(1.0, 10.0, 1440.0, 2880.0))) col.decks.save(conf) // pass it - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) // two reps to graduate, 1 more today Assert.assertEquals(3, (c.left % 1000).toLong()) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) c = col.sched.card!! - Assert.assertEquals(SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_THREE)) + Assert.assertEquals(SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.GOOD)) // answering it will place it in queue 3 - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) Assert.assertEquals((col.sched.today + 1), c.due) Assert.assertEquals(QUEUE_TYPE_DAY_LEARN_RELEARN, c.queue) assertNull(col.sched.card) @@ -367,18 +364,18 @@ open class SchedulerTest : JvmTest() { Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) c = col.sched.card!! // nextIvl should work - Assert.assertEquals(SECONDS_PER_DAY * 2, col.sched.nextIvl(c, BUTTON_THREE)) + Assert.assertEquals(SECONDS_PER_DAY * 2, col.sched.nextIvl(c, Ease.GOOD)) // if we fail it, it should be back in the correct queue - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) Assert.assertEquals(QUEUE_TYPE_LRN, c.queue) col.undo() c = col.sched.card!! - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) // simulate the passing of another two days c.update { due -= 2 } // 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) + Assert.assertEquals(SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.GOOD)) + col.sched.answerCard(c, Ease.GOOD) Assert.assertEquals(CARD_TYPE_REV, c.type) Assert.assertEquals(QUEUE_TYPE_REV, c.queue) // if the lapse step is tomorrow, failing it should handle the counts @@ -389,7 +386,7 @@ open class SchedulerTest : JvmTest() { conf.getJSONObject("lapse").put("delays", JSONArray(doubleArrayOf(1440.0))) col.decks.save(conf) c = col.sched.card!! - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) Assert.assertEquals(QUEUE_TYPE_DAY_LEARN_RELEARN, c.queue) Assert.assertEquals(Counts(0, 0, 0), col.sched.counts()) } @@ -421,7 +418,7 @@ open class SchedulerTest : JvmTest() { // ////////////////////////////////////////////////////////////////////////////////////////////////// c = cardcopy.clone() col.updateCard(c, skipUndoEntry = true) - col.sched.answerCard(c, BUTTON_TWO) + col.sched.answerCard(c, Ease.HARD) Assert.assertEquals(QUEUE_TYPE_REV, c.queue) // the new interval should be (100) * 1.2 = 120 Assert.assertTrue(AnkiAssert.checkRevIvl(c, 120)) @@ -435,7 +432,7 @@ open class SchedulerTest : JvmTest() { // ////////////////////////////////////////////////////////////////////////////////////////////////// c = cardcopy.clone() col.updateCard(c, skipUndoEntry = true) - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) // the new interval should be (100 + 8/2) * 2.5 = 260 Assert.assertTrue(AnkiAssert.checkRevIvl(c, 260)) Assert.assertEquals((col.sched.today + c.ivl), c.due) @@ -445,7 +442,7 @@ open class SchedulerTest : JvmTest() { // ////////////////////////////////////////////////////////////////////////////////////////////////// c = cardcopy.clone() col.updateCard(c, skipUndoEntry = true) - col.sched.answerCard(c, BUTTON_FOUR) + col.sched.answerCard(c, Ease.EASY) // the new interval should be (100 + 8) * 2.5 * 1.3 = 351 Assert.assertTrue(AnkiAssert.checkRevIvl(c, 351)) Assert.assertEquals((col.sched.today + c.ivl), c.due) @@ -465,7 +462,7 @@ open class SchedulerTest : JvmTest() { hooked.append(1); hooks.card_did_leech.append(onLeech); - col.getSched().answerCard(c, BUTTON_ONE); + col.getSched().answerCard(c, EaseNumber.AGAIN); assertTrue(hooked); assertEquals(QUEUE_TYPE_SUSPENDED, c.getQueue()); c.load(); @@ -491,14 +488,14 @@ open class SchedulerTest : JvmTest() { // Upstream, there is no space in 2d Assert.assertEquals( "2d", - AnkiAssert.without_unicode_isolation(col.sched.nextIvlStr(c, BUTTON_TWO)) + AnkiAssert.without_unicode_isolation(col.sched.nextIvlStr(c, Ease.HARD)) ) Assert.assertEquals( "3d", AnkiAssert.without_unicode_isolation( col.sched.nextIvlStr( c, - BUTTON_THREE + Ease.GOOD ) ) ) @@ -507,7 +504,7 @@ open class SchedulerTest : JvmTest() { AnkiAssert.without_unicode_isolation( col.sched.nextIvlStr( c, - BUTTON_FOUR + Ease.EASY ) ) ) @@ -518,7 +515,7 @@ open class SchedulerTest : JvmTest() { col.decks.save(conf) Assert.assertEquals( "1d", - AnkiAssert.without_unicode_isolation(col.sched.nextIvlStr(c, BUTTON_TWO)) + AnkiAssert.without_unicode_isolation(col.sched.nextIvlStr(c, Ease.HARD)) ) } @@ -547,7 +544,7 @@ open class SchedulerTest : JvmTest() { col.getSched().reset(); assertEquals(new Counts(0, 2, 0), col.getSched().counts()); c = getCard(); - col.getSched().answerCard(c, BUTTON_THREE); + col.getSched().answerCard(c, EaseNumber.GOOD); // it should be due tomorrow assertEquals(col.getSched().getToday()+ 1, c.getDue()); // revert to before @@ -574,26 +571,26 @@ open class SchedulerTest : JvmTest() { val c = col.sched.card!! // new cards // ////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals(30, col.sched.nextIvl(c, BUTTON_ONE)) - Assert.assertEquals(((30 + 180) / 2).toLong(), col.sched.nextIvl(c, BUTTON_TWO)) - Assert.assertEquals(180, col.sched.nextIvl(c, BUTTON_THREE)) - Assert.assertEquals(4 * SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_FOUR)) - col.sched.answerCard(c, BUTTON_ONE) + Assert.assertEquals(30, col.sched.nextIvl(c, Ease.AGAIN)) + Assert.assertEquals(((30 + 180) / 2).toLong(), col.sched.nextIvl(c, Ease.HARD)) + Assert.assertEquals(180, col.sched.nextIvl(c, Ease.GOOD)) + Assert.assertEquals(4 * SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.EASY)) + col.sched.answerCard(c, Ease.AGAIN) // cards in learning // ////////////////////////////////////////////////////////////////////////////////////////////////// - Assert.assertEquals(30, col.sched.nextIvl(c, BUTTON_ONE)) - Assert.assertEquals(((30 + 180) / 2).toLong(), col.sched.nextIvl(c, BUTTON_TWO)) - Assert.assertEquals(180, col.sched.nextIvl(c, BUTTON_THREE)) - Assert.assertEquals(4 * SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_FOUR)) - col.sched.answerCard(c, BUTTON_THREE) - Assert.assertEquals(30, col.sched.nextIvl(c, BUTTON_ONE)) - Assert.assertEquals(180, col.sched.nextIvl(c, BUTTON_TWO)) - Assert.assertEquals(600, col.sched.nextIvl(c, BUTTON_THREE)) - Assert.assertEquals(4 * SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_FOUR)) - col.sched.answerCard(c, BUTTON_THREE) + Assert.assertEquals(30, col.sched.nextIvl(c, Ease.AGAIN)) + Assert.assertEquals(((30 + 180) / 2).toLong(), col.sched.nextIvl(c, Ease.HARD)) + Assert.assertEquals(180, col.sched.nextIvl(c, Ease.GOOD)) + Assert.assertEquals(4 * SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.EASY)) + col.sched.answerCard(c, Ease.GOOD) + Assert.assertEquals(30, col.sched.nextIvl(c, Ease.AGAIN)) + Assert.assertEquals(180, col.sched.nextIvl(c, Ease.HARD)) + Assert.assertEquals(600, col.sched.nextIvl(c, Ease.GOOD)) + Assert.assertEquals(4 * SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.EASY)) + col.sched.answerCard(c, Ease.GOOD) // normal graduation is tomorrow - Assert.assertEquals(SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_THREE)) - Assert.assertEquals(4 * SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_FOUR)) + Assert.assertEquals(SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.GOOD)) + Assert.assertEquals(4 * SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.EASY)) // lapsed cards // ////////////////////////////////////////////////////////////////////////////////////////////////// c.update { @@ -601,9 +598,9 @@ open class SchedulerTest : JvmTest() { ivl = 100 factor = STARTING_FACTOR } - 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)) + Assert.assertEquals(60, col.sched.nextIvl(c, Ease.AGAIN)) + Assert.assertEquals(100 * SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.GOOD)) + Assert.assertEquals(101 * SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.EASY)) // review cards // ////////////////////////////////////////////////////////////////////////////////////////////////// c.update { @@ -613,22 +610,22 @@ open class SchedulerTest : JvmTest() { factor = STARTING_FACTOR } // failing it should put it at 60s - Assert.assertEquals(60, col.sched.nextIvl(c, BUTTON_ONE)) + Assert.assertEquals(60, col.sched.nextIvl(c, Ease.AGAIN)) // or 1 day if relearn is false conf.getJSONObject("lapse").put("delays", JSONArray(doubleArrayOf())) col.decks.save(conf) - Assert.assertEquals(SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_ONE)) + Assert.assertEquals(SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.AGAIN)) // (* 100 1.2 SECONDS_PER_DAY)10368000.0 - Assert.assertEquals(10368000, col.sched.nextIvl(c, BUTTON_TWO)) + Assert.assertEquals(10368000, col.sched.nextIvl(c, Ease.HARD)) // (* 100 2.5 SECONDS_PER_DAY)21600000.0 - Assert.assertEquals(21600000, col.sched.nextIvl(c, BUTTON_THREE)) + Assert.assertEquals(21600000, col.sched.nextIvl(c, Ease.GOOD)) // (* 100 2.5 1.3 SECONDS_PER_DAY)28080000.0 - Assert.assertEquals(28080000, col.sched.nextIvl(c, BUTTON_FOUR)) + Assert.assertEquals(28080000, col.sched.nextIvl(c, Ease.EASY)) MatcherAssert.assertThat( AnkiAssert.without_unicode_isolation( col.sched.nextIvlStr( c, - BUTTON_FOUR + Ease.EASY ) ), Matchers.equalTo("10.8mo") @@ -690,7 +687,7 @@ open class SchedulerTest : JvmTest() { queue = QUEUE_TYPE_REV } c = col.sched.card!! - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) MatcherAssert.assertThat( c.due, Matchers.greaterThanOrEqualTo(time.intTime().toInt()) @@ -749,23 +746,23 @@ open class SchedulerTest : JvmTest() { Assert.assertEquals(Counts(0, 0, 1), col.sched.counts()) // grab it and check estimates c = col.sched.card!! - Assert.assertEquals(600, col.sched.nextIvl(c, BUTTON_ONE)) + Assert.assertEquals(600, col.sched.nextIvl(c, Ease.AGAIN)) Assert.assertEquals( (75 * 1.2).roundToInt() * SECONDS_PER_DAY, - col.sched.nextIvl(c, BUTTON_TWO) + col.sched.nextIvl(c, Ease.HARD) ) val toLong = fun(v: Double) = v.roundToLong() * SECONDS_PER_DAY MatcherAssert.assertThat( - col.sched.nextIvl(c, BUTTON_THREE), + col.sched.nextIvl(c, Ease.GOOD), equalTo(toLong(75 * 2.5)) ) MatcherAssert.assertThat( - col.sched.nextIvl(c, BUTTON_FOUR), + col.sched.nextIvl(c, Ease.EASY), equalTo(toLong(75 * 2.5 * 1.15)) ) // answer 'good' - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) AnkiAssert.checkRevIvl(c, 90) Assert.assertEquals((col.sched.today + c.ivl), c.due) Assert.assertEquals(0, c.oDue) @@ -784,9 +781,9 @@ open class SchedulerTest : JvmTest() { } col.sched.rebuildDyn(did) c = col.sched.card!! - Assert.assertEquals(60 * SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_TWO)) - Assert.assertEquals(100 * SECONDS_PER_DAY, col.sched.nextIvl(c, BUTTON_THREE)) - Assert.assertEquals(toLong(114.5), col.sched.nextIvl(c, BUTTON_FOUR)) + Assert.assertEquals(60 * SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.HARD)) + Assert.assertEquals(100 * SECONDS_PER_DAY, col.sched.nextIvl(c, Ease.GOOD)) + Assert.assertEquals(toLong(114.5), col.sched.nextIvl(c, Ease.EASY)) } @Test @@ -801,11 +798,11 @@ open class SchedulerTest : JvmTest() { val conf = col.sched.cardConf(c) conf.getJSONObject("new").put("delays", JSONArray(doubleArrayOf(1.0, 10.0, 61.0))) col.decks.save(conf) - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) Assert.assertEquals(CARD_TYPE_LRN, c.queue) Assert.assertEquals(QUEUE_TYPE_LRN, c.type) Assert.assertEquals(3, c.left % 1000) - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) Assert.assertEquals(CARD_TYPE_LRN, c.queue) Assert.assertEquals(QUEUE_TYPE_LRN, c.type) @@ -820,7 +817,7 @@ open class SchedulerTest : JvmTest() { Assert.assertEquals(2, c.left % 1000) // should be able to advance learning steps - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) // should be due at least an hour in the future MatcherAssert.assertThat( c.due - time.intTime(), @@ -857,11 +854,11 @@ open class SchedulerTest : JvmTest() { col.sched.rebuildDyn(did) // grab the first card val c: Card = col.sched.card!! - Assert.assertEquals(60, col.sched.nextIvl(c, BUTTON_ONE)) - Assert.assertEquals(600, col.sched.nextIvl(c, BUTTON_TWO)) + Assert.assertEquals(60, col.sched.nextIvl(c, Ease.AGAIN)) + Assert.assertEquals(600, col.sched.nextIvl(c, Ease.HARD)) // failing it will push its due time back val due = c.due - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) Assert.assertNotEquals(c.due, due) // the other card should come next @@ -869,7 +866,7 @@ open class SchedulerTest : JvmTest() { Assert.assertNotEquals(c2.id, c.id) // passing it will remove it - col.sched.answerCard(c2, BUTTON_FOUR) + col.sched.answerCard(c2, Ease.EASY) Assert.assertEquals(QUEUE_TYPE_NEW, c2.queue) Assert.assertEquals(0, c2.reps) Assert.assertEquals(CARD_TYPE_NEW, c2.type) @@ -908,19 +905,19 @@ open class SchedulerTest : JvmTest() { var c = sched.card sched.answerCard( c!!, - 3 + Ease.GOOD ) // not upstream. But we are not expecting multiple getCard without review Assert.assertEquals(0, c.ord) c = sched.card sched.answerCard( c!!, - 3 + Ease.GOOD ) // not upstream. But we are not expecting multiple getCard without review Assert.assertEquals(1, c.ord) c = sched.card sched.answerCard( c!!, - 3 + Ease.GOOD ) // not upstream. But we are not expecting multiple getCard without review Assert.assertEquals(2, c.ord) } @@ -942,7 +939,7 @@ open class SchedulerTest : JvmTest() { Assert.assertEquals(Counts(2, 0, 0), col.sched.counts()) Assert.assertEquals(Counts.Queue.NEW, col.sched.countIdx()) // answer to move to learn queue - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) Assert.assertEquals(Counts(1, 1, 0), col.sched.counts()) // fetching next will not decrement the count Assert.assertEquals(Counts(1, 1, 0), col.sched.counts()) @@ -957,33 +954,33 @@ open class SchedulerTest : JvmTest() { col.addNote(note) // lrnReps should be accurate on pass/fail Assert.assertEquals(Counts(1, 0, 0), col.sched.counts()) - col.sched.answerCard(col.sched.card!!, BUTTON_ONE) + col.sched.answerCard(col.sched.card!!, Ease.AGAIN) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) - col.sched.answerCard(col.sched.card!!, BUTTON_ONE) + col.sched.answerCard(col.sched.card!!, Ease.AGAIN) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) - col.sched.answerCard(col.sched.card!!, BUTTON_THREE) + col.sched.answerCard(col.sched.card!!, Ease.GOOD) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) - col.sched.answerCard(col.sched.card!!, BUTTON_ONE) + col.sched.answerCard(col.sched.card!!, Ease.AGAIN) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) - col.sched.answerCard(col.sched.card!!, BUTTON_THREE) + col.sched.answerCard(col.sched.card!!, Ease.GOOD) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) - col.sched.answerCard(col.sched.card!!, BUTTON_THREE) + col.sched.answerCard(col.sched.card!!, Ease.GOOD) Assert.assertEquals(Counts(0, 0, 0), col.sched.counts()) note = col.newNote() note.setItem("Front", "two") col.addNote(note) // initial pass should be correct too - col.sched.answerCard(col.sched.card!!, BUTTON_THREE) + col.sched.answerCard(col.sched.card!!, Ease.GOOD) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) - col.sched.answerCard(col.sched.card!!, BUTTON_ONE) + col.sched.answerCard(col.sched.card!!, Ease.AGAIN) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) - col.sched.answerCard(col.sched.card!!, BUTTON_FOUR) + col.sched.answerCard(col.sched.card!!, Ease.EASY) Assert.assertEquals(Counts(0, 0, 0), col.sched.counts()) // immediate graduate should work note = col.newNote() note.setItem("Front", "three") col.addNote(note) - col.sched.answerCard(col.sched.card!!, BUTTON_FOUR) + col.sched.answerCard(col.sched.card!!, Ease.EASY) Assert.assertEquals(Counts(0, 0, 0), col.sched.counts()) // and failing a review should too note = col.newNote() @@ -995,7 +992,7 @@ open class SchedulerTest : JvmTest() { due = col.sched.today } Assert.assertEquals(Counts(0, 0, 1), col.sched.counts()) - col.sched.answerCard(col.sched.card!!, BUTTON_ONE) + col.sched.answerCard(col.sched.card!!, Ease.AGAIN) Assert.assertEquals(Counts(0, 1, 0), col.sched.counts()) } @@ -1015,7 +1012,7 @@ open class SchedulerTest : JvmTest() { } // fail the first one var c = col.sched.card!! - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) // the next card should be another review val c2 = col.sched.card!! Assert.assertEquals(QUEUE_TYPE_REV, c2.queue) @@ -1034,9 +1031,9 @@ open class SchedulerTest : JvmTest() { col.addNote(note) // test collapsing var c = col.sched.card - col.sched.answerCard(c!!, BUTTON_ONE) + col.sched.answerCard(c!!, Ease.AGAIN) c = col.sched.card - col.sched.answerCard(c!!, BUTTON_FOUR) + col.sched.answerCard(c!!, Ease.EASY) assertNull(col.sched.card) } @@ -1124,7 +1121,7 @@ open class SchedulerTest : JvmTest() { for (i in arrayOf("one", "three", "two")) { val c = col.sched.card!! Assert.assertEquals(i, c.note().getItem("Front")) - col.sched.answerCard(c, BUTTON_THREE) + col.sched.answerCard(c, Ease.GOOD) } } @@ -1226,9 +1223,9 @@ open class SchedulerTest : JvmTest() { ivl = 100 startTimer() } - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) col.sched.cardConf(c).getJSONObject("lapse").put("delays", JSONArray(doubleArrayOf())) - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) } @Test @@ -1252,9 +1249,9 @@ open class SchedulerTest : JvmTest() { conf.getJSONObject("lapse").put("mult", 0.5) col.decks.save(conf) c = col.sched.card!! - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) Assert.assertEquals(50, c.ivl) - col.sched.answerCard(c, BUTTON_ONE) + col.sched.answerCard(c, Ease.AGAIN) Assert.assertEquals(25, c.ivl) } @@ -1294,7 +1291,7 @@ open class SchedulerTest : JvmTest() { note.setItem("Back", "two") col.addNote(note) val c = col.sched.card!! - col.sched.answerCard(c, BUTTON_TWO) + col.sched.answerCard(c, Ease.HARD) // should be due in ~ 5.5 mins val expected = time.intTime() + (5.5 * 60).toInt() val due = c.due @@ -1322,12 +1319,12 @@ open class SchedulerTest : JvmTest() { for (i in 0..2) { card = sched.card assertNotNull(card) - sched.answerCard(card, BUTTON_ONE) + sched.answerCard(card, Ease.AGAIN) } Assert.assertEquals(1, sched.lrnCount().toLong()) card = sched.card Assert.assertEquals(1, sched.counts().lrn.toLong()) - sched.answerCard(card!!, BUTTON_ONE) + sched.answerCard(card!!, Ease.AGAIN) AnkiAssert.assertDoesNotThrow { col.undo() } } } diff --git a/api/src/main/java/com/ichi2/anki/api/Ease.kt b/api/src/main/java/com/ichi2/anki/api/Ease.kt index 33a84814da46..74173a6fbcbd 100644 --- a/api/src/main/java/com/ichi2/anki/api/Ease.kt +++ b/api/src/main/java/com/ichi2/anki/api/Ease.kt @@ -16,6 +16,12 @@ package com.ichi2.anki.api +/* + * [value] should be kept in sync with the [com.ichi2.anki.Ease] enum. + * + * param value The so called value of the button. For the sake of consistency with upstream and our API + * the buttons are numbered from 1 to 4. + */ public enum class Ease(public val value: Int) { EASE_1(1), EASE_2(2),