-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
DoubleTypeTests.cs
67 lines (60 loc) · 2.34 KB
/
DoubleTypeTests.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Globalization;
using Microsoft.VisualBasic.CompilerServices;
using Xunit;
namespace Microsoft.VisualBasic.Tests
{
public class DoubleTypeTests
{
[Theory]
[InlineData(null, 0)]
[InlineData("&H123", 291)]
[InlineData("&O123", 83)]
[InlineData("123", 123)]
public void FromString(string value, double expected)
{
Assert.Equal(expected, DoubleType.FromString(value));
}
[Fact]
public void FromString_Invalid()
{
Assert.Throws<InvalidCastException>(() => DoubleType.FromString("abc"));
}
[Fact]
public void FromObject()
{
Assert.Equal(0d, DoubleType.FromObject(null));
Assert.Equal(-1d, DoubleType.FromObject(true));
Assert.Equal(123d, DoubleType.FromObject((byte)123));
Assert.Equal(123d, DoubleType.FromObject((short)123));
Assert.Equal(123d, DoubleType.FromObject((int)123));
Assert.Equal(123d, DoubleType.FromObject((long)123));
Assert.Equal(123d, DoubleType.FromObject((float)123));
Assert.Equal(123d, DoubleType.FromObject((double)123));
Assert.Equal(123d, DoubleType.FromObject((decimal)123));
Assert.Equal(123d, DoubleType.FromObject("123"));
}
[Fact]
public void FromObject_Invalid()
{
Assert.Throws<InvalidCastException>(() => DoubleType.FromObject('1'));
Assert.Throws<InvalidCastException>(() => DoubleType.FromObject(DateTime.MinValue));
Assert.Throws<InvalidCastException>(() => DoubleType.FromObject(Guid.Empty));
}
[Theory]
[InlineData("123", 123)]
[InlineData("\u00A4123", 123)]
public void Parse(string value, double expected)
{
Assert.Equal(expected, DoubleType.Parse(value, CultureInfo.InvariantCulture.NumberFormat));
}
[Fact]
public void Parse_Invalid()
{
Assert.Throws<ArgumentNullException>(() => DoubleType.Parse(null, null));
Assert.Throws<FormatException>(() => DoubleType.Parse("abc", CultureInfo.InvariantCulture.NumberFormat));
}
}
}