forked from sam-vdp/bepuphysics1int
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossPlatformDeterminismTests.cs
118 lines (101 loc) · 2.67 KB
/
CrossPlatformDeterminismTests.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
using BEPUbenchmark;
using BEPUbenchmark.Benchmarks;
using System;
using System.Text;
using Xunit;
using Xunit.Abstractions;
namespace BEPUtests
{
public class CrossPlatformDeterminismTests
{
private readonly ITestOutputHelper output;
public CrossPlatformDeterminismTests(ITestOutputHelper output)
{
this.output = output;
}
private void GetExpectedHash(Benchmark b, StringBuilder result)
{
result.AppendFormat("{{\"{0}\", new string[] {{", b.GetName());
b.Initialize();
long startTime = DateTime.Now.Ticks;
for (int i = 0; i < 50; i++)
{
string expectedHash = b.RunToNextHash();
if (i != 0)
result.Append(",\n");
result.AppendFormat("\"{0}\"", expectedHash);
if (i > 5 && DateTime.Now.Ticks - startTime > TimeSpan.TicksPerSecond * 5)
break;
}
result.AppendLine("}}");
}
//[Fact]
public void OutputExpectedHashes()
{
StringBuilder result = new StringBuilder();
result.AppendLine(@"
using System.Collections.Generic;
namespace BEPUtests
{
class CrossPlatformDeterminismExpectedHashes
{
public static readonly Dictionary<string, string[]> Hashes = new Dictionary<string, string[]>()
{");
bool first = true;
foreach (Benchmark b in AllBenchmarks.Benchmarks)
{
if (!first)
result.Append(",\n");
GetExpectedHash(b, result);
first = false;
}
result.AppendLine("};\n}\n}\n");
output.WriteLine(result.ToString());
}
//[Fact]
public void OutputExpectedHashesForBenchmark()
{
Benchmark b = new PathFollowingBenchmark();
StringBuilder result = new StringBuilder();
GetExpectedHash(b, result);
output.WriteLine(result.ToString());
}
[Fact]
public void DiscreteVsContinuous()
{
TestDeterminism(new DiscreteVsContinuousBenchmark());
}
[Fact]
public void InverseKinematic()
{
TestDeterminism(new InverseKinematicsBenchmark());
}
[Fact]
public void Pyramid()
{
TestDeterminism(new PyramidBenchmark());
}
[Fact]
public void PathFollowing()
{
TestDeterminism(new PathFollowingBenchmark());
}
[Fact]
public void SelfCollidingCloth()
{
TestDeterminism(new SelfCollidingClothBenchmark());
}
private void TestDeterminism(Benchmark b)
{
b.Initialize();
string[] expectedHashes = CrossPlatformDeterminismExpectedHashes.Hashes[b.GetName()];
int step = 0;
foreach (string expectedHash in expectedHashes)
{
string actualHash = b.RunToNextHash();
Assert.True(expectedHash == actualHash, string.Format("Expected {0}, actual {1} in step {2}", expectedHash, actualHash, step));
step++;
}
}
}
}