-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathConvert.ToDouble.cs
135 lines (117 loc) · 5 KB
/
Convert.ToDouble.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.Tests
{
public class ConvertToDoubleTests : ConvertTestBase<double>
{
[Fact]
public void FromBoolean()
{
bool[] testValues = { true, false };
double[] expectedValues = { 1.0, 0.0 };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromByte()
{
byte[] testValues = { byte.MaxValue, byte.MinValue };
double[] expectedValues = { byte.MaxValue, byte.MinValue };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromDecimal()
{
decimal[] testValues = { decimal.MaxValue, decimal.MinValue, 0.0m };
double[] expectedValues = { (double)decimal.MaxValue, (double)decimal.MinValue, 0.0 };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromDouble()
{
double[] testValues = { double.MaxValue, double.MinValue, double.NegativeInfinity, double.PositiveInfinity, double.Epsilon };
double[] expectedValues = { double.MaxValue, double.MinValue, double.NegativeInfinity, double.PositiveInfinity, double.Epsilon };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromInt16()
{
short[] testValues = { short.MaxValue, short.MinValue, 0 };
double[] expectedValues = { short.MaxValue, short.MinValue, 0 };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromInt32()
{
int[] testValues = { int.MaxValue, int.MinValue, 0 };
double[] expectedValues = { int.MaxValue, int.MinValue, 0 };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromInt64()
{
long[] testValues = { long.MaxValue, long.MinValue, 0 };
double[] expectedValues = { (double)long.MaxValue, (double)long.MinValue, 0 };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromObject()
{
object[] testValues = { null };
double[] expectedValues = { 0.0 };
VerifyFromObject(Convert.ToDouble, Convert.ToDouble, testValues, expectedValues);
object[] invalidValues = { new object(), DateTime.Now };
VerifyFromObjectThrows<InvalidCastException>(Convert.ToDouble, Convert.ToDouble, invalidValues);
}
[Fact]
public void FromSByte()
{
sbyte[] testValues = { sbyte.MaxValue, sbyte.MinValue };
double[] expectedValues = { sbyte.MaxValue, sbyte.MinValue };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromSingle()
{
float[] testValues = { float.MaxValue, float.MinValue, 0.0f };
double[] expectedValues = { float.MaxValue, float.MinValue, 0.0 };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromString()
{
string[] testValues = { Double.MinValue.ToString("R"), Double.MaxValue.ToString("R"), (0.0).ToString(), (10.0).ToString(), (-10.0).ToString(), null };
double[] expectedValues = { double.MinValue, double.MaxValue, 0.0, 10.0, -10.0, 0.0 };
VerifyFromString(Convert.ToDouble, Convert.ToDouble, testValues, expectedValues);
string[] formatExceptionValues = { "123xyz" };
VerifyFromStringThrows<FormatException>(Convert.ToDouble, Convert.ToDouble, formatExceptionValues);
}
[Fact]
public void FromString_NotNetFramework()
{
string[] overflowValues = { Double.MaxValue.ToString(), Double.MinValue.ToString() };
VerifyFromString(Convert.ToDouble, Convert.ToDouble, overflowValues, new double[] { 1.7976931348623157E+308, -1.7976931348623157E+308 });
}
[Fact]
public void FromUInt16()
{
ushort[] testValues = { ushort.MaxValue, ushort.MinValue };
double[] expectedValues = { ushort.MaxValue, ushort.MinValue };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromUInt32()
{
uint[] testValues = { uint.MaxValue, uint.MinValue };
double[] expectedValues = { uint.MaxValue, uint.MinValue };
Verify(Convert.ToDouble, testValues, expectedValues);
}
[Fact]
public void FromUInt64()
{
ulong[] testValues = { ulong.MaxValue, ulong.MinValue };
double[] expectedValues = { (double)ulong.MaxValue, (double)ulong.MinValue };
Verify(Convert.ToDouble, testValues, expectedValues);
}
}
}