-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlFlowTests.cs
119 lines (94 loc) · 2.92 KB
/
ControlFlowTests.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
using System.Collections;
namespace AlgorithmTests;
[TestClass()]
public class ControlFlowTests : TestBase, IDisposable
{
protected bool _dispose;
public override IDictionary Properties => throw new NotImplementedException();
public ControlFlowTests()
{
}
[TestMethod()]
public void RunTest()
{
//Mental model: Random.Shared.NextSystem.Double() is [0, 1)
//System.Double.Epsilon is the smallest positive System.Double value that is significant?
//Math.Abs(1.0 - (1.0 + System.Double.Epsilon) * Random.Shared.NextSystem.Double()???
//use System.Double-floating point error to break the loop?
while (Random.Shared.NextDouble() is >= 0.0 and < 1.0)
{
if(CancellationTokenSource.Token.IsCancellationRequested)
{
break;
}
#if false
if (Random.Shared.Next(0, 九十六) < 四十八)
{
Assert.Fail();
}
#endif
Assert.IsFalse(Random.Shared.Next(0, 九十六) < 四十八);
Assert.IsTrue(Random.Shared.Next(0, 九十六) is >= 0 and < 九十六);
Assert.IsTrue(Random.Shared.NextDouble() is >= System.Double.Epsilon and < 1.0);
Assert.IsFalse(Random.Shared.Next(0, 九十六) is < 0 or >= 九十六);
}
}
public static IEnumerable<bool> RunTest2(CancellationToken? cancellationToken = default)
{
while (true)
{
if (cancellationToken is not null && cancellationToken.Value.IsCancellationRequested)
{
yield break;
}
yield return Random.Shared.Next(0, 九十六) is >= 0 and < 九十六;
}
}
[TestMethod()]
public void RunTest2()
{
foreach (bool item in RunTest2(CancellationTokenSource.Token))
{
Assert.IsTrue(item);
}
Assert.IsTrue(CancellationTokenSource.Token.IsCancellationRequested || true);
}
[TestMethod()]
public void RunTest3()
{
Assert.Inconclusive();
}
protected virtual void Dispose(bool disposing)
{
if (!_dispose)
{
if (disposing)
{
CancellationTokenSource.Cancel();
CancellationTokenSource.Dispose();
}
Interlocked.Exchange(ref _dispose, true);
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
public override void AddResultFile(string fileName)
{
}
public override void Write(string? message)
{
}
public override void Write(string format, params object?[] args)
{
}
public override void WriteLine(string? message)
{
}
public override void WriteLine(string format, params object?[] args)
{
}
}