1+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2+ using System ;
3+ using Algorithm . Interop ;
4+ using System . Collections . Generic ;
5+
6+ namespace Algorithm . UnitTest
7+ {
8+ [ TestClass ]
9+ public class HashTest
10+ {
11+ /// <summary>
12+ /// 哈希可行性测试
13+ /// </summary>
14+ [ TestMethod ]
15+ public void FeasibilityTest ( )
16+ {
17+ string [ ] testData = new string [ 12 ]
18+ {
19+ "SHVIOSJDifjDKljkJ$*F$W*938r5834r89we9fIOSFJOIS" , // 基础 ASCII 测试
20+ "SHVIOSJDifjDKljkJ$*F$W*939r5834r89we9fIOSFJOIS" , // 微变更测试 938 -> 939
21+ "DHSJKfkl5262fads43234LKgjsd#$%$%#$%fjLKSdkfJLD" , // 大变更测试
22+ "的是抗拒那就客服的撒滤镜打算离开房间啊w8e9832" , // 中文测试
23+ "的是抗拒那就客服的撒滤镜打算离开房间啊w8e9132" , // 中文微变更测试 9832 -> 9132
24+ "的dsa是fsd抗f拒s阿f斯是25是34会3卡死了的肌肤" , // 中文大变更测试
25+ "^$#%#$@T#@$@#$%#@^#$#@^#@%$&$#*$!*()$*@)($*)(#@" , // 纯符号测试
26+ "^$#%#$@T#@$@#$%#@^#$#@!#@%$&$#*$!*()$*@)($*)(#@" , // 纯符号微变更测试 ^ -> !
27+ "^$#%#*$(**(&#@(*$#*%(@$*(#@()#@09(()$*!)#(@*(#@" , // 纯符号大变更测试
28+ "🐦🐡🐣🐱💣" , // Emoji(Unicode) 测试
29+ "🐦🐡💯🐱💣" , // Emoji(Unicode) 小变更测试 🐣 -> 💯
30+ "💬💰💮🕷🚩" // Emoji(Unicode) 大变更测试
31+ } ;
32+ for ( int i = 0 ; i < testData . Length ; ++ i )
33+ {
34+ Console . WriteLine ( testData [ i ] ) ;
35+ Console . WriteLine ( Hash . FromString_ToHex_WithoutCompress ( testData [ i ] ) ) ;
36+ }
37+ }
38+
39+ /// <summary>
40+ /// 短长度字符串Hash测试
41+ /// </summary>
42+ [ TestMethod ]
43+ public void BenchMark_1 ( )
44+ {
45+ List < string > testdata = new ( ) ;
46+ Random random = new ( ) ;
47+ for ( int i = 0 ; i < 50 ; ++ i )
48+ {
49+ string data = "" ;
50+ for ( int j = 0 ; j < 1024 ; ++ j )
51+ {
52+ data += ( char ) ( 'a' + random . Next ( 0 , 25 ) ) ;
53+ }
54+ testdata . Add ( data ) ;
55+ }
56+ foreach ( string item in testdata )
57+ {
58+ Console . WriteLine ( item ) ;
59+ Console . WriteLine ( Hash . FromString_ToHex_WithoutCompress ( item ) ) ;
60+ }
61+ }
62+
63+ /// <summary>
64+ /// 短长度字符串Hash测试
65+ /// </summary>
66+ [ TestMethod ]
67+ public void BenchMark_1_Native ( )
68+ {
69+ List < string > testdata = new ( ) ;
70+ Random random = new ( ) ;
71+ for ( int i = 0 ; i < 50 ; ++ i )
72+ {
73+ string data = "" ;
74+ for ( int j = 0 ; j < 1024 ; ++ j )
75+ {
76+ data += ( char ) ( 'a' + random . Next ( 0 , 25 ) ) ;
77+ }
78+ testdata . Add ( data ) ;
79+ }
80+ foreach ( string item in testdata )
81+ {
82+ Console . WriteLine ( item ) ;
83+ Console . WriteLine ( BitConverter . ToString ( BitConverter . GetBytes ( item . GetHashCode ( ) ) ) ) ;
84+ }
85+ }
86+ }
87+ }
0 commit comments