mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-08-22 23:15:25 +00:00
Avoid @MainActor class
This commit is contained in:
@ -10,7 +10,7 @@ import Foundation
|
||||
import KanaKanjiConverterModuleWithDefaultDictionary
|
||||
import XCTest
|
||||
|
||||
@MainActor final class ConverterTests: XCTestCase {
|
||||
final class ConverterTests: XCTestCase {
|
||||
func sequentialInput(_ composingText: inout ComposingText, sequence: String, inputStyle: KanaKanjiConverterModule.InputStyle) {
|
||||
for char in sequence {
|
||||
composingText.insertAtCursorPosition(String(char), inputStyle: inputStyle)
|
||||
@ -37,7 +37,8 @@ import XCTest
|
||||
)
|
||||
}
|
||||
|
||||
func testFullConversion() throws {
|
||||
func testFullConversion() async throws {
|
||||
await MainActor.run {
|
||||
do {
|
||||
let converter = KanaKanjiConverter()
|
||||
var c = ComposingText()
|
||||
@ -51,13 +52,14 @@ import XCTest
|
||||
c.insertAtCursorPosition("ようしょうきからてにすすいえいやきゅうしょうりんじけんぽうなどさまざまなすぽーつをけいけんしながらそだちしょうがっこうじだいはろさんぜるすきんこうにたいざいしておりごるふやてにすをならっていた", inputStyle: .direct)
|
||||
let results = converter.requestCandidates(c, options: requestOptions())
|
||||
XCTAssertEqual(results.mainResults.first?.text, "幼少期からテニス水泳野球少林寺拳法など様々なスポーツを経験しながら育ち小学校時代はロサンゼルス近郊に滞在しておりゴルフやテニスを習っていた")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1文字ずつ変換する
|
||||
// memo: 内部実装としては別のモジュールが呼ばれるのだが、それをテストする方法があまりないかもしれない
|
||||
func testGradualConversion() throws {
|
||||
func testGradualConversion() async throws {
|
||||
await MainActor.run {
|
||||
let converter = KanaKanjiConverter()
|
||||
var c = ComposingText()
|
||||
let text = "ようしょうきからてにすすいえいやきゅうしょうりんじけんぽうなどさまざまなすぽーつをけいけんしながらそだちしょうがっこうじだいはろさんぜるすきんこうにたいざいしておりごるふやてにすをならっていた"
|
||||
@ -69,10 +71,12 @@ import XCTest
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1文字ずつ変換する
|
||||
// memo: 内部実装としては別のモジュールが呼ばれるのだが、それをテストする方法があまりないかもしれない
|
||||
func testRoman2KanaGradualConversion() throws {
|
||||
func testRoman2KanaGradualConversion() async throws {
|
||||
await MainActor.run {
|
||||
let converter = KanaKanjiConverter()
|
||||
var c = ComposingText()
|
||||
let text = "youshoukikaratenisusuieiyakyuushourinjikenpounadosamazamanasupoーtuwokeikennsinagarasodatishougakkouzidaiharosanzerusukinkounitaizaisiteorigoruhuyatenisuwonaratteita"
|
||||
@ -89,10 +93,12 @@ import XCTest
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2,3文字ずつ変換する
|
||||
// memo: 内部実装としては別のモジュールが呼ばれるのだが、それをテストする方法があまりないかもしれない
|
||||
func testSemiGradualConversion() throws {
|
||||
func testSemiGradualConversion() async throws {
|
||||
await MainActor.run {
|
||||
let converter = KanaKanjiConverter()
|
||||
var c = ComposingText()
|
||||
let text = "ようしょうきからてにすすいえいやきゅうしょうりんじけんぽうなどさまざまなすぽーつをけいけんしながらそだちしょうがっこうじだいはろさんぜるすきんこうにたいざいしておりごるふやてにすをならっていた"
|
||||
@ -111,10 +117,12 @@ import XCTest
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1文字ずつ入力するが、時折削除を行う
|
||||
// memo: 内部実装としてはdeleted_last_nのテストを意図している
|
||||
func testGradualConversionWithDelete() throws {
|
||||
func testGradualConversionWithDelete() async throws {
|
||||
await MainActor.run {
|
||||
let converter = KanaKanjiConverter()
|
||||
var c = ComposingText()
|
||||
let text = Array("ようしょうきからてにすすいえいやきゅうしょうりんじけんぽうなどさまざまなすぽーつをけいけんしながらそだちしょうがっこうじだいはろさんぜるすきんこうにたいざいしておりごるふやてにすをならっていた")
|
||||
@ -135,9 +143,11 @@ import XCTest
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 必ず正解すべきテストケース
|
||||
func testMustCases() throws {
|
||||
func testMustCases() async throws {
|
||||
await MainActor.run {
|
||||
// ダイレクト入力
|
||||
do {
|
||||
let cases: [(input: String, expect: String)] = [
|
||||
@ -204,10 +214,12 @@ import XCTest
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 変換結果が比較的一意なテストケースを無数に持ち、一定の割合を正解することを要求する
|
||||
// 辞書を更新した結果性能が悪化したら気付ける
|
||||
func testAccuracy() throws {
|
||||
func testAccuracy() async throws {
|
||||
await MainActor.run {
|
||||
let cases: [(input: String, expect: [String])] = [
|
||||
("3がつ8にち", ["3月8日"]),
|
||||
("いっていのわりあい", ["一定の割合"]),
|
||||
@ -280,11 +292,13 @@ import XCTest
|
||||
print("\(#function) Result: accuracy \(accuracy), score \(score), count \(cases.count)")
|
||||
XCTAssertGreaterThan(accuracy, 0.7) // 0.7 < acuracy
|
||||
}
|
||||
}
|
||||
|
||||
// 変換結果が比較的一意なテストケースを無数に持ち、一定の割合を正解することを要求する
|
||||
// 辞書を更新した結果性能が悪化したら気付ける
|
||||
// 口語表現を中心にテストする
|
||||
func testVerbalAccuracy() throws {
|
||||
func testVerbalAccuracy() async throws {
|
||||
await MainActor.run {
|
||||
let cases: [(input: String, expect: [String])] = [
|
||||
("うわああああ、まじか", ["うわああああ、マジか", "うわああああ、まじか"]),
|
||||
("は?", ["は?"]),
|
||||
@ -329,9 +343,11 @@ import XCTest
|
||||
print("\(#function) Result: accuracy \(accuracy), score \(score), count \(cases.count)")
|
||||
XCTAssertGreaterThan(accuracy, 0.7) // 0.7 < acuracy
|
||||
}
|
||||
}
|
||||
|
||||
/// MIDベースの文節単位計算でどれだけ同音異義語の判断が向上しているか確認する。
|
||||
func testMeaningBasedConversionAccuracy() throws {
|
||||
func testMeaningBasedConversionAccuracy() async throws {
|
||||
await MainActor.run {
|
||||
let cases: [(input: String, expect: String)] = [
|
||||
("しょうぼう、しょうか、ほのお", "消防、消火、炎"),
|
||||
("いえき、しょうか、こうそ", "胃液、消化、酵素"),
|
||||
@ -630,6 +646,7 @@ import XCTest
|
||||
print("\(#function) Result: accuracy \(accuracy), score \(score), count \(cases.count)")
|
||||
XCTAssertGreaterThan(accuracy, 0.7) // 0.7 < accuracy
|
||||
}
|
||||
}
|
||||
|
||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
|
||||
func testMozcEvaluationData() async throws {
|
||||
@ -684,12 +701,12 @@ import XCTest
|
||||
}
|
||||
|
||||
let argument = items[4]
|
||||
let converter = KanaKanjiConverter()
|
||||
let converter = await KanaKanjiConverter()
|
||||
var c = ComposingText()
|
||||
c.insertAtCursorPosition(input, inputStyle: .direct)
|
||||
var options = requestOptions()
|
||||
options.requireJapanesePrediction = false
|
||||
let results = converter.requestCandidates(c, options: options).mainResults
|
||||
let results = await converter.requestCandidates(c, options: options).mainResults
|
||||
cases += 1
|
||||
let azooKeyStatus = mozcEvaluation(command: command, argument: argument, results: results)
|
||||
if azooKeyStatus {
|
||||
|
Reference in New Issue
Block a user