-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNullableTests.cs
58 lines (51 loc) · 1.31 KB
/
NullableTests.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
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine.Profiling;
using UnityEngine.TestTools.Constraints;
using Is = UnityEngine.TestTools.Constraints.Is;
namespace MH.GCTests
{
using Random = UnityEngine.Random;
public class NullableTests
{
const int LOOP_COUNT = 100000; //don't know why, but if the mem allocation is too small, the profiler.GetMonoUsedSizeLong cannot detect it
[OneTimeSetUp]
public void Init()
{
GC.Collect();
Profiler.enabled = true;
}
[OneTimeTearDown]
public void Fini()
{
Profiler.enabled = false;
}
[Test]
public void OK_Nullable()
{
GC.Collect();
//------------------//
Assert.That(
() => {
for (int i = 0; i<100; ++i)
_ReturnNullableInt(i).GetValueOrDefault();
},
Is.Not.AllocatingGCMemory()
);
}
private int? _ReturnNullableInt(int v)
{
if( Random.value < 0.5f )
{
return v;
}
else
{
return null;
}
}
}
}