-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTestStringUtil.cs
98 lines (91 loc) · 2.83 KB
/
TestStringUtil.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DigitalPlatform.Text;
namespace UnitTestCore
{
public class TestStringUtil
{
[Theory]
[InlineData("", false)]
[InlineData(null, false)]
[InlineData("a", false)]
[InlineData("z", false)]
[InlineData("A", false)]
[InlineData("Z", false)]
[InlineData(".", false)]
[InlineData("~", false)]
[InlineData("a0", false)]
[InlineData("0z", false)]
[InlineData("0", true)]
[InlineData("1", true)]
[InlineData("2", true)]
[InlineData("3", true)]
[InlineData("4", true)]
[InlineData("5", true)]
[InlineData("6", true)]
[InlineData("7", true)]
[InlineData("8", true)]
[InlineData("9", true)]
public void test_isDigital(string input, bool expected)
{
var result = StringUtil.IsDigital(input);
Assert.Equal(expected, result);
}
[Theory]
[InlineData("", "-1")]
[InlineData(null, "-1")]
[InlineData("a", "-1")]
[InlineData("z", "-1")]
[InlineData("A", "-1")]
[InlineData("Z", "-1")]
[InlineData(".", ".")]
[InlineData("~", "-1")]
[InlineData("a0", "0")]
[InlineData("0z", "0")]
[InlineData(" 00 ", "00")]
[InlineData("0", "0")]
[InlineData("1", "1")]
[InlineData("2", "2")]
[InlineData("3", "3")]
[InlineData("4", "4")]
[InlineData("5", "5")]
[InlineData("6", "6")]
[InlineData("7", "7")]
[InlineData("8", "8")]
[InlineData("9", "9")]
public void test_getStringNumber(string input, string expected)
{
var result = StringUtil.GetStringNumber(input);
Assert.Equal(expected, result);
}
[Fact]
public void test_isNumSpeed()
{
int count = 1000;
var stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
for (int i = 0; i < count; i++)
{
var ret = StringUtil.IsNum("1234567890");
}
stopwatch.Stop();
Console.WriteLine($"IsNum() 调用 {count} 次耗费时间: {stopwatch.ElapsedMilliseconds} ms");
}
[Fact]
public void test_isDigitalSpeed()
{
int count = 1000;
var stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
for (int i = 0; i < count; i++)
{
var ret = StringUtil.IsDigital("1234567890");
}
stopwatch.Stop();
Console.WriteLine($"IsDigital() 调用 {count} 次耗费时间: {stopwatch.ElapsedMilliseconds} ms");
}
}
}