forked from CarlVerret/csFastFloat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseTestClass.cs
More file actions
65 lines (46 loc) · 1.38 KB
/
Copy pathBaseTestClass.cs
File metadata and controls
65 lines (46 loc) · 1.38 KB
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
using ApprovalTests;
using ApprovalTests.Namers;
using ApprovalTests.Reporters;
using System;
namespace TestcsFastFloat.Tests
{
[UseReporter(typeof(DiffReporter))]
public class BaseTestClass
{
public static void VerifyData<T>(T data, string scenarioName = "")
{
if (!string.IsNullOrEmpty(scenarioName))
{
using (ApprovalResults.ForScenario(scenarioName))
{
Approvals.Verify(data);
}
}
else
{
Approvals.Verify(data);
}
}
public bool NoDiffToolDetected() => !DiffEngine.DiffTools.TryFind("txt", out _);
/// @Credit Dmitry Bychenko
/// https://stackoverflow.com/questions/35449339/c-sharp-converting-from-float-to-hexstring-via-ieee-754-and-back-to-float/35450540#35450540
internal static short ShortFromHexString(string s)
{
var i = Convert.ToInt16(s, 16);
var bytes = BitConverter.GetBytes(i);
return BitConverter.ToInt16(bytes, 0);
}
internal static float FloatFromHexString(string s)
{
var i = Convert.ToInt32(s, 16);
var bytes = BitConverter.GetBytes(i);
return BitConverter.ToSingle(bytes, 0);
}
internal static double DoubleFromHexString(string s)
{
var i = Convert.ToInt64(s, 16);
var bytes = BitConverter.GetBytes(i);
return BitConverter.ToDouble(bytes, 0);
}
}
}