add: Grammar2测试
This commit is contained in:
parent
fff3a4ed96
commit
da71e8d4df
36
Katheryne.Tests/Katheryne/Grammar2/grammar.yaml
Normal file
36
Katheryne.Tests/Katheryne/Grammar2/grammar.yaml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
robotName: 凯瑟琳
|
||||||
|
stages:
|
||||||
|
- name: running
|
||||||
|
answer: 向着星辰和深渊!欢迎来到冒险家协会。
|
||||||
|
transformers:
|
||||||
|
- pattern: 领取每日委托奖励
|
||||||
|
nextStageName: daily-task-question
|
||||||
|
- pattern: 你好|您好|[Hh]ello
|
||||||
|
nextStageName: hello
|
||||||
|
- pattern: .*?
|
||||||
|
nextStageName: unknown
|
||||||
|
|
||||||
|
- name: daily-task-question
|
||||||
|
answer: 冒险家今日完成的任务是?
|
||||||
|
transformers:
|
||||||
|
- pattern: (.*)
|
||||||
|
nextStageName: daily-task
|
||||||
|
|
||||||
|
- name: daily-task
|
||||||
|
answer: 感谢冒险家完成了“$1”, 这是你的奖励。
|
||||||
|
transformers:
|
||||||
|
- pattern:
|
||||||
|
nextStageName: running
|
||||||
|
|
||||||
|
- name: hello
|
||||||
|
answer: 你好,我是冒险家协会的接待员凯瑟琳。
|
||||||
|
transformers:
|
||||||
|
- pattern:
|
||||||
|
nextStageName: running
|
||||||
|
|
||||||
|
- name: unknown
|
||||||
|
answer: 对不起,做不到。
|
||||||
|
transformers:
|
||||||
|
- pattern:
|
||||||
|
nextStageName: running
|
||||||
|
beginStageName: running
|
4
Katheryne.Tests/Katheryne/Grammar2/in.txt
Normal file
4
Katheryne.Tests/Katheryne/Grammar2/in.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
你好
|
||||||
|
I asdasdasdfsavnakjnhvas;dvf
|
||||||
|
领取每日委托奖励
|
||||||
|
sCSJDASKJDNVF
|
9
Katheryne.Tests/Katheryne/Grammar2/out.txt
Normal file
9
Katheryne.Tests/Katheryne/Grammar2/out.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
向着星辰和深渊!欢迎来到冒险家协会。
|
||||||
|
你好,我是冒险家协会的接待员凯瑟琳。
|
||||||
|
向着星辰和深渊!欢迎来到冒险家协会。
|
||||||
|
对不起,做不到。
|
||||||
|
向着星辰和深渊!欢迎来到冒险家协会。
|
||||||
|
冒险家今日完成的任务是?
|
||||||
|
感谢冒险家完成了“sCSJDASKJDNVF”, 这是你的奖励。
|
||||||
|
向着星辰和深渊!欢迎来到冒险家协会。
|
||||||
|
再见。
|
|
@ -1,4 +1,5 @@
|
||||||
using Katheryne.Abstractions;
|
using Katheryne.Abstractions;
|
||||||
|
using Katheryne.Modules;
|
||||||
using Katheryne.Services;
|
using Katheryne.Services;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
@ -46,7 +47,57 @@ public class KatheryneRobotTests
|
||||||
ValidateOutput(_katheryneChatRobotFactory.GetRobot(), file);
|
ValidateOutput(_katheryneChatRobotFactory.GetRobot(), file);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ValidateOutput(IChatRobot robot, InputOutputFile file)
|
[Fact]
|
||||||
|
public void KatheryneRobotTest2()
|
||||||
|
{
|
||||||
|
InputOutputFile file = new("Grammar2");
|
||||||
|
StreamReader reader = new(Path.Combine(file.PrefixPath, "grammar.yaml"));
|
||||||
|
_katheryneChatRobotFactory.SetGrammar(reader.ReadToEnd());
|
||||||
|
|
||||||
|
ValidateOutput(_katheryneChatRobotFactory.GetRobot(), file);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WeatherModuleTest()
|
||||||
|
{
|
||||||
|
const string grammar =
|
||||||
|
"""
|
||||||
|
robotName: 凯瑟琳
|
||||||
|
stages:
|
||||||
|
- name: running
|
||||||
|
answer: 向着星辰和深渊!欢迎来到冒险家协会。
|
||||||
|
transformers:
|
||||||
|
- pattern: .*?天气|气温.*?
|
||||||
|
nextStageName: weather
|
||||||
|
- pattern: .*?
|
||||||
|
nextStageName: running
|
||||||
|
|
||||||
|
- name: weather
|
||||||
|
answer: 今天璃月港的天气是@weather/text,气温是@weather/temp。
|
||||||
|
transformers:
|
||||||
|
- pattern:
|
||||||
|
nextStageName: running
|
||||||
|
beginStageName: running
|
||||||
|
""";
|
||||||
|
|
||||||
|
ModuleBase weatherModule = new WeatherModule();
|
||||||
|
|
||||||
|
_katheryneChatRobotFactory.Modules.Clear();
|
||||||
|
_katheryneChatRobotFactory.Modules.Add(weatherModule.ModuleName, weatherModule);
|
||||||
|
_katheryneChatRobotFactory.SetGrammar(grammar);
|
||||||
|
|
||||||
|
IChatRobot robot = _katheryneChatRobotFactory.GetRobot();
|
||||||
|
IEnumerable<string> answers = robot.ChatNext("今天天气怎么样?");
|
||||||
|
|
||||||
|
Assert.Contains(answers, answer =>
|
||||||
|
answer == $"今天璃月港的天气是{weatherModule["text"]},气温是{weatherModule["temp"]}。");
|
||||||
|
|
||||||
|
answers = robot.ChatNext("今天气温是多少度?");
|
||||||
|
Assert.Contains(answers, answer =>
|
||||||
|
answer == $"今天璃月港的天气是{weatherModule["text"]},气温是{weatherModule["temp"]}。");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateOutput(IChatRobot robot, InputOutputFile file)
|
||||||
{
|
{
|
||||||
foreach (string output in robot.OnChatStart())
|
foreach (string output in robot.OnChatStart())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user