-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[GSoC'24] Fix: cloze number incorrect on undo #16779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You should add a test as well |
ShridharGoel
approved these changes
Jul 25, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
david-allison
requested changes
Jul 27, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel the tests are readable.
Subject: [PATCH] aa
---
Index: AnkiDroid/src/test/java/com/ichi2/anki/instanteditor/InstantEditorViewModelTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/instanteditor/InstantEditorViewModelTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/instanteditor/InstantEditorViewModelTest.kt
--- a/AnkiDroid/src/test/java/com/ichi2/anki/instanteditor/InstantEditorViewModelTest.kt (revision 3ae8b861623eb072b52b0575a12329ed00460db8)
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/instanteditor/InstantEditorViewModelTest.kt (date 1722110794241)
@@ -58,34 +58,32 @@
@Test
fun `test cloze number reset to 1`() = runViewModelTest {
val sentenceArray = mutableListOf("Hello", "world")
- sentenceArray[0] = buildClozeText(sentenceArray[0])
- sentenceArray[1] = buildClozeText(sentenceArray[1])
+
+ toggleAllClozeDeletions(sentenceArray)
- assertEquals(intClozeList.size, 2)
+ assertEquals("all clozes are detected", clozeDeletionCount, 2)
- buildClozeText(sentenceArray[0])
- buildClozeText(sentenceArray[1])
+ toggleAllClozeDeletions(sentenceArray)
- assertEquals(intClozeList.size, 0)
- assertEquals(currentClozeNumber, 1)
+ assertEquals("all cloze deletions are removed", clozeDeletionCount, 0)
+ assertEquals("cloze number is reset if there are no clozes", currentClozeNumber, 1)
}
@Test
fun `test cloze number is reset to max value from cloze list`() = runViewModelTest {
val sentenceArray = mutableListOf("Hello", "world", "this", "is", "test", "sentence")
- sentenceArray[0] = buildClozeText(sentenceArray[0])
- sentenceArray[1] = buildClozeText(sentenceArray[1])
- sentenceArray[2] = buildClozeText(sentenceArray[2])
+ // cloze on the first 3 words
+ toggleClozeDeletions(sentenceArray, 0, 1, 2)
- buildClozeText(sentenceArray[0])
- buildClozeText(sentenceArray[1])
+ // disable cloze on the first 2, leaving "this" as {{c3::
+ toggleClozeDeletions(sentenceArray, 0, 1)
- assertEquals(currentClozeNumber, 4)
+ assertEquals("cloze number is 'Current Cloze Number + 1'", currentClozeNumber, 4)
- // removing all clozes
- buildClozeText(sentenceArray[2])
- assertEquals(currentClozeNumber, 1)
+ // remove the remaining cloze all clozes
+ toggleClozeDeletion(sentenceArray, 2)
+ assertEquals("cloze number is reset if all clozes are removed", currentClozeNumber, 1)
}
@Test
@@ -234,3 +232,25 @@
}
}
}
+
+context (InstantEditorViewModel)
+private fun toggleAllClozeDeletions(words: MutableList<String>) {
+ for (index in words.indices) {
+ words[index] = buildClozeText(words[index])
+ }
+}
+
+
+context (InstantEditorViewModel)
+@Suppress("SameParameterValue")
+private fun toggleClozeDeletions(words: MutableList<String>, vararg indices: Int) {
+ for (index in indices) {
+ words[index] = buildClozeText(words[index])
+ }
+}
+
+context (InstantEditorViewModel)
+@Suppress("SameParameterValue")
+private fun toggleClozeDeletion(words: MutableList<String>, index: Int) {
+ words[index] = buildClozeText(words[index])
+}
\ No newline at end of file
Index: AnkiDroid/src/main/java/com/ichi2/anki/instantnoteeditor/InstantEditorViewModel.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/instantnoteeditor/InstantEditorViewModel.kt b/AnkiDroid/src/main/java/com/ichi2/anki/instantnoteeditor/InstantEditorViewModel.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/instantnoteeditor/InstantEditorViewModel.kt (revision 3ae8b861623eb072b52b0575a12329ed00460db8)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/instantnoteeditor/InstantEditorViewModel.kt (date 1722109604855)
@@ -60,7 +60,11 @@
get() = _currentClozeNumber.value
// List to store the cloze integers
- val intClozeList = mutableListOf<Int>()
+ private val intClozeList = mutableListOf<Int>()
+
+ /** The number of words which are marked as cloze deletions */
+ @VisibleForTesting
+ val clozeDeletionCount get() = intClozeList.size
private val _currentClozeMode = MutableStateFlow(InstantNoteEditorActivity.ClozeMode.INCREMENT)
AnkiDroid/src/main/java/com/ichi2/anki/instantnoteeditor/InstantEditorViewModel.kt
Outdated
Show resolved
Hide resolved
david-allison
approved these changes
Jul 28, 2024
* refactor: update the viewmodel tests
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
GSoC
Pull requests authored by a Google Summer of Code participant [Candidate/Selected], for GSoC mentors
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose / Description
Cloze number is reset to 1 or the current cloze number is max of the close number list
Fixes
Approach
How does this change address the problem?
How Has This Been Tested?
Oneplus nord ce
Checklist
Please, go through these checks before submitting the PR.