-
Notifications
You must be signed in to change notification settings - Fork 659
/
Copy pathStaticTest.cs
144 lines (124 loc) · 3.47 KB
/
StaticTest.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestCases
{
public class StaticTest
{
public class Test_A
{
public Test_A(Test_B b)
{
}
}
public class Test_B
{
}
public sealed class NormalClass
{
//public static int result;
public static void Create()
{
//result++;
Console.WriteLine("2");
}
static NormalClass()
{
//result++;
Console.WriteLine("1");
}
}
static Test_A Create_With_Reference()
{
return new Test_A(new Test_B());
}
public static void UnitTest_StaticTest01()
{
Test_A a = Create_With_Reference();
if (a.GetType() != typeof(Test_A))
throw new Exception($"{a.GetType()} != Test_A");
}
public static void UnitTest_StaticTest02()
{
NormalClass.Create();
//if (NormalClass.result != 2)
// throw new Exception("result != 2");
//NormalClass.result = 0;
}
public static void UnitTest_StaticTest03()
{
dict[1] = new List<string>() { "helloworld", "hi" };
UnitTest_StaticTest03Sub();
}
public static Dictionary<int, List<string>> dict = new Dictionary<int, List<string>>();
static void UnitTest_StaticTest03Sub()
{
if (dict.TryGetValue(1, out var ls))
{
ls.Add("ggg");
foreach (var item in ls)
{
Console.WriteLine(item);
}
}
}
private static int testVal;
private static Vector3 testVal2;
private static object testVal3;
private static void UnitTest_StaticTest04Sub(ref int i)
{
Console.WriteLine(i);
i = 0;
}
public static void UnitTest_StaticTest04()
{
testVal = 111;
UnitTest_StaticTest04Sub(ref testVal);
if (testVal != 0)
throw new Exception();
}
private static void UnitTest_StaticTest05Sub(ref Vector3 i)
{
Console.WriteLine(i);
i = Vector3.Zero;
}
public static void UnitTest_StaticTest05()
{
testVal2 = Vector3.One;
UnitTest_StaticTest05Sub(ref testVal2);
if (testVal2.x != 0)
throw new Exception();
}
private static void UnitTest_StaticTest06Sub(ref object i)
{
Console.WriteLine(i);
i = 0;
}
public static void UnitTest_StaticTest06()
{
testVal3 = 111;
UnitTest_StaticTest06Sub(ref testVal3);
if ((int)testVal3 != 0)
throw new Exception();
}
public static bool static_field = true;
public static bool static_Property => static_field;
public static int UnitTest_StaticTest07()
{
int a = 2;
int n = 0;
try
{
if (static_Property) //属性
n += a;
return n;
}
catch (Exception)
{
n = -1;
}
return n;
}
}
}