-
-
Notifications
You must be signed in to change notification settings - Fork 517
/
Copy pathIssue319.cs
90 lines (75 loc) · 2.31 KB
/
Issue319.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
using System;
using System.Collections.Generic;
using System.Reflection;
using Bogus.Extensions;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Bogus.Tests.GitHubIssues
{
public class Issue319 : SeededTest
{
ITestOutputHelper _output;
public Issue319(ITestOutputHelper output)
=> _output = output;
[Fact]
public void can_generate_decimal_edge_case()
{
var r = new Randomizer();
Action a = () =>
{
r.Decimal(0m, decimal.MaxValue);
r.Decimal(0m, decimal.MaxValue);
r.Decimal(0m, decimal.MaxValue);
r.Decimal(0m, decimal.MaxValue);
};
a.Should().NotThrow();
}
[Fact]
public void decimal2_should_throw_on_edge_case()
{
var r = new Randomizer();
Action a = () =>
{
r.Decimal2(0, decimal.MaxValue);
};
a.Should().Throw<OverflowException>();
}
class TestDataProvider : DataAttribute
{
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
yield return new object[] { 0m, decimal.MaxValue };
yield return new object[] { decimal.MinValue, decimal.MaxValue };
yield return new object[] { decimal.MinValue, 0m };
// A range whose size exceeds decimal.MaxValue but which doesn't have decimal.MinValue or decimal.MaxValue as a bound.
yield return new object[] { decimal.MinValue * 0.6m, decimal.MaxValue * 0.6m };
}
}
[Theory, TestDataProvider]
public void decimal_with_very_large_range_succeeds(decimal min, decimal max)
{
var randomizer = new Randomizer();
for (int iteration = 0; iteration < 300; iteration++)
{
try
{
randomizer.Decimal3(min, max).Should().BeInRange(min, max);
}
catch
{
_output.WriteLine("Test failed on iteration {0}", iteration);
throw;
}
}
}
[Fact]
public void decimal3_fails_after_2_calls()
{
var r = new Randomizer();
r.Decimal3(0m, decimal.MaxValue);
r.Decimal3(0m, decimal.MaxValue);
}
}
}