86 lines
3.4 KiB
C#
86 lines
3.4 KiB
C#
using Microsoft.Extensions.Options;
|
|
using RecordBot.Options;
|
|
using RecordBot.Services;
|
|
using Xunit;
|
|
|
|
namespace RecordBot.Tests;
|
|
|
|
public class KeywordClassifierTests
|
|
{
|
|
private readonly KeywordClassifier _classifier =
|
|
new(Microsoft.Extensions.Options.Options.Create(new RecordBotOptions()));
|
|
|
|
[Theory]
|
|
[InlineData("#支出 午餐 35", "支出", "午餐 35", 35.0)]
|
|
[InlineData("支出:买菜 42.5", "支出", "买菜 42.5", 42.5)]
|
|
[InlineData("待办 明天交房租", "待办", "明天交房租", null)]
|
|
[InlineData("随便记一笔", "笔记", "随便记一笔", null)]
|
|
[InlineData("提醒我10月15日还信用卡", "待办", "我10月15日还信用卡", null)]
|
|
public void ClassifyText_Works(string input, string category, string content, double? amount)
|
|
{
|
|
var r = _classifier.ClassifyText(input);
|
|
Assert.False(r.IsCommand);
|
|
Assert.Equal(category, r.Category);
|
|
Assert.Equal(content, r.Content);
|
|
if (amount is null)
|
|
Assert.Null(r.Amount);
|
|
else
|
|
Assert.Equal((decimal)amount, r.Amount);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("帮助", "help")]
|
|
[InlineData("查询", "list")]
|
|
[InlineData("统计", "stats")]
|
|
[InlineData("聊天模式", "mode_chat")]
|
|
[InlineData("联网聊天模式", "mode_chat_online")]
|
|
[InlineData("记录模式", "mode_record")]
|
|
[InlineData("当前模式", "mode_status")]
|
|
[InlineData("我的提醒", "reminders")]
|
|
[InlineData("取消提醒 3", "cancel_reminder:3")]
|
|
[InlineData("我的待办", "todos")]
|
|
[InlineData("导出本月", "export_month")]
|
|
[InlineData("删除 12", "delete_record:12")]
|
|
[InlineData("删除上一条", "delete_last")]
|
|
[InlineData("改金额 12 35", "set_amount:12:35")]
|
|
[InlineData("改分类 12 支出", "set_category:12:支出")]
|
|
[InlineData("完成 3", "complete_todo:3")]
|
|
[InlineData("完成待办 3", "complete_todo:3")]
|
|
[InlineData("延期 3 明天", "defer_todo:3:明天")]
|
|
[InlineData("今天", "list_range:today")]
|
|
[InlineData("昨天", "list_range:yesterday")]
|
|
[InlineData("本周", "list_range:this_week")]
|
|
[InlineData("上周花了多少", "stats_range:last_week")]
|
|
[InlineData("昨天午餐", "list_range:yesterday:午餐")]
|
|
[InlineData("画图 一只橘猫", "draw_image:一只橘猫")]
|
|
[InlineData("生成图片 海边日落", "draw_image:海边日落")]
|
|
[InlineData("画图 第一行\n第二行风格", "draw_image:第一行\n第二行风格")]
|
|
[InlineData("绘图 一只橘猫", "draw_grok_image:一只橘猫")]
|
|
[InlineData("绘图:海边日落", "draw_grok_image:海边日落")]
|
|
[InlineData("绘图 第一行\n第二行风格", "draw_grok_image:第一行\n第二行风格")]
|
|
public void Commands_Detected(string input, string command)
|
|
{
|
|
var r = _classifier.ClassifyText(input);
|
|
Assert.True(r.IsCommand);
|
|
Assert.Equal(command, r.Command);
|
|
}
|
|
|
|
[Fact]
|
|
public void Today_With_Purchase_Is_Not_Command()
|
|
{
|
|
var r = _classifier.ClassifyText("今天买了菜花了30元");
|
|
Assert.False(r.IsCommand);
|
|
Assert.Equal("支出", r.Category);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("今天是几号?")]
|
|
[InlineData("今天的日期")]
|
|
[InlineData("昨天星期几")]
|
|
public void Today_Date_Questions_Are_Not_Range_Commands(string input)
|
|
{
|
|
var r = _classifier.ClassifyText(input);
|
|
Assert.False(r.IsCommand);
|
|
}
|
|
}
|