Skip to content

Commit eac1fb6

Browse files
committed
Fixed GetSentence()
Was getting a System.IndexOutOfRangeException. Also added unit test.
1 parent 8dd2d9f commit eac1fb6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Source/RandomData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public static string GetSentence(int minWords = 5, int maxWords = 25) {
235235
builder.Append(UpperCaseFirstCharacter(_words[GetInt(0, _words.Length)]));
236236
int numberOfWords = GetInt(minWords, maxWords);
237237
for (int i = 1; i < numberOfWords; i++)
238-
builder.Append(' ').Append(_words[GetInt(0, _words.Length)]);
238+
builder.Append(' ').Append(_words[GetInt(0, _words.Length - 1)]);
239239

240240
builder.Append('.');
241241
return builder.ToString();

Source/Tests/RandomDataTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ namespace Exceptionless.Tests
55
public class RandomDataTests
66
{
77
[Fact]
8-
public void CanGenerateRandomData() {
8+
public void CanGenerateRandomData()
9+
{
910
int value = RandomData.GetInt(1, 5);
1011
Assert.InRange(value, 1, 5);
1112

@@ -21,7 +22,15 @@ public void GetEnumWithOneValueTest()
2122
Assert.Equal<_days>(_days.Monday, result);
2223
}
2324

24-
private int[] _numbers = new[] {1, 2, 3};
25+
[Fact]
26+
public void GetSentencesTest()
27+
{
28+
var result = RandomData.GetSentence();
29+
30+
Assert.False(string.IsNullOrEmpty(result));
31+
}
32+
33+
private int[] _numbers = new[] { 1, 2, 3 };
2534

2635
private enum _days
2736
{

0 commit comments

Comments
 (0)