diff --git a/app/src/main/java/com/urik/keyboard/service/PostureDetector.kt b/app/src/main/java/com/urik/keyboard/service/PostureDetector.kt index e85d014..8354691 100644 --- a/app/src/main/java/com/urik/keyboard/service/PostureDetector.kt +++ b/app/src/main/java/com/urik/keyboard/service/PostureDetector.kt @@ -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() { diff --git a/app/src/test/java/com/urik/keyboard/service/PostureDetectorTest.kt b/app/src/test/java/com/urik/keyboard/service/PostureDetectorTest.kt index 58ffbdb..fd3ec29 100644 --- a/app/src/test/java/com/urik/keyboard/service/PostureDetectorTest.kt +++ b/app/src/test/java/com/urik/keyboard/service/PostureDetectorTest.kt @@ -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 diff --git a/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerJapaneseSpatialTest.kt b/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerJapaneseSpatialTest.kt index 6136590..7a6464e 100644 --- a/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerJapaneseSpatialTest.kt +++ b/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerJapaneseSpatialTest.kt @@ -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 diff --git a/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerSpatialTest.kt b/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerSpatialTest.kt index 6289b2d..ed99511 100644 --- a/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerSpatialTest.kt +++ b/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerSpatialTest.kt @@ -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( @@ -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 ) } diff --git a/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerTest.kt b/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerTest.kt index 8d172a4..5326f4d 100644 --- a/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerTest.kt +++ b/app/src/test/java/com/urik/keyboard/service/SpellCheckManagerTest.kt @@ -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()) @@ -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