test: add unit tests for CardUtils#20385
test: add unit tests for CardUtils#20385Ayush-Patel-56 wants to merge 1 commit intoankidroid:mainfrom
Conversation
david-allison
left a comment
There was a problem hiding this comment.
Cheers!
In future: It's a huge timesaver to see if code is unused. We've still got... 15 years of cruft (many of which my own) to deal with.
Fun fact:
This code came from 2018, when multiselect in the Card Browser was added: d98f676. It was in Java at the time.
| @Test | ||
| fun getNotes_emptyCollection_returnsEmptySet() { | ||
| val cards = emptyList<com.ichi2.anki.libanki.Card>() | ||
| val notes = CardUtils.getNotes(col, cards) |
There was a problem hiding this comment.
getNotes is unused, and should be deleted
There was a problem hiding this comment.
Done - removed the trivial empty collection test.
There was a problem hiding this comment.
The method in CardUtils should be deleted, not just the test.
There was a problem hiding this comment.
Done, removed getNotes() from CardUtils.kt as well
985ae14 to
37cca2e
Compare
37cca2e to
e285238
Compare
david-allison
left a comment
There was a problem hiding this comment.
Are you sure you're not using an LLM for this? The comments seem very redundant, as they feel t be duplicated in the assertion message
| val note = addBasicNote("Front", "Back") | ||
| val card = note.firstCard() | ||
|
|
||
| // Verify oDid is 0 for regular decks |
There was a problem hiding this comment.
| // Verify oDid is 0 for regular decks |
| col.sched.rebuildFilteredDeck(filteredDid) | ||
| card.load() | ||
|
|
||
| // In a filtered deck, oDid should be set |
There was a problem hiding this comment.
| // In a filtered deck, oDid should be set |
| val note = addBasicNote("Front", "Back") | ||
| val card = note.firstCard() | ||
|
|
||
| // Move card to a filtered deck |
There was a problem hiding this comment.
| // Move card to a filtered deck |
| val note = addBasicNote("Front", "Back") | ||
| val card = note.firstCard() | ||
|
|
||
| // Regular deck has oDid = 0 |
There was a problem hiding this comment.
| // Regular deck has oDid = 0 |
Purpose / Description
Added unit tests for CardUtils. This class had no test coverage before.
Fixes
@NeedsTest) #13283Approach
Created CardUtilsTest.kt with 7 test cases covering both public methods:
getNotes():getDeckIdForCard():How Has This Been Tested?
Ran unit tests locally:
./gradlew :AnkiDroid:testPlayDebugUnitTest --tests "com.ichi2.anki.CardUtilsTest"
All 7 tests passed with 0 failures.
Learning (optional, can help others)
addBasicNote()andaddDynamicDeck()oDidfield to store the original deck ID when cards are moved to cram decksChecklist
Please, go through these checks before submitting the PR.