Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class PostureDetector(private val context: Context, private val scope: Coroutine
}

fun onConfigurationChanged() {
_postureInfo.value = getCurrentPostureInfo(context)
_postureInfo.value = getCurrentPostureInfo()
}

fun stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,38 @@ class PostureDetectorTest {
}

@Test
fun `onConfigurationChanged uses service context`() {
fun `onConfigurationChanged prefers window context over service context (GH-742)`() {
val detector = PostureDetector(portraitContext(), scope)
detector.attachToWindow(landscapeContext())

detector.onConfigurationChanged()

assertEquals(
Configuration.ORIENTATION_LANDSCAPE,
detector.postureInfo.value.orientation
)
}

@Test
fun `onConfigurationChanged falls back to service context when no window attached`() {
val detector = PostureDetector(portraitContext(), scope)

detector.onConfigurationChanged()

assertEquals(
Configuration.ORIENTATION_PORTRAIT,
detector.postureInfo.value.orientation
)
}

@Test
fun `onConfigurationChanged falls back to service context after stop clears window context`() {
val detector = PostureDetector(portraitContext(), scope)
detector.attachToWindow(landscapeContext())
detector.stop()

detector.onConfigurationChanged()

assertEquals(
Configuration.ORIENTATION_PORTRAIT,
detector.postureInfo.value.orientation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ import org.robolectric.RobolectricTestRunner

/**
* Tests that the Japanese spatial-score bypass (`if (languageCode == "ja") 0.0`)
* is load-bearing: without it, a low-frequency candidate adjacent to the input key
* would outscore a high-frequency candidate due to SPATIAL_PROXIMITY_WEIGHT (0.35)
* dwarfing SYMSPELL_FREQUENCY_WEIGHT (0.05).
* is load-bearing
*
* Setup:
* dictionary: あい=100, あう=10_000_000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class SpellCheckManagerSpatialTest {
}

@Test
fun `learned word with poor spatial score ranks below symspell ed1 with good spatial score`() = runTest {
fun `learned word with poor spatial score ranks below dict ed1 with good spatial score`() = runTest {
keyPositionsFlow.emit(qwertyPositions)

whenever(
Expand All @@ -182,14 +182,14 @@ class SpellCheckManagerSpatialTest {
val suggestions = spellCheckManager.getSpellingSuggestionsWithConfidence("foz")

val learnedSuggestion = suggestions.find { it.source == "learned" }
val symspellSuggestion = suggestions.find { it.source == "dictionary" && it.word == "fox" }
val dictSuggestion = suggestions.find { it.source == "dictionary" && it.word == "fox" }

assertNotNull("learned word should appear in suggestions", learnedSuggestion)
assertNotNull("symspell ed1 match 'fox' should appear in suggestions for input 'foz'", symspellSuggestion)
assertNotNull("dict ed1 match 'fox' should appear in suggestions for input 'foz'", dictSuggestion)
assertTrue(
"symspell ed1 (good spatial) should beat learned word (poor spatial, freq=1); " +
"symspell=${symspellSuggestion!!.confidence}, learned=${learnedSuggestion!!.confidence}",
symspellSuggestion.confidence > learnedSuggestion.confidence
"dict ed1 (good spatial) should beat learned word (poor spatial, freq=1); " +
"dict=${dictSuggestion!!.confidence}, learned=${learnedSuggestion!!.confidence}",
dictSuggestion.confidence > learnedSuggestion.confidence
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ class SpellCheckManagerTest {
}

@Test
fun `corrections from symspell have varied confidence based on frequency`() = runTest {
fun `corrections from dict have varied confidence based on frequency`() = runTest {
whenever(wordLearningEngine.getSimilarLearnedWordsWithFrequency(any(), any(), any()))
.thenReturn(emptyList())

Expand Down Expand Up @@ -811,16 +811,16 @@ class SpellCheckManagerTest {
}

@Test
fun `symspell contraction gets guaranteed confidence`() = runTest {
fun `dict contraction gets guaranteed confidence`() = runTest {
whenever(wordLearningEngine.getSimilarLearnedWordsWithFrequency(any(), any(), any()))
.thenReturn(emptyList())

val suggestions = spellCheckManager.getSpellingSuggestionsWithConfidence("havent")

val contractionSuggestion = suggestions.find { it.word == "haven't" }
assertNotNull("Should find contraction haven't from SymSpell", contractionSuggestion)
assertNotNull("Should find contraction haven't from dict", contractionSuggestion)
assertEquals(
"SymSpell contraction should have guaranteed confidence",
"dict contraction should have guaranteed confidence",
0.995,
contractionSuggestion!!.confidence,
0.001
Expand Down