Files
OSGKeyboard/OSGKeyboardTests/ProgressiveDictationTranscriptAccumulatorTests.swift
Rocky 498f407585 feat(account): add managed credits and cloud gateway
Introduce optional Apple account-backed credits with scoped gateway access while preserving local and BYOK paths. Refresh assistant behavior, tests, privacy disclosures, docs, and the website for the 2.0 experience.
2026-08-20 11:43:21 +08:00

82 lines
2.9 KiB
Swift

// ProgressiveDictationTranscriptAccumulatorTests.swift
// OSGKeyboardTests
import CoreMedia
@testable import OSGKeyboardShared
import XCTest
final class ProgressiveDictationTranscriptAccumulatorTests: XCTestCase {
private func range(start: Double, duration: Double = 30) -> CMTimeRange {
CMTimeRange(
start: CMTime(seconds: start, preferredTimescale: 600),
duration: CMTime(seconds: duration, preferredTimescale: 600)
)
}
func testCumulativePartialsWithinSameRangeUpdateSegment() {
var acc = ProgressiveDictationTranscriptAccumulator()
let r0 = range(start: 0)
XCTAssertEqual(acc.ingest(range: r0, text: "今天天气"), "今天天气")
XCTAssertEqual(acc.ingest(range: r0, text: "今天天气很好"), "今天天气很好")
XCTAssertEqual(acc.finalize(), "今天天气很好")
}
func testNewRangeAppendsInsteadOfReplacingEarlierSpeech() {
var acc = ProgressiveDictationTranscriptAccumulator()
let r0 = range(start: 0)
let r30 = range(start: 30)
_ = acc.ingest(range: r0, text: "前三十秒的内容")
_ = acc.ingest(range: r30, text: "后二十秒的内容")
XCTAssertEqual(acc.finalize(), "前三十秒的内容后二十秒的内容")
}
func testDuplicateEmissionIsSuppressed() {
var acc = ProgressiveDictationTranscriptAccumulator()
let r0 = range(start: 0)
XCTAssertNotNil(acc.ingest(range: r0, text: "hello"))
XCTAssertNil(acc.ingest(range: r0, text: "hello"))
}
func testPunctuationRevisionWithRangeDriftReplacesPriorSegment() {
var acc = ProgressiveDictationTranscriptAccumulator()
_ = acc.ingest(
range: range(start: 0.0, duration: 2.5),
text: "先这样用着就算目前的可用性"
)
_ = acc.ingest(
range: range(start: 0.25, duration: 2.5),
text: "先这样用着,就算目前的可用性已经"
)
_ = acc.ingest(
range: range(start: 2.8, duration: 2.5),
text: "提升很多了"
)
XCTAssertEqual(acc.finalize(), "先这样用着,就算目前的可用性已经提升很多了")
}
func testComposerDropsOverlappingSuffixAndPrefix() {
let composed = DictationTextComposer.compose(
anchor: "先这样用着,就算目前的可用性已经",
live: "可用性已经提升很多了"
)
XCTAssertEqual(composed, "先这样用着,就算目前的可用性已经提升很多了")
}
func testComposerMapsNormalizedOverlapThroughRawPunctuation() {
let composed = DictationTextComposer.compose(
anchor: "先这样用着,就算目前的可用性已经",
live: "可用性,已经提升很多了"
)
XCTAssertEqual(composed, "先这样用着,就算目前的可用性已经提升很多了")
}
}