You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.8 KiB
88 lines
2.8 KiB
import 'package:eaimar/modules/translation/models/translation_direction.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
const zh = 'zh-CN';
|
|
const en = 'en-US';
|
|
|
|
void main() {
|
|
group('单向模式:同声翻译 / 多媒体翻译', () {
|
|
for (final mode in ['simultaneous', 'audioVideo']) {
|
|
test('$mode 永远是 源→目标,与 ASR 报的语种无关', () {
|
|
// ASR 报对了
|
|
expect(
|
|
resolveTranslationDirection(
|
|
mode: mode,
|
|
sourceCode: zh,
|
|
targetCode: en,
|
|
detectedLanguageCode: zh),
|
|
const TranslationDirection(zh, en),
|
|
);
|
|
// ASR 没报(空串)—— 老实现在这里会判成反向
|
|
expect(
|
|
resolveTranslationDirection(
|
|
mode: mode, sourceCode: zh, targetCode: en),
|
|
const TranslationDirection(zh, en),
|
|
);
|
|
// ASR 报成了目标语言 —— 老实现同样会反向
|
|
expect(
|
|
resolveTranslationDirection(
|
|
mode: mode,
|
|
sourceCode: zh,
|
|
targetCode: en,
|
|
detectedLanguageCode: en),
|
|
const TranslationDirection(zh, en),
|
|
);
|
|
// 大小写/地区不一致
|
|
expect(
|
|
resolveTranslationDirection(
|
|
mode: mode,
|
|
sourceCode: zh,
|
|
targetCode: en,
|
|
detectedLanguageCode: 'zh'),
|
|
const TranslationDirection(zh, en),
|
|
);
|
|
});
|
|
}
|
|
|
|
test('换了语言对照样只认源→目标', () {
|
|
expect(
|
|
resolveTranslationDirection(
|
|
mode: 'simultaneous', sourceCode: en, targetCode: zh),
|
|
const TranslationDirection(en, zh),
|
|
);
|
|
});
|
|
});
|
|
|
|
group('面对面仍是双向', () {
|
|
test('说话人 1 → 源到目标;说话人 2 → 目标到源', () {
|
|
expect(
|
|
resolveTranslationDirection(
|
|
mode: 'faceToFace', sourceCode: zh, targetCode: en, speaker: 1),
|
|
const TranslationDirection(zh, en),
|
|
);
|
|
expect(
|
|
resolveTranslationDirection(
|
|
mode: 'faceToFace', sourceCode: zh, targetCode: en, speaker: 2),
|
|
const TranslationDirection(en, zh),
|
|
);
|
|
});
|
|
|
|
test('说话人未知时才看 ASR 检测结果', () {
|
|
expect(
|
|
resolveTranslationDirection(
|
|
mode: 'faceToFace',
|
|
sourceCode: zh,
|
|
targetCode: en,
|
|
detectedLanguageCode: en),
|
|
const TranslationDirection(en, zh),
|
|
);
|
|
});
|
|
});
|
|
|
|
test('isOneWayTranslationMode 只覆盖这两个模式', () {
|
|
expect(isOneWayTranslationMode('simultaneous'), isTrue);
|
|
expect(isOneWayTranslationMode('audioVideo'), isTrue);
|
|
expect(isOneWayTranslationMode('faceToFace'), isFalse);
|
|
expect(isOneWayTranslationMode('call'), isFalse);
|
|
});
|
|
}
|
|
|