Skip to content

Commit 13cbcab

Browse files
committed
Added tests for get decimal
For some reasons the existing code wouldn't generate a decimal in a specified range.
1 parent dea0cde commit 13cbcab

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

Source/RandomData.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ public static decimal GetDecimal() {
149149
}
150150

151151
public static decimal GetDecimal(int min, int max) {
152-
byte scale = (byte) Instance.Next(29);
153-
bool sign = Instance.Next(2) == 1;
154-
return new decimal(min, GetInt(min, max), max, sign, scale);
152+
return (decimal)GetDouble(min, max);
155153
}
156154

157155
public static T GetEnum<T>() {

Source/Tests/RandomDataTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
using Xunit;
22

3-
namespace Exceptionless.Tests
4-
{
5-
public class RandomDataTests
6-
{
3+
namespace Exceptionless.Tests {
4+
public class RandomDataTests {
75
[Fact]
8-
public void CanGenerateRandomData()
9-
{
6+
public void RandomInt() {
107
int value = RandomData.GetInt(1, 5);
118
Assert.InRange(value, 1, 5);
129

@@ -15,26 +12,29 @@ public void CanGenerateRandomData()
1512
}
1613

1714
[Fact]
18-
public void GetEnumWithOneValueTest()
19-
{
15+
public void RandomDecimal() {
16+
decimal value = RandomData.GetDecimal(1, 5);
17+
Assert.InRange(value, 1, 5);
18+
}
19+
20+
[Fact]
21+
public void GetEnumWithOneValueTest() {
2022
var result = RandomData.GetEnum<_days>();
2123

2224
Assert.Equal<_days>(_days.Monday, result);
2325
}
2426

2527
[Fact]
26-
public void GetSentencesTest()
27-
{
28+
public void GetSentencesTest() {
2829
var result = RandomData.GetSentence();
2930

3031
Assert.False(string.IsNullOrEmpty(result));
3132
}
3233

3334
private int[] _numbers = new[] { 1, 2, 3 };
3435

35-
private enum _days
36-
{
36+
private enum _days {
3737
Monday
3838
}
3939
}
40-
}
40+
}

0 commit comments

Comments
 (0)