add: Grammar2测试

This commit is contained in:
jackfiled 2023-11-20 13:32:44 +08:00
parent fff3a4ed96
commit da71e8d4df
4 changed files with 101 additions and 1 deletions

View 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

View File

@ -0,0 +1,4 @@
你好
I asdasdasdfsavnakjnhvas;dvf
领取每日委托奖励
sCSJDASKJDNVF

View File

@ -0,0 +1,9 @@
向着星辰和深渊!欢迎来到冒险家协会。
你好,我是冒险家协会的接待员凯瑟琳。
向着星辰和深渊!欢迎来到冒险家协会。
对不起,做不到。
向着星辰和深渊!欢迎来到冒险家协会。
冒险家今日完成的任务是?
感谢冒险家完成了“sCSJDASKJDNVF”, 这是你的奖励。
向着星辰和深渊!欢迎来到冒险家协会。
再见。

View File

@ -1,4 +1,5 @@
using Katheryne.Abstractions;
using Katheryne.Modules;
using Katheryne.Services;
using Microsoft.Extensions.Logging;
using Moq;
@ -46,7 +47,57 @@ public class KatheryneRobotTests
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())
{