-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestHashCollision.cs
More file actions
59 lines (49 loc) · 2.64 KB
/
Copy pathTestHashCollision.cs
File metadata and controls
59 lines (49 loc) · 2.64 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
using System;
using CSExcelConverter.Services;
namespace CSExcelConverter
{
public static class TestHashCollision
{
public static void RunTest()
{
Console.WriteLine("=== TextId Hash冲突检测测试 ===");
var textIdManager = new TextIdManager("./test_output");
// 测试正常情况
Console.WriteLine("\n1. 测试正常TextId生成:");
var id1 = textIdManager.GetOrCreateTextId("Hello World", "test.field1", "TestSheet", "name", 1);
var id2 = textIdManager.GetOrCreateTextId("Hello World", "test.field1", "TestSheet", "name", 1); // 相同文本
var id3 = textIdManager.GetOrCreateTextId("Goodbye World", "test.field2", "TestSheet", "desc", 2);
Console.WriteLine($" 'Hello World' -> {id1}");
Console.WriteLine($" 'Hello World' (重复) -> {id2}");
Console.WriteLine($" 'Goodbye World' -> {id3}");
Console.WriteLine($" 相同文本生成相同ID: {id1 == id2}");
// 测试后缀标识
Console.WriteLine("\n2. 测试后缀标识功能:");
var id4 = textIdManager.GetOrCreateTextId("apple", "test.field3", "TestSheet", "item", 3);
var id5 = textIdManager.GetOrCreateTextId("apple#company", "test.field4", "TestSheet", "item", 4);
var id6 = textIdManager.GetOrCreateTextId("apple#fruit", "test.field5", "TestSheet", "item", 5);
Console.WriteLine($" 'apple' -> {id4}");
Console.WriteLine($" 'apple#company' -> {id5}");
Console.WriteLine($" 'apple#fruit' -> {id6}");
Console.WriteLine($" 后缀产生不同ID: {id4 != id5 && id5 != id6}");
// 测试大量文本以增加冲突概率
Console.WriteLine("\n3. 测试大量文本生成 (检测潜在冲突):");
for (int i = 0; i < 100; i++)
{
var text = $"test_text_{i:D3}";
var textId = textIdManager.GetOrCreateTextId(text, $"test.field{i}", "TestSheet", "data", i + 10);
if (i < 5) // 只显示前5个
{
Console.WriteLine($" '{text}' -> {textId}");
}
}
// 显示统计信息
Console.WriteLine("\n4. 统计信息:");
textIdManager.ReportHashStatistics();
// 导出TextId映射表
Console.WriteLine("\n5. 导出TextId映射表:");
textIdManager.ExportTextIdMap();
Console.WriteLine("\n=== 测试完成 ===");
}
}
}