-
Notifications
You must be signed in to change notification settings - Fork 659
/
Copy pathLightTester1.cs
482 lines (415 loc) · 12.5 KB
/
LightTester1.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
using ILRuntimeTest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestCases
{
//原来C#LightTestor的部分
public class ExpTest_10
{
struct tttttt
{
public bool aol;
}
//只要有一个静态函数包含UnitTest名称的,就作为单元测试
public static object UnitTest_1001()
{
int[] aaa = new int[10];
for (uint i = 0; i < 10; i++)
{
aaa[i] = 1;
}
object[] arr = new object[3];
for (uint i = 0; i < 2; i++)
{
arr[i + 1] = 1;
}
//1001 _1001_expression
return TestIsInt(arr);
}
static bool TestIsInt(object[] obj)
{
if (obj[1] is StructTest2)
return false;
if (obj[1] is int)
return true;
return false;
}
public static object UnitTest_1002()
{
//1002 _1002_expression
int a = (int)(Math.Pow(1.4f, 5) * 5f);
Vector3 v3 = new Vector3((252.0f / 255.0f), (207.0f / 255.0f), (20.0f / 255.0f));
Console.WriteLine("v3=" + v3);
tttttt b = new tttttt();
UnitTest_1002_Sub(ref b.aol);
Console.WriteLine("bol=" + b.aol.ToString());
return (2 + 55) * 3434 + a;
}
static void UnitTest_1002_Sub(ref bool aol)
{
aol = true;
Console.WriteLine("bol=" + aol.ToString());
}
class StructTest
{
public Vector3 Vector;
public ILRuntimeTest.TestFramework.TestStruct Struct;
}
struct StructTest3
{
public float A;
public StructTest B;
public Vector3 C;
}
public static void UnitTest_Struct()
{
StructTest a = new TestCases.ExpTest_10.StructTest();
Vector3 vec = a.Vector;
vec.x += 10;
vec.y += 11;
Console.WriteLine(vec.x);
Console.WriteLine(a.Vector.x);
ILRuntimeTest.TestFramework.TestStruct b = a.Struct;
a.Struct.value += 100;
Console.WriteLine(b.value);
Console.WriteLine(a.Struct.value);
}
class StructTest2
{
public ILRuntimeTest.TestFramework.TestStruct Struct;
}
public static void UnitTest_Struct2()
{
ILRuntimeTest.TestFramework.TestClass3 obj = new ILRuntimeTest.TestFramework.TestClass3();
obj.Struct.value = 111;
obj.Struct.value += 111;
Console.WriteLine(obj.Struct.value);
StructTest2 obj2 = new TestCases.ExpTest_10.StructTest2();
obj2.Struct.value = 111;
obj2.Struct.value += 111;
Console.WriteLine(obj2.Struct.value);
ILRuntimeTest.TestFramework.TestStruct.instance.value = 222;
ILRuntimeTest.TestFramework.TestStruct.instance.value += 111;
Console.WriteLine(ILRuntimeTest.TestFramework.TestStruct.instance.value);
}
public static void UnitTest_10022()
{
Vector3 pos = Vector3.One;
var pos2 = tttt(pos);
if (pos.x == pos2.x)
{
Console.WriteLine("pos.x = " + pos.x);
Console.WriteLine("pos2.x = " + pos2.x);
throw new Exception("Value Type Violation");
}
}
public static void UnitTest_10023()
{
StructTest3 a;
a = Sub10023();
Vector3 pos = a.C;
pos.x += 123;
Vector3 pos2 = a.B.Vector;
pos2.x -= 120;
Console.WriteLine("pos.x=" + pos.x);
Console.WriteLine("a.C.x=" + a.C.x);
if (pos.x == a.C.x)
throw new Exception("Value Type Violation");
Console.WriteLine("pos2.x=" + pos2.x);
Console.WriteLine("a.B.Vector.x=" + a.B.Vector.x);
if (pos2.x == a.B.Vector.x)
throw new Exception("Value Type Violation");
}
static StructTest3 Sub10023()
{
StructTest3 a;
a.A = 123;
a.C = Vector3.One;
a.B = new StructTest();
a.B.Vector = Vector3.One * 123;
return a;
}
static Vector3 tttt(Vector3 a)
{
a.x = 12345;
return a;
}
public static object UnitTest_1003()
{
//1003 _1003_expression
return 1 + 2 * 2 + 55 * 3434 + (2 - 3) - (3 - 3) + 5;
}
public static object UnitTest_1004()
{
//1004 _1004_expression
string a = "abc";
string b = "abd";
return "str=" + a + b;
}
public static object UnitTest_1005()
{
float s = 0.2f;
if (s <= 0f || s >= 2f)
{
Console.WriteLine("" + 1);
}
else
{
Console.WriteLine("" + 2);
}
return 1;
}
public static string UnitTest_1006()
{
byte b = 11;
return b.ToString();
}
public static byte UnitTest_1007()
{
byte b = 12;
byte c = 255;
return (byte)(b + c);
}
public static sbyte UnitTest_1007_2()
{
sbyte b = 12;
sbyte c = 127;
return (sbyte)(b + c);
}
struct TestStruc
{
public int a;
public float b;
public TestStruc(int a, float b)
{
this.a = a;
this.b = b;
}
}
public static int UnitTest_1008()
{
TestStruc a, b;
a.a = 1;
a.b = 2.3f;
b = new TestStruc();
b = new TestStruc(9, 10.2f);
Console.WriteLine("Value of b:");
Console.WriteLine(b.a);
Console.WriteLine(b.b);
b = a;
b.a = 2;
b.b = 3.2f;
ValueTest(a);
a.b = b.b;
return a.a;
}
static void ValueTest(TestStruc a)
{
a.a = 3;
}
class ClsA
{
public int A { get; set; }
public bool B { get; set; }
public virtual void TestVirtual()
{
A = 1;
B = false;
}
public override string ToString()
{
return string.Format("A={0},B={1}", A, B);
}
}
class B : ClsA
{
public override void TestVirtual()
{
base.TestVirtual();
B = true;
}
}
class C : B
{
}
[ILRuntimeTest(ExpectException = typeof(NullReferenceException))]
public static bool UnitTest_1009()
{
B test = new B();
test.TestVirtual();
Console.WriteLine(string.Format("A={0},B={1}", test.A, test.B));
ClsA test2 = (ClsA)test;
test2.TestVirtual();
Console.WriteLine(string.Format("A={0},B={1}", test2.A, test2.B));
test2 = new C();
test2.TestVirtual();
Console.WriteLine(string.Format("A={0},B={1}", test2.A, test2.B));
ClsA test3 = new ClsA();
test3.TestVirtual();
Console.WriteLine(string.Format("A={0},B={1}", test3.A, test3.B));
test = test3 as B;
if (test == null)
{
Console.WriteLine(string.Format("A={0},B={1}", test.A, test.B));
}
return test3.B;
}
public static void UnitTest_1010()
{
uint a = 100;
TestUInt(a);
TestUInt((ulong)a);
}
static void TestUInt(uint a)
{
float speedUp = (1 - (float)a / 1000f);
uint speedUp2 = 1000 / a;
Console.WriteLine(speedUp);
Console.WriteLine(speedUp2);
}
static void TestUInt(ulong a)
{
float speedUp = (1 - (float)a / 1000f);
ulong speedUp2 = 1000 / a;
Console.WriteLine(speedUp);
Console.WriteLine(speedUp2);
}
public static void UnitTest_1011()
{
long value = 0;
value = value + 0xffffffff;
Console.WriteLine(value);
}
public static void UnitTest_1012()
{
object och = 'd';
char ch1 = (char)och;
Console.WriteLine("test1:" + (int)ch1 + " " + ch1);
}
public static void UnitTest_1013()
{
var testClass = new TestClass<object>();
testClass.tValue = new object();
testClass.obj = new object();
// 清理异常
testClass.SetNull();
if (testClass.tValue != null)
throw new Exception();
testClass.Print();
// 清理正常
testClass.tValue = null;
testClass.obj = null;
testClass.Print();
}
public static void UnitTest_1014()
{
int a = 0;
UnitTest_1014Sub(ref a);
if (a != 1)
throw new Exception();
}
static void UnitTest_1014Sub(ref int a)
{
try
{
a = 2;
return;
}
finally
{
a = 1;
}
}
public static void UnitTest_1015()
{
//Console.WriteLine(ILRuntimeTest.TestMainForm._app.GetCurrentStackTrace());
}
public static void UnitTest_1016()
{
uint u1 = 1607900000;
uint u2 = 1609000000;
double d1 = u1;
double d2 = u2;
double diff = Math.Abs(d1 - u1);
Console.WriteLine("diff=" + diff);
if (Math.Abs(d1 - u1) > 1)
throw new Exception("diff=" + diff);
}
public class TestClass<T> where T : class, new()
{
public T tValue;
public object obj;
public void SetNull()
{
tValue = null; // 清理失败,不为空
obj = null; // 能正常清理
}
public void Print()
{
Console.WriteLine(tValue);
Console.WriteLine(obj);
}
}
public static void UnitTest_1017()
{
int defaultTabSN = -1;
UnitTest_1017Sub(defaultTabSN != -1 ? defaultTabSN : 111, false);
}
static void UnitTest_1017Sub(int result, bool flag)
{
if (result != 111)
throw new Exception();
Console.WriteLine($"result={result}");
}
public static void UnitTest_1018()
{
UnitTest_1018Sub(false, new sss(), 0);
}
class sss
{
public int Position { get; set; }
}
static void UnitTest_1018Sub(bool byPos, sss data, int idx)
{
Dictionary<int, sss> retDict = new Dictionary<int, sss>();
for (int i = 0; i < 10; i++)
{
if (byPos)
{
}
else
{
var key = byPos ? data.Position : ++idx;
Console.WriteLine($"byPos:{byPos}, key:{key},idx:{idx}");
if (retDict.ContainsKey(key))
{
Console.WriteLine("Contains");
}
retDict[key] = data;
}
}
}
static int a = 0;
public static void UnitTest_1019()
{
uint x = 1000;
int xx = (int)x;
a = xx;
}
public static void UnitTest_1020()
{
var res = UnitTest_1020Sub(20176515, 2400000000);
Console.WriteLine($"res={res}");
if (Math.Abs(res - 0.008406881f) > 0.00001)
throw new Exception();
}
static float UnitTest_1020Sub(long exp, long maxExp)
{
float percent = (float)exp / maxExp;
Console.WriteLine("maxExp:" + maxExp + ",exp:" + exp + ", exp / maxExp:" + percent);
return percent;
}
}
}