-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestReminderSystem.cs
More file actions
199 lines (174 loc) · 7.46 KB
/
TestReminderSystem.cs
File metadata and controls
199 lines (174 loc) · 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
namespace TimeTask.Tests
{
/// <summary>
/// 测试改进的任务提醒系统
/// </summary>
public class TestReminderSystem
{
public static async Task RunTests()
{
Console.WriteLine("=== 任务提醒系统测试 ===");
// 测试1: 提醒时间计算
TestReminderTiming();
// 测试2: 设置验证
TestSettingsValidation();
// 测试3: 任务优先级分析(需要LLM服务)
await TestTaskPriorityAnalysis();
Console.WriteLine("=== 测试完成 ===");
}
private static void TestReminderTiming()
{
Console.WriteLine("\n--- 测试提醒时间计算 ---");
var testTask = new ItemGrid
{
Task = "测试任务",
CreatedDate = DateTime.Now.AddDays(-2),
LastModifiedDate = DateTime.Now.AddDays(-2),
InactiveWarningCount = 0,
IsActive = true
};
// 模拟第一次提醒条件
var inactiveDuration = DateTime.Now - testTask.LastModifiedDate;
var firstWarningThreshold = TimeSpan.FromDays(1);
if (inactiveDuration > firstWarningThreshold && testTask.InactiveWarningCount == 0)
{
Console.WriteLine("✓ 第一次提醒条件满足");
testTask.InactiveWarningCount = 1;
testTask.LastModifiedDate = DateTime.Now;
}
// 模拟第二次提醒条件
testTask.LastModifiedDate = DateTime.Now.AddDays(-4);
inactiveDuration = DateTime.Now - testTask.LastModifiedDate;
var secondWarningThreshold = TimeSpan.FromDays(3);
if (inactiveDuration > secondWarningThreshold && testTask.InactiveWarningCount == 1)
{
Console.WriteLine("✓ 第二次提醒条件满足");
testTask.InactiveWarningCount = 2;
}
Console.WriteLine($"任务警告次数: {testTask.InactiveWarningCount}");
}
private static void TestSettingsValidation()
{
Console.WriteLine("\n--- 测试设置验证 ---");
// 测试有效设置
var validSettings = new
{
FirstWarningAfterDays = 1,
SecondWarningAfterDays = 3,
StaleTaskThresholdDays = 14,
MaxInactiveWarnings = 3,
ReminderCheckIntervalMinutes = 5
};
bool isValid = ValidateReminderSettings(
validSettings.FirstWarningAfterDays,
validSettings.SecondWarningAfterDays,
validSettings.StaleTaskThresholdDays,
validSettings.MaxInactiveWarnings,
validSettings.ReminderCheckIntervalMinutes
);
Console.WriteLine($"✓ 有效设置验证: {(isValid ? "通过" : "失败")}");
// 测试无效设置
bool isInvalid = ValidateReminderSettings(5, 3, 14, 3, 5); // 第二次提醒小于第一次
Console.WriteLine($"✓ 无效设置验证: {(!isInvalid ? "通过" : "失败")}");
}
private static bool ValidateReminderSettings(int first, int second, int stale, int maxWarnings, int interval)
{
if (first < 1 || first > 30) return false;
if (second < first || second > 60) return false;
if (stale < second || stale > 365) return false;
if (maxWarnings < 1 || maxWarnings > 10) return false;
if (interval < 1 || interval > 60) return false;
return true;
}
private static async Task TestTaskPriorityAnalysis()
{
Console.WriteLine("\n--- 测试任务优先级分析 ---");
try
{
var llmService = LlmService.Create();
var testTasks = new[]
{
"修复生产环境的关键bug",
"准备下周的项目演示",
"整理办公桌",
"回复邮件"
};
foreach (var taskDesc in testTasks)
{
try
{
var (importance, urgency) = await llmService.AnalyzeTaskPriorityAsync(taskDesc);
var quadrant = GetQuadrantFromPriority(importance, urgency);
Console.WriteLine($"任务: {taskDesc}");
Console.WriteLine($" 重要性: {importance}, 紧急性: {urgency}");
Console.WriteLine($" 推荐象限: {quadrant}");
Console.WriteLine();
}
catch (Exception ex)
{
Console.WriteLine($"分析任务 '{taskDesc}' 时出错: {ex.Message}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"LLM服务不可用: {ex.Message}");
}
}
private static string GetQuadrantFromPriority(string importance, string urgency)
{
bool isImportant = importance?.ToLower().Contains("high") == true;
bool isUrgent = urgency?.ToLower().Contains("high") == true;
if (isImportant && isUrgent) return "重要且紧急";
if (isImportant && !isUrgent) return "重要不紧急";
if (!isImportant && isUrgent) return "不重要但紧急";
return "不重要不紧急";
}
/// <summary>
/// 创建测试任务数据
/// </summary>
public static List<ItemGrid> CreateTestTasks()
{
return new List<ItemGrid>
{
new ItemGrid
{
Task = "需要第一次提醒的任务",
CreatedDate = DateTime.Now.AddDays(-2),
LastModifiedDate = DateTime.Now.AddDays(-2),
InactiveWarningCount = 0,
IsActive = true,
IsActiveInQuadrant = true,
Importance = "High",
Urgency = "High"
},
new ItemGrid
{
Task = "需要第二次提醒的任务",
CreatedDate = DateTime.Now.AddDays(-5),
LastModifiedDate = DateTime.Now.AddDays(-4),
InactiveWarningCount = 1,
IsActive = true,
IsActiveInQuadrant = true,
Importance = "High",
Urgency = "Low"
},
new ItemGrid
{
Task = "过期任务",
CreatedDate = DateTime.Now.AddDays(-20),
LastModifiedDate = DateTime.Now.AddDays(-15),
InactiveWarningCount = 2,
IsActive = true,
IsActiveInQuadrant = true,
Importance = "Medium",
Urgency = "Low"
}
};
}
}
}