chengjie 4 月之前
父節點
當前提交
52b3e56aa7
共有 5 個文件被更改,包括 76 次插入63 次删除
  1. 15 0
      test-aliyun-api.js
  2. 0 22
      test-enhance.mjs
  3. 61 0
      test-json-fix.js
  4. 0 38
      test-string-validation.js
  5. 0 3
      test-syntax.mjs

+ 15 - 0
test-aliyun-api.js

@@ -0,0 +1,15 @@
1
+// 测试阿里云通义千问API调用
2
+import { generateArticle } from './src/api/yjbdc/aiController.js';
3
+
4
+async function testAliyunAPI() {
5
+  try {
6
+    console.log('开始测试阿里云通义千问API...');
7
+    const result = await generateArticle('请简要介绍一下人工智能的发展历程', 'aliyun');
8
+    console.log('API调用成功,返回结果:');
9
+    console.log(result);
10
+  } catch (error) {
11
+    console.error('API调用失败:', error);
12
+  }
13
+}
14
+
15
+testAliyunAPI();

+ 0 - 22
test-enhance.mjs

@@ -1,22 +0,0 @@
1
-import { enhanceFormsOfWords } from './src/api/yjbdc/aiController.js';
2
-
3
-// 创建一个测试用例
4
-const testJson = {
5
-  ArticleEnglish: [
6
-    "The quick brown fox jumps over the lazy dog.",
7
-    "She is running in the park every morning.",
8
-    "They have been working on this project for months.",
9
-    "I went to the store yesterday and bought some groceries.",
10
-    "The children are playing with their new toys."
11
-  ],
12
-  FormsOfWords: []
13
-};
14
-
15
-// 测试单词列表
16
-const testWords = "fox, run, go, play, work";
17
-
18
-// 调用函数
19
-const result = enhanceFormsOfWords(testJson, testWords);
20
-
21
-// 打印结果
22
-console.log(JSON.stringify(result, null, 2));

+ 61 - 0
test-json-fix.js

@@ -0,0 +1,61 @@
1
+// 测试JSON修复功能
2
+import { validateAndFixJSON } from './src/api/yjbdc/aiController.js';
3
+
4
+// 测试用例
5
+const testCases = [
6
+  // 正常JSON
7
+  { 
8
+    name: "正常JSON", 
9
+    input: '{"name":"test","value":123}' 
10
+  },
11
+  // Markdown代码块包裹的JSON
12
+  { 
13
+    name: "Markdown代码块", 
14
+    input: '```json\n{"name":"test","value":123}\n```' 
15
+  },
16
+  // 带有语法错误的JSON
17
+  { 
18
+    name: "语法错误JSON", 
19
+    input: '{name:"test",value:123}' 
20
+  },
21
+  // 混合问题
22
+  { 
23
+    name: "混合问题", 
24
+    input: '```json\n{name:"test",value:123}\n```' 
25
+  },
26
+  // 非JSON内容中包含JSON对象
27
+  {
28
+    name: "非JSON内容中包含JSON对象",
29
+    input: '这是一段文本,其中包含JSON:{"name":"test","value":123},后面还有其他内容'
30
+  },
31
+  // 阿里云通义千问可能返回的格式
32
+  {
33
+    name: "阿里云通义千问返回格式",
34
+    input: '```json\n{\n  "title": "测试文章",\n  "content": "这是一篇测试文章",\n  "author": "AI助手",\n  "date": "2023-07-15"\n}\n```'
35
+  }
36
+];
37
+
38
+// 运行测试
39
+console.log("开始测试JSON修复功能...\n");
40
+
41
+testCases.forEach(testCase => {
42
+  console.log(`测试用例: ${testCase.name}`);
43
+  console.log(`输入: ${testCase.input}`);
44
+  
45
+  try {
46
+    const fixed = validateAndFixJSON(testCase.input);
47
+    console.log(`修复后: ${fixed}`);
48
+    
49
+    try {
50
+      const parsed = JSON.parse(fixed);
51
+      console.log(`解析结果: ${JSON.stringify(parsed, null, 2)}`);
52
+      console.log("✅ 测试通过\n");
53
+    } catch (error) {
54
+      console.error(`❌ 修复后仍无法解析: ${error.message}\n`);
55
+    }
56
+  } catch (error) {
57
+    console.error(`❌ 修复过程出错: ${error.message}\n`);
58
+  }
59
+});
60
+
61
+console.log("测试完成");

+ 0 - 38
test-string-validation.js

@@ -1,38 +0,0 @@
1
-'use strict';
2
-import { stringUtils } from './src/util/stringClass.js';
3
-
4
-// 测试用例
5
-const testCases = [
6
-    { input: '你好123', expected: true, desc: '汉字和数字' },
7
-    { input: '测试(123)', expected: true, desc: '汉字、数字和半角括号' },
8
-    { input: '测试(456)', expected: true, desc: '汉字、数字和全角括号' },
9
-    { input: '测试(123)(456)', expected: true, desc: '混合使用全角和半角括号' },
10
-    { input: '', expected: true, desc: '空字符串' },
11
-    { input: '测试abc', expected: true, desc: '包含小写英文字母' },
12
-    { input: '测试ABC', expected: true, desc: '包含大写英文字母' },
13
-    { input: '测试aBC123', expected: true, desc: '混合大小写字母和数字' },
14
-    { input: 'Hello世界123', expected: true, desc: '混合英文、汉字和数字' },
15
-    { input: '测试123!', expected: false, desc: '包含特殊字符' },
16
-    { input: '测试[123]', expected: false, desc: '包含方括号' },
17
-    { input: '测试{123}', expected: false, desc: '包含花括号' },
18
-    { input: 'Test@123', expected: false, desc: '包含@符号' }
19
-];
20
-
21
-// 运行测试
22
-console.log('开始测试 IsValidChineseNumberParentheses 函数...');
23
-console.log('----------------------------------------');
24
-
25
-let passCount = 0;
26
-for (const test of testCases) {
27
-    const result = stringUtils.IsValidChineseNumberParentheses(test.input);
28
-    const passed = result === test.expected;
29
-    
30
-    console.log(`测试: ${test.desc}`);
31
-    console.log(`输入: "${test.input}"`);
32
-    console.log(`期望: ${test.expected}, 实际: ${result}, 结果: ${passed ? '通过' : '失败'}`);
33
-    console.log('----------------------------------------');
34
-    
35
-    if (passed) passCount++;
36
-}
37
-
38
-console.log(`测试完成: ${passCount}/${testCases.length} 通过`);

+ 0 - 3
test-syntax.mjs

@@ -1,3 +0,0 @@
1
-import { enhanceFormsOfWords } from './src/api/yjbdc/aiController.js';
2
-
3
-console.log('函数语法检查通过');